]> git.lizzy.rs Git - rust.git/commitdiff
Point to variable in `asm!` macro when failing borrowck
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 9 Oct 2018 22:53:37 +0000 (15:53 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 9 Oct 2018 22:53:37 +0000 (15:53 -0700)
src/librustc/hir/lowering.rs
src/librustc/hir/mod.rs
src/librustc/ich/impls_hir.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc_mir/borrow_check/mod.rs
src/test/ui/asm/asm-out-assign-imm.nll.stderr
src/test/ui/asm/asm-out-assign-imm.stderr
src/test/ui/borrowck/borrowck-asm.ast.nll.stderr
src/test/ui/borrowck/borrowck-asm.ast.stderr
src/test/ui/borrowck/borrowck-asm.mir.stderr

index 7309358091056e32bc512e7536d5b0d05b6681fe..4d51126621d7dcaf66d10f50170d892d17fdd54a 100644 (file)
@@ -3953,6 +3953,7 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                             constraint: out.constraint.clone(),
                             is_rw: out.is_rw,
                             is_indirect: out.is_indirect,
+                            span: out.expr.span,
                         })
                         .collect(),
                     asm: asm.asm.clone(),
index c57c26434e32af38012a12d1554b05de6e93f83d..1a97c678ef1c0a4cb2893a61e5cc10c4bd1d205b 100644 (file)
@@ -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)]
index da9604702dfa38ac91545a898231deb40b08a95c..9f4ac77fa1fe1483d4f832e491b4720e6f3ac02c 100644 (file)
@@ -983,7 +983,8 @@ fn to_stable_hash_key(&self,
 impl_stable_hash_for!(struct hir::InlineAsmOutput {
     constraint,
     is_rw,
-    is_indirect
+    is_indirect,
+    span
 });
 
 impl_stable_hash_for!(struct hir::GlobalAsm {
index d6b43ffe6da625dc73aefd8d0b4cb4761e88d814..7e9b26bbf729c357a70ac32a9e0c3ed2426738d1 100644 (file)
@@ -364,11 +364,12 @@ pub fn consume_expr(&mut self, expr: &hir::Expr) {
     }
 
     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);
     }
 
@@ -472,12 +473,16 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
                     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);
@@ -515,7 +520,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
             }
 
             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);
             }
 
@@ -527,7 +532,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
                 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);
             }
index 0943b36440aa67c7fc2f2f65c814d22f1c76e750..9cbaf35acd33fe978ae9fa0e73496a941352c249 100644 (file)
@@ -544,7 +544,7 @@ fn visit_statement_entry(
                         // be encoeded through MIR place derefs instead.
                         self.access_place(
                             context,
-                            (output, span),
+                            (output, o.span),
                             (Deep, Read(ReadKind::Copy)),
                             LocalMutationIsAllowed::No,
                             flow_state,
@@ -552,13 +552,13 @@ fn visit_statement_entry(
                         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,
index 7fefb6672c76bce79aad3017232d7173c49f639a..40a36dd895f772b9b82b217f2004418f1029188b 100644 (file)
@@ -1,5 +1,5 @@
 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`
@@ -7,7 +7,7 @@ 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
 
index 83cb8092e16a29e7174f5e24a616e8bbfa610ba6..51933cac39692003261bc72e51121fe5c3b78648 100644 (file)
@@ -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
 
index b0f0535b9f6c7aefe768775756dc4bffe85f6d19..0cec1975db8805e7b1d6bfbdfc034452914fdf14 100644 (file)
@@ -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;
    |             -
@@ -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;
    |             -
@@ -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
index e2e54aa9b8ad9cf8524773f5bd7896452bf2e4b6..5856a1b0790b217c50a044685e3d2915b2ab4b62 100644 (file)
@@ -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
@@ -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
index b0f0535b9f6c7aefe768775756dc4bffe85f6d19..0cec1975db8805e7b1d6bfbdfc034452914fdf14 100644 (file)
@@ -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;
    |             -
@@ -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;
    |             -
@@ -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