-
Notifications
You must be signed in to change notification settings - Fork 1.7k
needless_borrow suggests removing a necessary borrow in a loop #9778
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@martinvonz Would you mind testing your code again with a more recent version of Clippy? There was a bug like you described, but I think it has been fixed. While it's possible I am doing something wrong, I don't seem to get a warning from your code with 6b4e7dd, for example. |
I tried just now with rustc 1.67.0-nightly (edf0182 2022-11-02) but the bug is still there. I suppose your fix just hasn't reached the nightly build yet. I don't feel like building clippy from source just to test, but I'm happy to test again once it's reached nightly. Do you know when that will be? |
I'm not sure. I think an "Update Clippy" PR is opened about every two weeks, and it looks like the last one was opened on October 24. So November 7-ish, maybe(?). |
Feel free to close this. It does seem to be the same problem and same fix. Or remind me to check again in a week or so :) |
I'll try to remember to remind you. :) |
Just stumbled upon this myself, still getting this with use std::path::PathBuf;
pub fn foo() {
let path = PathBuf::new();
let directory_path: PathBuf = PathBuf::new();
loop {
let _ = path.join(&directory_path);
}
} |
I just ran Clippy master (a599527) on this example and got no warnings. So I think the fix just hasn't made it into the Rust tree yet. |
@martinvonz I think this is fixed in nightly, if you want to give it another shot. |
Yes, looks good now. Thanks! |
Looks like beta 1.66 also has this problem. I tried the original example and get the lint; with I'm running
|
And this problem is in stable 1.66 as well. This is a regression from 1.65. |
Summary
With a very recent nightly build, the needless_borrow lint suggests removing a necessary borrow when the borrow occurs in a loop (though I haven't spent any time trying to figure out exactly what the condition is).
Lint Name
needless_borrow
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No warning
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: