Skip to content

Commit 57f10c7

Browse files
committed
Point to variable in asm! macro when failing borrowck
1 parent 0e07c42 commit 57f10c7

File tree

10 files changed

+49
-41
lines changed

10 files changed

+49
-41
lines changed

src/librustc/hir/lowering.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3953,6 +3953,7 @@ impl<'a> LoweringContext<'a> {
39533953
constraint: out.constraint.clone(),
39543954
is_rw: out.is_rw,
39553955
is_indirect: out.is_indirect,
3956+
span: out.expr.span,
39563957
})
39573958
.collect(),
39583959
asm: asm.asm.clone(),

src/librustc/hir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ pub struct InlineAsmOutput {
18121812
pub constraint: Symbol,
18131813
pub is_rw: bool,
18141814
pub is_indirect: bool,
1815+
pub span: Span,
18151816
}
18161817

18171818
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

src/librustc/ich/impls_hir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,8 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
983983
impl_stable_hash_for!(struct hir::InlineAsmOutput {
984984
constraint,
985985
is_rw,
986-
is_indirect
986+
is_indirect,
987+
span
987988
});
988989

989990
impl_stable_hash_for!(struct hir::GlobalAsm {

src/librustc/middle/expr_use_visitor.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
364364
}
365365

366366
fn mutate_expr(&mut self,
367+
span: Span,
367368
assignment_expr: &hir::Expr,
368369
expr: &hir::Expr,
369370
mode: MutateMode) {
370371
let cmt = return_if_err!(self.mc.cat_expr(expr));
371-
self.delegate.mutate(assignment_expr.id, assignment_expr.span, &cmt, mode);
372+
self.delegate.mutate(assignment_expr.id, span, &cmt, mode);
372373
self.walk_expr(expr);
373374
}
374375

@@ -472,12 +473,16 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
472473
if o.is_indirect {
473474
self.consume_expr(output);
474475
} else {
475-
self.mutate_expr(expr, output,
476-
if o.is_rw {
477-
MutateMode::WriteAndRead
478-
} else {
479-
MutateMode::JustWrite
480-
});
476+
self.mutate_expr(
477+
output.span,
478+
expr,
479+
output,
480+
if o.is_rw {
481+
MutateMode::WriteAndRead
482+
} else {
483+
MutateMode::JustWrite
484+
},
485+
);
481486
}
482487
}
483488
self.consume_exprs(inputs);
@@ -515,7 +520,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
515520
}
516521

517522
hir::ExprKind::Assign(ref lhs, ref rhs) => {
518-
self.mutate_expr(expr, &lhs, MutateMode::JustWrite);
523+
self.mutate_expr(expr.span, expr, &lhs, MutateMode::JustWrite);
519524
self.consume_expr(&rhs);
520525
}
521526

@@ -527,7 +532,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
527532
if self.mc.tables.is_method_call(expr) {
528533
self.consume_expr(lhs);
529534
} else {
530-
self.mutate_expr(expr, &lhs, MutateMode::WriteAndRead);
535+
self.mutate_expr(expr.span, expr, &lhs, MutateMode::WriteAndRead);
531536
}
532537
self.consume_expr(&rhs);
533538
}

