mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
65 lines
1.3 KiB
Rust
65 lines
1.3 KiB
Rust
#![warn(clippy::unnecessary_literal_bound)]
|
|
|
|
struct Struct<'a> {
|
|
not_literal: &'a str,
|
|
}
|
|
|
|
impl Struct<'_> {
|
|
// Should warn
|
|
fn returns_lit(&self) -> &str {
|
|
"Hello"
|
|
}
|
|
|
|
// Should NOT warn
|
|
fn returns_non_lit(&self) -> &str {
|
|
self.not_literal
|
|
}
|
|
|
|
// Should warn, does not currently
|
|
fn conditionally_returns_lit(&self, cond: bool) -> &str {
|
|
if cond { "Literal" } else { "also a literal" }
|
|
}
|
|
|
|
// Should NOT warn
|
|
fn conditionally_returns_non_lit(&self, cond: bool) -> &str {
|
|
if cond { "Literal" } else { self.not_literal }
|
|
}
|
|
|
|
// Should warn
|
|
fn contionally_returns_literals_explicit(&self, cond: bool) -> &str {
|
|
if cond {
|
|
return "Literal";
|
|
}
|
|
|
|
"also a literal"
|
|
}
|
|
|
|
// Should NOT warn
|
|
fn conditionally_returns_non_lit_explicit(&self, cond: bool) -> &str {
|
|
if cond {
|
|
return self.not_literal;
|
|
}
|
|
|
|
"Literal"
|
|
}
|
|
}
|
|
|
|
trait ReturnsStr {
|
|
fn trait_method(&self) -> &str;
|
|
}
|
|
|
|
impl ReturnsStr for u8 {
|
|
// Should warn, even though not useful without trait refinement
|
|
fn trait_method(&self) -> &str {
|
|
"Literal"
|
|
}
|
|
}
|
|
|
|
impl ReturnsStr for Struct<'_> {
|
|
// Should NOT warn
|
|
fn trait_method(&self) -> &str {
|
|
self.not_literal
|
|
}
|
|
}
|
|
|
|
fn main() {}
|