-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Lint name: needless_borrow
I tried this code:
I wonder if the lint should warn on passing &arg to a function that takes AsRef<..>
where the &
would not be needed
#![warn(clippy::needless_borrow)]
pub fn main() {
fn is_hello<T: AsRef<str>>(s: T) {
assert_eq!("hello", s.as_ref());
}
let s: &String = &"hello".to_string();
is_hello(&&&&s); // warn?
is_hello(&s); // warn?
is_hello(s); // ok
is_hello(&"hello"); // warn?
is_hello("hello"); // ok
}
Meta
cargo clippy -V
:clippy 0.1.52 (9c09c1f 2021-02-26)
rustc -Vv
:
rustc 1.52.0-nightly (9c09c1f7c 2021-02-26)
binary: rustc
commit-hash: 9c09c1f7cfcf9de0522bcd1cfda32b552195c464
commit-date: 2021-02-26
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't