src/librustc_mir/borrow_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,21 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
544544
// be encoeded through MIR place derefs instead.
545545
self.access_place(
546546
context,
547-
(output, span),
547+
(output, o.span),
548548
(Deep, Read(ReadKind::Copy)),
549549
LocalMutationIsAllowed::No,
550550
flow_state,
551551
);
552552
self.check_if_path_or_subpath_is_moved(
553553
context,
554554
InitializationRequiringAction::Use,
555-
(output, span),
555+
(output, o.span),
556556
flow_state,
557557
);
558558
} else {
559559
self.mutate_place(
560560
context,
561-
(output, span),
561+
(output, o.span),
562562
if o.is_rw { Deep } else { Shallow(None) },
563563
if o.is_rw { WriteAndRead } else { JustWrite },
564564
flow_state,

src/test/ui/asm/asm-out-assign-imm.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0384]: cannot assign twice to immutable variable `x`
2-
--> $DIR/asm-out-assign-imm.rs:34:9
2+
--> $DIR/asm-out-assign-imm.rs:34:34
33
|
44
LL | let x: isize;
55
| - help: make this binding mutable: `mut x`
66
LL | x = 1;
77
| ----- first assignment to `x`
88
...
99
LL | asm!("mov $1, $0" : "=r"(x) : "r"(5));
10-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
10+
| ^ cannot assign twice to immutable variable
1111

1212
error: aborting due to previous error
1313

src/test/ui/asm/asm-out-assign-imm.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0384]: cannot assign twice to immutable variable `x`
2-
--> $DIR/asm-out-assign-imm.rs:34:9
2+
--> $DIR/asm-out-assign-imm.rs:34:34
33
|
44
LL | x = 1;
55
| ----- first assignment to `x`
66
...
77
LL | asm!("mov $1, $0" : "=r"(x) : "r"(5));
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
8+
| ^ cannot assign twice to immutable variable
99

1010
error: aborting due to previous error
1111

src/test/ui/borrowck/borrowck-asm.ast.nll.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | let z = y;
2222
| - borrow later used here
2323

