Skip to content

Commit

Permalink
Point to variable in asm! macro when failing borrowck
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 9, 2018
1 parent 0e07c42 commit 57f10c7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/librustc/hir/lowering.rs
Expand Up @@ -3953,6 +3953,7 @@ impl<'a> LoweringContext<'a> {
constraint: out.constraint.clone(),
is_rw: out.is_rw,
is_indirect: out.is_indirect,
span: out.expr.span,
})
.collect(),
asm: asm.asm.clone(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/hir/mod.rs
Expand Up @@ -1812,6 +1812,7 @@ pub struct InlineAsmOutput {
pub constraint: Symbol,
pub is_rw: bool,
pub is_indirect: bool,
pub span: Span,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_hir.rs
Expand Up @@ -983,7 +983,8 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
impl_stable_hash_for!(struct hir::InlineAsmOutput {
constraint,
is_rw,
is_indirect
is_indirect,
span
});

impl_stable_hash_for!(struct hir::GlobalAsm {
Expand Down
23 changes: 14 additions & 9 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -364,11 +364,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
}

fn mutate_expr(&mut self,
span: Span,
assignment_expr: &hir::Expr,
expr: &hir::Expr,
mode: MutateMode) {
let cmt = return_if_err!(self.mc.cat_expr(expr));
self.delegate.mutate(assignment_expr.id, assignment_expr.span, &cmt, mode);
self.delegate.mutate(assignment_expr.id, span, &cmt, mode);
self.walk_expr(expr);
}

Expand Down Expand Up @@ -472,12 +473,16 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
if o.is_indirect {
self.consume_expr(output);
} else {
self.mutate_expr(expr, output,
if o.is_rw {
MutateMode::WriteAndRead
} else {
MutateMode::JustWrite
});
self.mutate_expr(
output.span,
expr,
output,
if o.is_rw {
MutateMode::WriteAndRead
} else {
MutateMode::JustWrite
},
);
}
}
self.consume_exprs(inputs);
Expand Down Expand Up @@ -515,7 +520,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
}

hir::ExprKind::Assign(ref lhs, ref rhs) => {
self.mutate_expr(expr, &lhs, MutateMode::JustWrite);
self.mutate_expr(expr.span, expr, &lhs, MutateMode::JustWrite);
self.consume_expr(&rhs);
}

Expand All @@ -527,7 +532,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
if self.mc.tables.is_method_call(expr) {
self.consume_expr(lhs);
} else {
self.mutate_expr(expr, &lhs, MutateMode::WriteAndRead);
self.mutate_expr(expr.span, expr, &lhs, MutateMode::WriteAndRead);
}
self.consume_expr(&rhs);
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -544,21 +544,21 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
// be encoeded through MIR place derefs instead.
self.access_place(
context,
(output, span),
(output, o.span),
(Deep, Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
flow_state,
);
self.check_if_path_or_subpath_is_moved(
context,
InitializationRequiringAction::Use,
(output, span),
(output, o.span),
flow_state,
);
} else {
self.mutate_place(
context,
(output, span),
(output, o.span),
if o.is_rw { Deep } else { Shallow(None) },
if o.is_rw { WriteAndRead } else { JustWrite },
flow_state,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/asm/asm-out-assign-imm.nll.stderr
@@ -1,13 +1,13 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/asm-out-assign-imm.rs:34:9
--> $DIR/asm-out-assign-imm.rs:34:34
|
LL | let x: isize;
| - help: make this binding mutable: `mut x`
LL | x = 1;
| ----- first assignment to `x`
...
LL | asm!("mov $1, $0" : "=r"(x) : "r"(5));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
| ^ cannot assign twice to immutable variable

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/asm/asm-out-assign-imm.stderr
@@ -1,11 +1,11 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/asm-out-assign-imm.rs:34:9
--> $DIR/asm-out-assign-imm.rs:34:34
|
LL | x = 1;
| ----- first assignment to `x`
...
LL | asm!("mov $1, $0" : "=r"(x) : "r"(5));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
| ^ cannot assign twice to immutable variable

error: aborting due to previous error

Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/borrowck/borrowck-asm.ast.nll.stderr
Expand Up @@ -22,7 +22,7 @@ LL | let z = y;
| - borrow later used here

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

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

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

error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/borrowck-asm.rs:87:13
--> $DIR/borrowck-asm.rs:87:31
|
LL | let y = &*x;
| --- borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here
| ^ assignment to borrowed `x` occurs here
...
LL | let z = y;
| - borrow later used here
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/borrowck/borrowck-asm.ast.stderr
Expand Up @@ -19,31 +19,31 @@ LL | asm!("nop" : : "r"(x)); //[ast]~ ERROR cannot use
| ^ use of borrowed `x`

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

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

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

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

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

error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:96:40
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/borrowck/borrowck-asm.mir.stderr
Expand Up @@ -22,7 +22,7 @@ LL | let z = y;
| - borrow later used here

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

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

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

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

0 comments on commit 57f10c7

Please sign in to comment.