diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-01-01 22:23:13 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-01-02 19:49:38 -0800 |
| commit | 48b684a40a503a85f5e62f03ea7217d40fee6e1a (patch) | |
| tree | 5ed7120b48dfb90648fbbb1ed25a87c2a77da7f2 | |
| parent | 6c506d4c71f957fa5ca50d364c7f56daa0872064 (diff) | |
| download | rust-48b684a40a503a85f5e62f03ea7217d40fee6e1a.tar.gz rust-48b684a40a503a85f5e62f03ea7217d40fee6e1a.zip | |
Be ambiguous when type cannot be properly mentioned
| -rw-r--r-- | src/librustc_borrowck/borrowck/mod.rs | 40 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-24357.rs | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/augmented-assignments.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/borrowck/borrowck-box-insensitivity.rs | 51 | ||||
| -rw-r--r-- | src/test/ui/borrowck/issue-41962.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/borrowck/issue-41962.stderr | 7 | ||||
| -rw-r--r-- | src/test/ui/moves-based-on-type-match-bindings.rs | 4 |
8 files changed, 72 insertions, 56 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index b33cd19b7a9..99403d01239 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -346,6 +346,16 @@ impl<'tcx> LoanPath<'tcx> { } fn to_type(&self) -> Ty<'tcx> { self.ty } + + fn is_downcast(&self) -> bool { + match self.kind { + LpDowncast(_, _) => true, + LpExtend(ref lp, _, LpInterior(_, _)) => { + lp.is_downcast() + } + _ => false, + } + } } // FIXME (pnkfelix): See discussion here @@ -711,28 +721,26 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { err = if use_span == move_span { err.span_label( use_span, - format!("value moved{} here in previous iteration of loop{}", - move_note, - extra_move_label)); - - if need_note { - err.note(&format!("value moved because it has type `{}`, \ - which does not implement the `Copy` trait", - moved_lp.ty) - } + format!("value moved{} here in previous iteration of loop", + move_note)); err } else { err.span_label(use_span, format!("value {} here after move", verb_participle)); - let extra_move_label = if need_note { - &format!(" because it has type `{}`, which does not implement the `Copy` trait", - moved_lp.ty) - } else { - "" - }; - err.span_label(move_span,format!("value moved{} here{}", move_note, extra_move_label)); + err.span_label(move_span, format!("value moved{} here", move_note)); err }; + if need_note { + err.note(&format!( + "move occurs because {} has type `{}`, which does not implement the `Copy` trait", + if moved_lp.is_downcast() { + "the value".to_string() + } else { + format!("`{}`", self.loan_path_to_string(moved_lp)) + }, + moved_lp.ty)); + } + // Note: we used to suggest adding a `ref binding` or calling // `clone` but those suggestions have been removed because // they are often not what you actually want to do, and were diff --git a/src/test/compile-fail/issue-24357.rs b/src/test/compile-fail/issue-24357.rs index 544679171b4..016ce93a0bd 100644 --- a/src/test/compile-fail/issue-24357.rs +++ b/src/test/compile-fail/issue-24357.rs @@ -12,8 +12,9 @@ struct NoCopy; fn main() { let x = NoCopy; let f = move || { let y = x; }; - //~^ NOTE value moved (into closure) here because it has type `NoCopy`, which does not + //~^ NOTE value moved (into closure) here let z = x; //~^ ERROR use of moved value: `x` //~| NOTE value used here after move + //~| NOTE move occurs because `x` has type `NoCopy` } diff --git a/src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs b/src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs index 0929e0b57d3..5329dcaaaf4 100644 --- a/src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs +++ b/src/test/compile-fail/moves-based-on-type-distribute-copy-over-paren.rs @@ -17,17 +17,19 @@ fn touch<A>(_a: &A) {} fn f00() { let x = "hi".to_string(); let _y = Foo { f:x }; - //~^ NOTE value moved here because it has type + //~^ NOTE value moved here touch(&x); //~ ERROR use of moved value: `x` //~^ NOTE value used here after move + //~| NOTE move occurs because `x` has type `std::string::String` } fn f05() { let x = "hi".to_string(); let _y = Foo { f:(((x))) }; - //~^ NOTE value moved here because it has type + //~^ NOTE value moved here touch(&x); //~ ERROR use of moved value: `x` //~^ NOTE value used here after move + //~| NOTE move occurs because `x` has type `std::string::String` } fn f10() { diff --git a/src/test/ui/augmented-assignments.rs b/src/test/ui/augmented-assignments.rs index 0ac48990be4..82f5c49eeb7 100644 --- a/src/test/ui/augmented-assignments.rs +++ b/src/test/ui/augmented-assignments.rs @@ -20,18 +20,15 @@ impl AddAssign for Int { fn main() { let mut x = Int(1); - x - //~^ error: use of moved value: `x` - //~| note: value used here after move + x //~ error: use of moved value: `x` + //~^ value used here after move += - x; - //~^ note: value moved here because it has type `Int`, which does not implement the `Copy` + x; //~ value moved here let y = Int(2); - //~^ note: consider changing this to `mut y` - y - //~^ error: cannot borrow immutable local variable `y` as mutable - //~| note: cannot borrow mutably + //~^ consider changing this to `mut y` + y //~ error: cannot borrow immutable local variable `y` as mutable + //~| cannot borrow += Int(1); } diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.rs b/src/test/ui/borrowck/borrowck-box-insensitivity.rs index a2b2d425f1d..75bf6bce04b 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.rs +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.rs @@ -33,25 +33,28 @@ struct D { fn copy_after_move() { let a: Box<_> = box A { x: box 0, y: 1 }; let _x = a.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not - let _y = a.y; //~ ERROR use of moved value - //~^ NOTE value used here after move + //~^ value moved here + let _y = a.y; //~ ERROR use of moved + //~^ move occurs because `a.x` has type `std::boxed::Box<isize>` + //~| value used here after move } fn move_after_move() { let a: Box<_> = box B { x: box 0, y: box 1 }; let _x = a.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not + //~^ value moved here let _y = a.y; //~ ERROR use of moved - //~^ NOTE value used here after move + //~^ move occurs because `a.x` has type `std::boxed::Box<isize>` + //~| value used here after move } fn borrow_after_move() { let a: Box<_> = box A { x: box 0, y: 1 }; let _x = a.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not + //~^ value moved here let _y = &a.y; //~ ERROR use of moved - //~^ NOTE value used here after move + //~^ move occurs because `a.x` has type `std::boxed::Box<isize>` + //~| value used here after move } fn move_after_borrow() { @@ -59,7 +62,7 @@ fn move_after_borrow() { let _x = &a.x; let _y = a.y; //~^ ERROR cannot move - //~| NOTE move out of + //~| move out of } fn copy_after_mut_borrow() { @@ -73,54 +76,54 @@ fn move_after_mut_borrow() { let _x = &mut a.x; let _y = a.y; //~^ ERROR cannot move - //~| NOTE move out of + //~| move out of } fn borrow_after_mut_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &mut a.x; let _y = &a.y; //~ ERROR cannot borrow - //~^ NOTE immutable borrow occurs here (via `a.y`) + //~^ immutable borrow occurs here (via `a.y`) } fn mut_borrow_after_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &a.x; let _y = &mut a.y; //~ ERROR cannot borrow - //~^ NOTE mutable borrow occurs here (via `a.y`) + //~^ mutable borrow occurs here (via `a.y`) } fn copy_after_move_nested() { let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = a.x.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not + //~^ value moved here let _y = a.y; //~ ERROR use of collaterally moved - //~^ NOTE value used here after move + //~| value used here after move } fn move_after_move_nested() { let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = a.x.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not + //~^ value moved here let _y = a.y; //~ ERROR use of collaterally moved - //~^ NOTE value used here after move + //~| value used here after move } fn borrow_after_move_nested() { let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = a.x.x; - //~^ NOTE value moved here because it has type `std::boxed::Box<isize>`, which does not + //~^ value moved here let _y = &a.y; //~ ERROR use of collaterally moved - //~^ NOTE value used here after move + //~| value used here after move } fn move_after_borrow_nested() { let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &a.x.x; - //~^ NOTE borrow of `a.x.x` occurs here + //~^ borrow of `a.x.x` occurs here let _y = a.y; //~^ ERROR cannot move - //~| NOTE move out of + //~| move out of } fn copy_after_mut_borrow_nested() { @@ -134,23 +137,23 @@ fn move_after_mut_borrow_nested() { let _x = &mut a.x.x; let _y = a.y; //~^ ERROR cannot move - //~| NOTE move out of + //~| move out of } fn borrow_after_mut_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &mut a.x.x; - //~^ NOTE mutable borrow occurs here + //~^ mutable borrow occurs here let _y = &a.y; //~ ERROR cannot borrow - //~^ NOTE immutable borrow occurs here + //~^ immutable borrow occurs here } fn mut_borrow_after_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &a.x.x; - //~^ NOTE immutable borrow occurs here + //~^ immutable borrow occurs here let _y = &mut a.y; //~ ERROR cannot borrow - //~^ NOTE mutable borrow occurs here + //~^ mutable borrow occurs here } fn main() { diff --git a/src/test/ui/borrowck/issue-41962.rs b/src/test/ui/borrowck/issue-41962.rs index a8e1edbdfdf..d8a4436532a 100644 --- a/src/test/ui/borrowck/issue-41962.rs +++ b/src/test/ui/borrowck/issue-41962.rs @@ -13,6 +13,8 @@ pub fn main(){ loop { if let Some(thing) = maybe { + //~^ ERROR use of partially moved value + //~| ERROR use of moved value } } } diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index caa67835ee5..51e4409c81f 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -4,14 +4,17 @@ error[E0382]: use of partially moved value: `maybe` 15 | if let Some(thing) = maybe { | ----- ^^^^^ value used here after move | | - | value moved here because it has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait + | value moved here + | + = note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait error[E0382]: use of moved value: `(maybe as std::prelude::v1::Some).0` --> $DIR/issue-41962.rs:15:21 | 15 | if let Some(thing) = maybe { | ^^^^^ value moved here in previous iteration of loop - = note: value moved because it has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait + | + = note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait error: aborting due to 2 previous errors diff --git a/src/test/ui/moves-based-on-type-match-bindings.rs b/src/test/ui/moves-based-on-type-match-bindings.rs index c08c1a788c1..1fd3d03570a 100644 --- a/src/test/ui/moves-based-on-type-match-bindings.rs +++ b/src/test/ui/moves-based-on-type-match-bindings.rs @@ -21,11 +21,11 @@ fn f10() { let y = match x { Foo {f} => {} - //~^ NOTE value moved here because it has type `std::string::String`, which does not }; touch(&x); //~ ERROR use of partially moved value: `x` - //~^ NOTE value used here after move + //~^ value used here after move + //~| move occurs because `x.f` has type `std::string::String` } fn main() {} |
