mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 02:00:00 +03:00
Be ambiguous when type cannot be properly mentioned
This commit is contained in:
@@ -346,6 +346,16 @@ fn new(kind: LoanPathKind<'tcx>, ty: Ty<'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 @@ pub fn report_use_of_moved_value(&self,
|
||||
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
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
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`
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -20,18 +20,15 @@ fn add_assign(&mut self, _: 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);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -13,6 +13,8 @@ pub fn main(){
|
||||
|
||||
loop {
|
||||
if let Some(thing) = maybe {
|
||||
//~^ ERROR use of partially moved value
|
||||
//~| ERROR use of moved value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user