2424
error[E0384]: cannot assign twice to immutable variable `x`
25-
--> $DIR/borrowck-asm.rs:54:13
25+
--> $DIR/borrowck-asm.rs:54:31
2626
|
2727
LL | let x = 3;
2828
| -
@@ -31,10 +31,10 @@ LL | let x = 3;
3131
| help: make this binding mutable: `mut x`
3232
LL | unsafe {
3333
LL | asm!("nop" : "=r"(x)); //[ast]~ ERROR cannot assign twice
34-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
34+
| ^ cannot assign twice to immutable variable
3535

3636
error[E0384]: cannot assign twice to immutable variable `x`
37-
--> $DIR/borrowck-asm.rs:70:13
37+
--> $DIR/borrowck-asm.rs:70:31
3838
|
3939
LL | let x = 3;
4040
| -
@@ -43,22 +43,22 @@ LL | let x = 3;
4343
| help: make this binding mutable: `mut x`
4444
LL | unsafe {
4545
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign twice
46-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
46+
| ^ cannot assign twice to immutable variable
4747

4848
error[E0381]: use of possibly uninitialized variable: `x`
49-
--> $DIR/borrowck-asm.rs:78:13
49+
--> $DIR/borrowck-asm.rs:78:32
5050
|
5151
LL | asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitialized variable
52-
| ^^^^^^^^^^^^^^^^^^^^^^^ use of possibly uninitialized `x`
52+
| ^ use of possibly uninitialized `x`
5353

5454
error[E0506]: cannot assign to `x` because it is borrowed
55-
--> $DIR/borrowck-asm.rs:87:13
55+
--> $DIR/borrowck-asm.rs:87:31
5656
|
5757
LL | let y = &*x;
5858
| --- borrow of `x` occurs here
5959
LL | unsafe {
6060
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed
61-
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
61+
| ^ assignment to borrowed `x` occurs here
6262
...
6363
LL | let z = y;
6464
| - borrow later used here

src/test/ui/borrowck/borrowck-asm.ast.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ LL | asm!("nop" : : "r"(x)); //[ast]~ ERROR cannot use
1919
| ^ use of borrowed `x`
2020

2121
error[E0384]: cannot assign twice to immutable variable `x`
22-
--> $DIR/borrowck-asm.rs:54:13
22+
--> $DIR/borrowck-asm.rs:54:31
2323
|
2424
LL | let x = 3;
2525
| - first assignment to `x`
2626
LL | unsafe {
2727
LL | asm!("nop" : "=r"(x)); //[ast]~ ERROR cannot assign twice
28-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
28+
| ^ cannot assign twice to immutable variable
2929

3030
error[E0506]: cannot assign to `a` because it is borrowed
31-
--> $DIR/borrowck-asm.rs:60:13
31+
--> $DIR/borrowck-asm.rs:60:31
3232
|
3333
LL | let b = &*a;
3434
| -- borrow of `a` occurs here
3535
LL | unsafe {
3636
LL | asm!("nop" : "=r"(a)); //[ast]~ ERROR cannot assign to `a` because it is borrowed
37-
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here
37+
| ^ assignment to borrowed `a` occurs here
3838

3939
error[E0384]: cannot assign twice to immutable variable `x`
40-
--> $DIR/borrowck-asm.rs:70:13
40+
--> $DIR/borrowck-asm.rs:70:31
4141
|
4242
LL | let x = 3;
4343
| - first assignment to `x`
4444
LL | unsafe {
4545
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign twice
46-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
46+
| ^ cannot assign twice to immutable variable
4747

4848
error[E0381]: use of possibly uninitialized variable: `x`
4949
--> $DIR/borrowck-asm.rs:78:32
@@ -52,13 +52,13 @@ LL | asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitia
5252
| ^ use of possibly uninitialized `x`
5353

5454
error[E0506]: cannot assign to `x` because it is borrowed
55-
--> $DIR/borrowck-asm.rs:87:13
55+
--> $DIR/borrowck-asm.rs:87:31
5656
|
5757
LL | let y = &*x;
5858
| -- borrow of `x` occurs here
5959
LL | unsafe {
6060
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed
61-
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
61+
| ^ assignment to borrowed `x` occurs here
6262

6363
error[E0382]: use of moved value: `x`
6464
--> $DIR/borrowck-asm.rs:96:40

src/test/ui/borrowck/borrowck-asm.mir.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | let z = y;
2222
| - borrow later used here
2323

2424
error[E0384]: cannot assign twice to immutable variable `x`
25-
--> $DIR/borrowck-asm.rs:54:13
25+
--> $DIR/borrowck-asm.rs:54:31
2626
|
2727
LL | let x = 3;
2828
| -
@@ -31,10 +31,10 @@ LL | let x = 3;
3131
| help: make this binding mutable: `mut x`
3232
LL | unsafe {
3333
LL | asm!("nop" : "=r"(x)); //[ast]~ ERROR cannot assign twice
34-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
34+
| ^ cannot assign twice to immutable variable
3535

3636
error[E0384]: cannot assign twice to immutable variable `x`
37-
--> $DIR/borrowck-asm.rs:70:13
37+
--> $DIR/borrowck-asm.rs:70:31
3838
|
3939
LL | let x = 3;
4040
| -
@@ -43,22 +43,22 @@ LL | let x = 3;
4343
| help: make this binding mutable: `mut x`
4444
LL | unsafe {
4545
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign twice
46-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
46+
| ^ cannot assign twice to immutable variable
4747

4848
error[E0381]: use of possibly uninitialized variable: `x`
49-
--> $DIR/borrowck-asm.rs:78:13
49+
--> $DIR/borrowck-asm.rs:78:32
5050
|
5151
LL | asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitialized variable
52-
| ^^^^^^^^^^^^^^^^^^^^^^^ use of possibly uninitialized `x`
52+
| ^ use of possibly uninitialized `x`
5353

5454
error[E0506]: cannot assign to `x` because it is borrowed
55-
--> $DIR/borrowck-asm.rs:87:13
55+
--> $DIR/borrowck-asm.rs:87:31
5656
|
5757
LL | let y = &*x;
5858
| --- borrow of `x` occurs here
5959
LL | unsafe {
6060
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed
61-
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
61+
| ^ assignment to borrowed `x` occurs here
6262
...
6363
LL | let z = y;
6464
| - borrow later used here

0 commit comments

Comments
 (0)