Skip to content

Commit

Permalink
Tweak move error due to non-Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 25, 2019
1 parent 9a59541 commit 9c97d73
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 175 deletions.
9 changes: 2 additions & 7 deletions src/librustc_mir/borrow_check/move_errors.rs
Expand Up @@ -555,7 +555,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'a>,
binds_to: &[Local],
) {
let mut noncopy_var_spans = Vec::new();
for (j, local) in binds_to.into_iter().enumerate() {
let bind_to = &self.body.local_decls[*local];
let binding_span = bind_to.source_info.span;
Expand All @@ -573,16 +572,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
bind_to.ty,
Some(binding_span)
);
} else {
noncopy_var_spans.push(binding_span);
}
}

if binds_to.len() > 1 {
err.span_note(
noncopy_var_spans,
"move occurs because these variables have types that \
don't implement the `Copy` trait",
err.note("move occurs because these variables have types that \
don't implement the `Copy` trait",
);
}
}
Expand Down
18 changes: 2 additions & 16 deletions src/test/ui/borrowck/borrowck-move-error-with-note.stderr
Expand Up @@ -10,15 +10,7 @@ LL | num2) => (),
LL | Foo::Foo2(num) => (),
| --- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-error-with-note.rs:12:19
|
LL | Foo::Foo1(num1,
| ^^^^
LL | num2) => (),
| ^^^^
LL | Foo::Foo2(num) => (),
| ^^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
--> $DIR/borrowck-move-error-with-note.rs:28:11
Expand All @@ -31,13 +23,7 @@ LL | f: _s,
LL | g: _t
| -- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-error-with-note.rs:31:16
|
LL | f: _s,
| ^^
LL | g: _t
| ^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0507]: cannot move out of `a.a` which is behind a shared reference
--> $DIR/borrowck-move-error-with-note.rs:46:11
Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr
Expand Up @@ -9,13 +9,7 @@ LL | &[Foo { string: a },
LL | Foo { string: b }] => {
| - ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-out-of-vec-tail.rs:21:33
|
LL | &[Foo { string: a },
| ^
LL | Foo { string: b }] => {
| ^
= note: move occurs because these variables have types that don't implement the `Copy` trait
help: consider removing the `&`
|
LL | [Foo { string: a },
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
Expand Up @@ -75,12 +75,12 @@ fn e() {
match vec {
//~^ ERROR cannot move out
//~| NOTE cannot move out
//~| NOTE move occurs because these variables have types
&mut [_a, _b, _c] => {}
//~^ NOTE data moved here
//~| NOTE and here
//~| NOTE and here
//~| HELP consider removing the `&mut`
//~| NOTE move occurs because these variables have types
_ => {}
}
let a = vec[0]; //~ ERROR cannot move out
Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr
Expand Up @@ -97,11 +97,7 @@ LL | &mut [_a, _b, _c] => {}
| | data moved here
| help: consider removing the `&mut`: `[_a, _b, _c]`
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-vec-pattern-nesting.rs:78:15
|
LL | &mut [_a, _b, _c] => {}
| ^^ ^^ ^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
--> $DIR/borrowck-vec-pattern-nesting.rs:86:13
Expand Down
18 changes: 2 additions & 16 deletions src/test/ui/issues/issue-12567.stderr
Expand Up @@ -10,14 +10,7 @@ LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| --- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/issue-12567.rs:8:17
|
LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
| ^^
LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| ^^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0508]: cannot move out of type `[T]`, a non-copy slice
--> $DIR/issue-12567.rs:4:11
Expand All @@ -31,14 +24,7 @@ LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| --- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/issue-12567.rs:8:17
|
LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
| ^^
LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| ^^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error: aborting due to 2 previous errors

Expand Down
Expand Up @@ -7,11 +7,7 @@ LL | let (a, b) = x[0];
| | ...and here
| data moved here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/issue-40402-2.rs:5:10
|
LL | let (a, b) = x[0];
| ^ ^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error: aborting due to previous error

Expand Down
14 changes: 2 additions & 12 deletions src/test/ui/nll/move-errors.stderr
Expand Up @@ -83,13 +83,7 @@ LL | B::U(d) => (),
LL | B::V(s) => (),
| - ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/move-errors.rs:76:14
|
LL | B::U(d) => (),
| ^
LL | B::V(s) => (),
| ^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> $DIR/move-errors.rs:83:11
Expand Down Expand Up @@ -138,11 +132,7 @@ LL | F(s, mut t) => (),
| |
| data moved here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/move-errors.rs:104:11
|
LL | F(s, mut t) => (),
| ^ ^^^^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0507]: cannot move out of `x.0` which is behind a shared reference
--> $DIR/move-errors.rs:110:11
Expand Down

0 comments on commit 9c97d73

Please sign in to comment.