-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Consider changing to & for let bindings #40402 #41640
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@estebank @jonathandturner please review the format. |
Specifically, as @gaurikholkar said, she and I were wondering what you guys thought might be best. Because the span to label for the suggestion is the same as the one for which we are reporting the error, the initial stab looked something like:
which didn't seem good. So we did the two other experiments you see in the main comment area. The main question is, should we repeat the "main error text" also in the label, or not? |
The code looks good, only question is how to format the error. |
What about using a error[E0507]: cannot move out of indexed content
--> ex1.rs:4:13
|
4 | let e = v[0];
| ^^^^ cannot move out of indexed content
|
help: consider using a reference instead:
| let e = &v[0]; It takes more vertical space, which I care little for, but it is the way these kind of suggestions are presented in other diagnostics. |
@estebank hmm, I thought we were moving away from that format for some reason. I'm not a big fan but maybe we should just use it for consistency's sake, and then we can think about upgrading how all uses of it are rendered in one step at some point. |
@nikomatsakis I'd opened #39152 some time ago as a catch all to improve the suggestion output. It was my understanding that span suggestions should be reserved for cases where certainty is high so that they can be applied automatically by tools. |
@estebank I've heard that line of thought. I find it hard to judge what an appropriate level of certainty is for a fictional tool -- but in general I do think people get quite frustrated when they apply a suggestion, only to find that it leads them to another error. And definitely presenting ill-formed code as a suggestion is very bad. It seems to me that this suggestion is certainly "as good" as the I'm trying to think if it's possible for the suggestion to be malformed. The only reason I can think for that to happen would be if |
@nikomatsakis I'm ok with the current output if we don't want to use |
@nikomatsakis @estebank have updated the PR.
|
@bors r+ |
📌 Commit 1c57bb4 has been approved by |
Consider changing to & for let bindings rust-lang#40402 This is a fix for rust-lang#40402 For the example ``` fn main() { let v = vec![String::from("oh no")]; let e = v[0]; } ``` It gives ``` error[E0507]: cannot move out of indexed content --> ex1.rs:4:13 | 4 | let e = v[0]; | ^^^^ cannot move out of indexed content | = help: consider changing to `&v[0]` error: aborting due to previous error ``` Another alternative is ``` error[E0507]: cannot move out of indexed content --> ex1.rs:4:13 | 4 | let e = v[0]; | ^^^^ consider changing to `&v[0]` error: aborting due to previous error ``` Also refer to rust-lang#41564 for more details. r? @nikomatsakis
This is a fix for #40402
For the example
It gives
Another alternative is
Also refer to #41564 for more details.
r? @nikomatsakis