-
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
Fix wrong test replacemen in ref mut
suggestion
#51249
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
35ba512
to
fb30eb6
Compare
This comment has been minimized.
This comment has been minimized.
@@ -1213,7 +1213,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |||
db.span_label( | |||
let_span, | |||
format!("consider changing this to `{}`", | |||
snippet.replace("ref ", "ref mut ")) | |||
snippet.replacen("ref ", "ref mut ", 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is (a) not requiring the ref
to be at the start of the span (this might be problematic) and (b) only matching the first space after it (this is okay if we want to preserve weird formatting). This might be fine for all inputs we consider now, but matching "^ref "
seems safer in general.
ce7540a
to
cc50347
Compare
This comment has been minimized.
This comment has been minimized.
the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Friendly triage ping @pnkfelix / @rust-lang/compiler, it looks like this PR needs your review. |
--> $DIR/issue-51244.rs:13:5 | ||
| | ||
LL | let ref my_ref @ _ = 0; | ||
| -------------- help: consider changing this to be a mutable reference: `&mut ef my_ref @ _` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked by #51612
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pietroalbini block occurs here.
snippet.replacen("ref ", "ref mut ", 1) | ||
} else { | ||
snippet | ||
}; | ||
db.span_label( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this to be a span_suggestion
? That way editors will know they can perform the replacement and the following code:
let replace_str = if snippet.starts_with("ref ") {
snippet.replacen("ref ", "ref mut ", 1)
} else {
snippet
};
db.span_label(
let_span,
"use a mutable reference instead",
replace_str,
);
output would look like this:
error[E0594]: cannot assign to immutable borrowed content `*my_ref`
--> $DIR/issue-51244.rs:13:5
|
LL | let ref my_ref @ _ = 0;
| -------------- use a mutable reference instead: `ref mut my_ref @ _`
LL | *my_ref = 0;
| ^^^^^^^^^^^ cannot borrow as mutable
This will likely require you to run ./x.py test src/test/ui --bless
to update the output in other test files too.
If you do not wish to make this change now, please file a ticket to follow up on all suggestions on this file, so that the team doesn't forget to address this later.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Use |
@estebank I did
In the origin suggestion: changing to
And this time, the span( |
You're right, although I would say that that is probably a preexisting problem (the current suggestion is already wrong). It needs to be fixed, but it doesn't seem to be a regression caused by your code. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
ping from triage @csmoe will you have time to fix the code? |
@csmoe this is blocked on what? |
NLL: Suggest `ref mut` and `&mut self` Fixes rust-lang#51244. Supersedes rust-lang#51249, I think. Under the old lexical lifetimes, the compiler provided helpful suggestions about adding `mut` when you tried to mutate a variable bound as `&self` or (explicit) `ref`. NLL doesn't have those suggestions yet. This pull request adds them. I didn't bother making the help text exactly the same as without NLL, but I can if that's important. (Originally this was supposed to be part of rust-lang#51612, but I got bogged down trying to fit everything in one PR.)
NLL: Suggest `ref mut` and `&mut self` Fixes #51244. Supersedes #51249, I think. Under the old lexical lifetimes, the compiler provided helpful suggestions about adding `mut` when you tried to mutate a variable bound as `&self` or (explicit) `ref`. NLL doesn't have those suggestions yet. This pull request adds them. I didn't bother making the help text exactly the same as without NLL, but I can if that's important. (Originally this was supposed to be part of #51612, but I got bogged down trying to fit everything in one PR.)
☔ The latest upstream changes (presumably #52242) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixed #52242 |
Closes #51244