Skip to content

Commit 094d67e

Browse files
committed
mir-borrowck: Remove parens in the lvalue description of a deref
1 parent d8d5b61 commit 094d67e

6 files changed

+14
-15
lines changed

src/librustc_mir/borrow_check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1601,9 +1601,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16011601
if autoderef {
16021602
self.append_lvalue_to_string(&proj.base, buf, Some(autoderef));
16031603
} else {
1604-
buf.push_str(&"(*");
1604+
buf.push_str(&"*");
16051605
self.append_lvalue_to_string(&proj.base, buf, Some(autoderef));
1606-
buf.push_str(&")");
16071606
}
16081607
},
16091608
ProjectionElem::Downcast(..) => {

src/test/compile-fail/borrowck/borrowck-closures-mut-and-imm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn f() {
7070
let c1 = || get(&*x);
7171
*x = 5; //[ast]~ ERROR cannot assign
7272
//[mir]~^ ERROR cannot assign to `*x` because it is borrowed (Ast)
73-
//[mir]~| ERROR cannot assign to `(*x)` because it is borrowed (Mir)
73+
//[mir]~| ERROR cannot assign to `*x` because it is borrowed (Mir)
7474
}
7575

7676
fn g() {
@@ -82,7 +82,7 @@ fn g() {
8282
let c1 = || get(&*x.f);
8383
*x.f = 5; //[ast]~ ERROR cannot assign to `*x.f`
8484
//[mir]~^ ERROR cannot assign to `*x.f` because it is borrowed (Ast)
85-
//[mir]~| ERROR cannot assign to `(*x.f)` because it is borrowed (Mir)
85+
//[mir]~| ERROR cannot assign to `*x.f` because it is borrowed (Mir)
8686
}
8787

8888
fn h() {

src/test/compile-fail/borrowck/borrowck-describe-lvalue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn main() {
252252
fn bump<'a>(mut block: &mut Block<'a>) {
253253
let x = &mut block;
254254
let p: &'a u8 = &*block.current;
255-
//[mir]~^ ERROR cannot borrow `(*block.current)` as immutable because it is also borrowed as mutable (Mir)
255+
//[mir]~^ ERROR cannot borrow `*block.current` as immutable because it is also borrowed as mutable (Mir)
256256
// No errors in AST because of issue rust#38899
257257
}
258258
}
@@ -266,7 +266,7 @@ fn main() {
266266
unsafe fn bump2(mut block: *mut Block2) {
267267
let x = &mut block;
268268
let p : *const u8 = &*(*block).current;
269-
//[mir]~^ ERROR cannot borrow `(*block.current)` as immutable because it is also borrowed as mutable (Mir)
269+
//[mir]~^ ERROR cannot borrow `*block.current` as immutable because it is also borrowed as mutable (Mir)
270270
// No errors in AST because of issue rust#38899
271271
}
272272
}
@@ -279,7 +279,7 @@ fn main() {
279279
//[ast]~^ ERROR cannot use `v[..].y` because it was mutably borrowed
280280
//[mir]~^^ ERROR cannot use `v[..].y` because it was mutably borrowed (Ast)
281281
//[mir]~| ERROR cannot use `v[..].y` because it was mutably borrowed (Mir)
282-
//[mir]~| ERROR cannot use `(*v)` because it was mutably borrowed (Mir)
282+
//[mir]~| ERROR cannot use `*v` because it was mutably borrowed (Mir)
283283
}
284284
// Field of constant index
285285
{
@@ -300,7 +300,7 @@ fn main() {
300300
let y = &mut x;
301301
&mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
302302
//[mir]~^ ERROR cannot borrow `**x` as mutable more than once at a time (Ast)
303-
//[mir]~| ERROR cannot borrow `(*x)` as mutable more than once at a time (Mir)
303+
//[mir]~| ERROR cannot borrow `*x` as mutable more than once at a time (Mir)
304304
*y = 1;
305305
};
306306
}
@@ -312,7 +312,7 @@ fn main() {
312312
let y = &mut x;
313313
&mut x; //[ast]~ ERROR cannot borrow `**x` as mutable more than once at a time
314314
//[mir]~^ ERROR cannot borrow `**x` as mutable more than once at a time (Ast)
315-
//[mir]~| ERROR cannot borrow `(*x)` as mutable more than once at a time (Mir)
315+
//[mir]~| ERROR cannot borrow `*x` as mutable more than once at a time (Mir)
316316
*y = 1;
317317
}
318318
};

src/test/compile-fail/coerce-overloaded-autoderef.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn double_mut_borrow<T>(x: &mut Box<T>) {
2222
let z = borrow_mut(x);
2323
//[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
2424
//[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time (Ast)
25-
//[mir]~| ERROR cannot borrow `(*x)` as mutable more than once at a time (Mir)
25+
//[mir]~| ERROR cannot borrow `*x` as mutable more than once at a time (Mir)
2626
}
2727

2828
fn double_imm_borrow(x: &mut Box<i32>) {
@@ -31,21 +31,21 @@ fn double_imm_borrow(x: &mut Box<i32>) {
3131
**x += 1;
3232
//[ast]~^ ERROR cannot assign to `**x` because it is borrowed
3333
//[mir]~^^ ERROR cannot assign to `**x` because it is borrowed (Ast)
34-
//[mir]~| ERROR cannot assign to `(*(*x))` because it is borrowed (Mir)
34+
//[mir]~| ERROR cannot assign to `**x` because it is borrowed (Mir)
3535
}
3636

3737
fn double_mut_borrow2<T>(x: &mut Box<T>) {
3838
borrow_mut2(x, x);
3939
//[ast]~^ ERROR cannot borrow `*x` as mutable more than once at a time
4040
//[mir]~^^ ERROR cannot borrow `*x` as mutable more than once at a time (Ast)
41-
//[mir]~| ERROR cannot borrow `(*x)` as mutable more than once at a time (Mir)
41+
//[mir]~| ERROR cannot borrow `*x` as mutable more than once at a time (Mir)
4242
}
4343

4444
fn double_borrow2<T>(x: &mut Box<T>) {
4545
borrow2(x, x);
4646
//[ast]~^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable
4747
//[mir]~^^ ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable (Ast)
48-
//[mir]~| ERROR cannot borrow `(*x)` as immutable because it is also borrowed as mutable (Mir)
48+
//[mir]~| ERROR cannot borrow `*x` as immutable because it is also borrowed as mutable (Mir)
4949
}
5050

5151
pub fn main() {}

src/test/compile-fail/mut-pattern-internal-mutability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ fn main() {
2727
let &mut ref x = foo;
2828
*foo += 1; //[ast]~ ERROR cannot assign to `*foo` because it is borrowed
2929
//[mir]~^ ERROR cannot assign to `*foo` because it is borrowed (Ast)
30-
//[mir]~| ERROR cannot assign to `(*foo)` because it is borrowed (Mir)
30+
//[mir]~| ERROR cannot assign to `*foo` because it is borrowed (Mir)
3131
}

src/test/ui/nll/get_default.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as imm
3434
51 | }
3535
| - immutable borrow ends here
3636

37-
error[E0502]: cannot borrow `(*map)` as mutable because it is also borrowed as immutable (Mir)
37+
error[E0502]: cannot borrow `*map` as mutable because it is also borrowed as immutable (Mir)
3838
--> $DIR/get_default.rs:43:17
3939
|
4040
41 | match map.get() {

0 commit comments

Comments
 (0)