about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-07-26 16:04:36 +0200
committerGitHub <noreply@github.com>2021-07-26 16:04:36 +0200
commitf9d00b4a7850ca3a5c710fec1debaf421b339718 (patch)
tree716223cf7a83ab26be551acba36a5307861bb480 /compiler
parente3c6cd23cfa69f9f985d52e4d59771ebfc795e84 (diff)
parentb4a873f54899c31525d3f1e1717b1d1a54191c21 (diff)
downloadrust-f9d00b4a7850ca3a5c710fec1debaf421b339718.tar.gz
rust-f9d00b4a7850ca3a5c710fec1debaf421b339718.zip
Rollup merge of #87458 - ibraheemdev:help-msg-block-borrow, r=oli-obk
Fix help message for modification to &T created by &{t}

Previous:
```rust
error[E0594]: cannot assign to `*x` which is behind a `&` reference
 --> src/main.rs:3:5
  |
2 |     let x: &usize = &mut{0};
  |                     ------- help: consider changing this to be a mutable reference: `&mut mut{0}`
3 |     *x = 1;
  |     ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs
index 671d947d1b1..336f48bde55 100644
--- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs
@@ -905,6 +905,8 @@ fn suggest_ampmut<'tcx>(
                         Some(c) if c.is_whitespace() => true,
                         // e.g. `&mut(x)`
                         Some('(') => true,
+                        // e.g. `&mut{x}`
+                        Some('{') => true,
                         // e.g. `&mutablevar`
                         _ => false,
                     }
@@ -912,9 +914,7 @@ fn suggest_ampmut<'tcx>(
                     false
                 }
             };
-            if let (true, Some(ws_pos)) =
-                (src.starts_with("&'"), src.find(|c: char| -> bool { c.is_whitespace() }))
-            {
+            if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
                 let lt_name = &src[1..ws_pos];
                 let ty = src[ws_pos..].trim_start();
                 if !is_mutbl(ty) {
@@ -940,9 +940,7 @@ fn suggest_ampmut<'tcx>(
     };
 
     if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span) {
-        if let (true, Some(ws_pos)) =
-            (src.starts_with("&'"), src.find(|c: char| -> bool { c.is_whitespace() }))
-        {
+        if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
             let lt_name = &src[1..ws_pos];
             let ty = &src[ws_pos..];
             return (highlight_span, format!("&{} mut{}", lt_name, ty));