Skip to content

Wrong diagnostic label text due to text replacement #51244

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

Closed
ytausky opened this issue May 31, 2018 · 0 comments
Closed

Wrong diagnostic label text due to text replacement #51244

ytausky opened this issue May 31, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@ytausky
Copy link
Contributor

ytausky commented May 31, 2018

The following snippet:

fn main() {
    let ref my_ref @ _ = 0;
    *my_ref = 0
}

Produces the following output:

error[E0594]: cannot assign to immutable borrowed content `*my_ref`
 --> src/main.rs:3:5
  |
2 |     let ref my_ref @ _ = 0;
  |         -------------- consider changing this to `ref mut my_ref mut @ _`
3 |     *my_ref = 0
  |     ^^^^^^^^^^^ cannot borrow as mutable

Note that the label suggests invalid syntax. I believe this happens due to the text replacement in the following code:

ty::BindByReference(..) => {
let snippet = self.tcx.sess.codemap().span_to_snippet(let_span);
if let Ok(snippet) = snippet {
db.span_label(
let_span,
format!("consider changing this to `{}`",
snippet.replace("ref ", "ref mut "))
);
}
}

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label May 31, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 13, 2018
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.)
bors added a commit that referenced this issue Jul 13, 2018
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.)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants