Skip to content

Commit 4280992

Browse files
author
Jonathan Turner
committed
Fix #33819 and update ui test
1 parent 9e55748 commit 4280992

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/librustc_borrowck/borrowck/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
977977
if let Categorization::Local(local_id) = err.cmt.cat {
978978
let span = self.tcx.map.span(local_id);
979979
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
980-
if snippet != "self" {
980+
if snippet.starts_with("ref ") {
981+
db.span_label(span,
982+
&format!("use `{}` here to make mutable",
983+
snippet.replace("ref ", "ref mut ")));
984+
} else if snippet != "self" {
981985
db.span_label(span,
982986
&format!("use `mut {}` here to make mutable", snippet));
983987
}

src/test/compile-fail/issue-33819.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let mut op = Some(2);
3+
match op {
4+
Some(ref v) => { let a = &mut v; },
5+
//~^ ERROR:cannot borrow immutable
6+
//~| use `ref mut v` here to make mutable
7+
None => {},
8+
}
9+
}
+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error: mismatched types [--explain E0308]
22
--> $DIR/main.rs:14:18
3+
|>
34
14 |> let x: u32 = (
45
|> ^ expected u32, found ()
56
note: expected type `u32`
67
note: found type `()`
78

9+
810
error: aborting due to previous error

0 commit comments

Comments
 (0)