-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Check definitions of arguments before suggest move expr out of loop #142189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
If I search for the string "consider moving the expression out of the loop so it is only moved once" from the codebase, I haven't seen a single suggestion that is correct in the context. I think it might just be better to remove this. cc @compiler-errors if you have opinions |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
There does seem to be something werid about this suggestion. As I tried it, I realized that the triggers to make this suggestion correct seemed a bit harsh, but it was indeed the correct suggestion in this instance: @rustbot ready |
I still don't think this is the correct approach. The original suggestion is very limited in what kinds of contexts would trigger a suggestion. For example, fn foo() {
let vec = vec!["one", "two", "three"];
while let Some(item) = vec.into_iter().next() {
println!("{:?}", item);
}
} This above doesn't trigger the suggestion even though it should. We have many false negatives and false positives. This should be rewritten by someone experienced but I don't have enough time/effort at the moment. r? compiler |
I also agree that this usage scenario is very limited. Do we need to remove it now? Maybe I can try to rewrite it, but I don't know if the difficulty is acceptable to me. |
Fixes #141880
The first commit is used to add tests and the second shows the changes. For the test cases I added, there are three cases, and only the third case passes compilation after applying this suggestion. The changed code implements this.
r? compiler