2018-08-13 05:17:53 -05:00
|
|
|
#[derive(Clone)]
|
2018-08-07 03:02:39 -05:00
|
|
|
enum Either {
|
|
|
|
One(X),
|
|
|
|
Two(X),
|
|
|
|
}
|
|
|
|
|
2018-08-13 05:17:53 -05:00
|
|
|
#[derive(Clone)]
|
2018-08-07 03:02:39 -05:00
|
|
|
struct X(Y);
|
|
|
|
|
2018-08-13 05:17:53 -05:00
|
|
|
#[derive(Clone)]
|
2018-08-07 03:02:39 -05:00
|
|
|
struct Y;
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let e = Either::One(X(Y));
|
|
|
|
let mut em = Either::One(X(Y));
|
|
|
|
|
|
|
|
let r = &e;
|
|
|
|
let rm = &mut Either::One(X(Y));
|
|
|
|
|
|
|
|
let x = X(Y);
|
|
|
|
let mut xm = X(Y);
|
|
|
|
|
|
|
|
let s = &x;
|
|
|
|
let sm = &mut X(Y);
|
|
|
|
|
2018-08-08 01:34:01 -05:00
|
|
|
let ve = vec![Either::One(X(Y))];
|
|
|
|
|
|
|
|
let vr = &ve;
|
|
|
|
let vrm = &mut vec![Either::One(X(Y))];
|
|
|
|
|
|
|
|
let vx = vec![X(Y)];
|
|
|
|
|
2018-08-12 18:07:19 -05:00
|
|
|
let vs = &vx;
|
2018-08-08 01:34:01 -05:00
|
|
|
let vsm = &mut vec![X(Y)];
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// move from Either/X place
|
2018-08-07 03:02:39 -05:00
|
|
|
|
|
|
|
let X(_t) = *s;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
if let Either::One(_t) = *r { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
while let Either::One(_t) = *r { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
match *r {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::One(_t)
|
|
|
|
| Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
match *r {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref _t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let X(_t) = *sm;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
if let Either::One(_t) = *rm { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
while let Either::One(_t) = *rm { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
match *rm {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::One(_t)
|
|
|
|
| Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
match *rm {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref _t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
match *rm {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-09 15:01:41 -06:00
|
|
|
//~| HELP consider removing the dereference here
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref mut _t) => (),
|
2018-08-14 13:56:20 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
|
2018-08-12 18:07:19 -05:00
|
|
|
let X(_t) = vs[0];
|
2018-08-08 01:34:01 -05:00
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
if let Either::One(_t) = vr[0] { }
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
while let Either::One(_t) = vr[0] { }
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
match vr[0] {
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
Either::One(_t)
|
|
|
|
| Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
match vr[0] {
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref _t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-08 01:34:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let X(_t) = vsm[0];
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
if let Either::One(_t) = vrm[0] { }
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
while let Either::One(_t) = vrm[0] { }
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
match vrm[0] {
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
Either::One(_t)
|
|
|
|
| Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
match vrm[0] {
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref _t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-08 01:34:01 -05:00
|
|
|
}
|
|
|
|
match vrm[0] {
|
|
|
|
//~^ ERROR cannot move
|
2018-08-12 15:55:34 -05:00
|
|
|
//~| HELP consider borrowing here
|
2018-08-08 01:34:01 -05:00
|
|
|
Either::One(_t) => (),
|
|
|
|
Either::Two(ref mut _t) => (),
|
2018-08-14 13:56:20 -05:00
|
|
|
// FIXME: should suggest removing `ref` too
|
2018-08-08 01:34:01 -05:00
|
|
|
}
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// move from &Either/&X place
|
2018-08-07 03:02:39 -05:00
|
|
|
|
|
|
|
let &X(_t) = s;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
if let &Either::One(_t) = r { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
while let &Either::One(_t) = r { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
match r {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t)
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
| &Either::Two(_t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: would really like a suggestion here too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
match r {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&Either::Two(ref _t) => (),
|
|
|
|
}
|
|
|
|
match r {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
fn f1(&X(_t): &X) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
|
|
|
|
let &mut X(_t) = sm;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
if let &mut Either::One(_t) = rm { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
while let &mut Either::One(_t) = rm { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
match rm {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&mut Either::Two(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
match rm {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&mut Either::Two(ref _t) => (),
|
|
|
|
}
|
|
|
|
match rm {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&mut Either::Two(ref mut _t) => (),
|
|
|
|
}
|
|
|
|
match rm {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
fn f2(&mut X(_t): &mut X) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// move from tuple of &Either/&X
|
2018-08-13 23:49:39 -05:00
|
|
|
|
|
|
|
// FIXME: These should have suggestions.
|
2018-08-13 17:52:23 -05:00
|
|
|
|
|
|
|
let (&X(_t),) = (&x.clone(),);
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
if let (&Either::One(_t),) = (&e.clone(),) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
while let (&Either::One(_t),) = (&e.clone(),) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
match (&e.clone(),) {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
(&Either::One(_t),)
|
2022-12-08 19:14:56 -06:00
|
|
|
//~^ HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
| (&Either::Two(_t),) => (),
|
|
|
|
}
|
|
|
|
fn f3((&X(_t),): (&X,)) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
|
|
|
|
let (&mut X(_t),) = (&mut xm.clone(),);
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
if let (&mut Either::One(_t),) = (&mut em.clone(),) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
while let (&mut Either::One(_t),) = (&mut em.clone(),) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
match (&mut em.clone(),) {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
(&mut Either::One(_t),) => (),
|
2022-12-08 19:14:56 -06:00
|
|
|
//~^ HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
(&mut Either::Two(_t),) => (),
|
2022-12-08 19:14:56 -06:00
|
|
|
//~^ HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
}
|
|
|
|
fn f4((&mut X(_t),): (&mut X,)) { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2018-08-13 17:52:23 -05:00
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// move from &Either/&X value
|
2018-08-07 03:02:39 -05:00
|
|
|
|
|
|
|
let &X(_t) = &x;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
if let &Either::One(_t) = &e { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
while let &Either::One(_t) = &e { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
match &e {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t)
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
| &Either::Two(_t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: would really like a suggestion here too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
match &e {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&Either::Two(ref _t) => (),
|
|
|
|
}
|
|
|
|
match &e {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
let &mut X(_t) = &mut xm;
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
if let &mut Either::One(_t) = &mut em { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
while let &mut Either::One(_t) = &mut em { }
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 11:02:54 -06:00
|
|
|
//~| HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
match &mut em {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t)
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
| &mut Either::Two(_t) => (),
|
2018-08-12 16:42:33 -05:00
|
|
|
// FIXME: would really like a suggestion here too
|
2018-08-07 03:02:39 -05:00
|
|
|
}
|
|
|
|
match &mut em {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&mut Either::Two(ref _t) => (),
|
|
|
|
}
|
|
|
|
match &mut em {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
&mut Either::Two(ref mut _t) => (),
|
|
|
|
}
|
|
|
|
match &mut em {
|
|
|
|
//~^ ERROR cannot move
|
|
|
|
&mut Either::One(_t) => (),
|
2022-12-08 11:02:54 -06:00
|
|
|
//~^ HELP consider removing
|
2018-08-07 03:02:39 -05:00
|
|
|
Either::Two(_t) => (),
|
|
|
|
}
|
|
|
|
}
|
2022-12-08 11:02:54 -06:00
|
|
|
|
|
|
|
struct Testing {
|
|
|
|
a: Option<String>
|
|
|
|
}
|
|
|
|
|
|
|
|
fn testing(a: &Testing) {
|
|
|
|
let Some(_s) = a.a else {
|
|
|
|
//~^ ERROR cannot move
|
2022-12-08 19:14:56 -06:00
|
|
|
//~| HELP consider borrowing the pattern binding
|
2022-12-08 11:02:54 -06:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
}
|