

Github fix `needless_borrow` suggestion by Jarcho · Pull Request #7105 · rust-la...
source link: https://github.com/rust-lang/rust-clippy/pull/7105
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

fixes: #2610
While I'm working on this, should needless_borrow be split into two? One lint for expressions and another for patterns. In expression it only lints when the compiler inserts a dereference, but for patterns it's whenever a double reference is created. I think at least the case where a double reference is needed should be split into a new lint as it's not 'needless', it can just be done without a ref binding.
For illustration:
fn foo(x: &&str) {} match Some("test") { // ref binding is useless here Some(ref x) => *x, _ => (), } match Some("test") { // ref binding is useless here Some(ref x) => x.len(), _ => (), } match Some("test") { // double reference is needed, but could be `Some(x) => foo(&x)` Some(ref x) => foo(x), _ => (), }
changelog: Improve the suggestion for needless_borrow
in patterns to change all usage sites as needed.
changelog: Add lint ref_binding_to_reference
Recommend
-
8
Copy link Contributor Jarcho commented...
-
7
Copy link Contributor Jarcho comme...
-
6
Copy link Collaborator llogiq ...
-
8
Copy link Contributor Jarcho commented...
-
5
error: this method is named `iter` but its return type does not implement `Iterator` --> $DIR/iter_not_returning_iterator.rs:50:...
-
8
Conversation Copy link Contribu...
-
3
Copy link Contributor Jarcho ...
-
8
New issue fix FP in lint [needless_match] #8549 ...
-
9
Contributor ...
-
6
Conversation Member...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK