RS.CLIPPY.UNNECESSARY_LITERAL_BOUND
Detects &str that could be &'static str in function return types
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unnecessary_literal_bound. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Detects functions that are written to return &str that could return &\'static str but instead return a &\'a str.
Why is this bad?
This leaves the caller unable to use the &str as &\'static str, causing unnecessary allocations or confusion.
This is also most likely what you meant to write.
Example
impl MyType {
fn returns_literal(&self) -> &str {
"Literal"
}
}
Use instead:
impl MyType {
fn returns_literal(&self) -> &\'static str {
"Literal"
}
}
Or, in case you may return a non-literal str in future:
impl MyType {
fn returns_literal<\'a>(&\'a self) -> &\'a str {
"Literal"
}
}