diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2017-03-12 21:28:49 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2017-03-13 19:22:48 -0700 |
| commit | 9ac628d5e84bd3664e41d53bafa3d66b303b19c1 (patch) | |
| tree | 25a898e1d8b2e8a165ce6856db99c4fa1c575a12 | |
| parent | 38b5b29c57fc86aae5a1bc8d1319cc08907d9ee0 (diff) | |
| download | rust-9ac628d5e84bd3664e41d53bafa3d66b303b19c1.tar.gz rust-9ac628d5e84bd3664e41d53bafa3d66b303b19c1.zip | |
Add label to primary span for mutable access of immutable struct error
| -rw-r--r-- | src/librustc_borrowck/borrowck/mod.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-39544.stderr | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 073ebe24de9..1b44ba1ec61 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -747,9 +747,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { if let Some((span, msg)) = immutable_field { db.span_label(span, &msg); } - if let Some(span) = local_def { - if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) { - db.span_label(span, &format!("consider changing this to `mut {}`", snippet)); + if let Some(let_span) = local_def { + if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) { + db.span_label(let_span, &format!("consider changing this to `mut {}`", snippet)); } } db @@ -1120,6 +1120,11 @@ before rustc 1.16, this temporary lived longer - see issue #39283 \ } else { db.span_label(*error_span, &format!("cannot borrow mutably")); } + } else if let Categorization::Interior(ref cmt, _) = err.cmt.cat { + if let mc::MutabilityCategory::McImmutable = cmt.mutbl { + db.span_label(*error_span, + &"cannot mutably borrow immutable field"); + } } } } diff --git a/src/test/ui/did_you_mean/issue-39544.stderr b/src/test/ui/did_you_mean/issue-39544.stderr index 3eb3e9a4c3b..7f124e6d34d 100644 --- a/src/test/ui/did_you_mean/issue-39544.stderr +++ b/src/test/ui/did_you_mean/issue-39544.stderr @@ -4,7 +4,7 @@ error: cannot borrow immutable field `z.x` as mutable 20 | let z = Z { x: X::Y }; | - consider changing this to `mut z` 21 | let _ = &mut z.x; - | ^^^ + | ^^^ cannot mutably borrow immutable field error: aborting due to previous error |
