rust/tests/ui/suggestions/dont-suggest-ref/move-into-closure.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.7 KiB
Rust
Raw Normal View History

2018-08-14 13:56:20 -05:00
#[derive(Clone)]
enum Either {
One(X),
Two(X),
}
#[derive(Clone)]
struct X(Y);
#[derive(Clone)]
struct Y;
fn consume_fn<F: Fn()>(_f: F) { }
fn consume_fnmut<F: FnMut()>(_f: F) { }
pub fn main() { }
fn move_into_fn() {
let e = Either::One(X(Y));
let mut em = Either::One(X(Y));
let x = X(Y);
// move into Fn
2018-08-14 13:56:20 -05:00
consume_fn(|| {
let X(_t) = x;
//~^ ERROR cannot move
//~| HELP consider borrowing here
if let Either::One(_t) = e { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
while let Either::One(_t) = e { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
match e {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(_t)
| Either::Two(_t) => (),
}
match e {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(_t) => (),
Either::Two(ref _t) => (),
// FIXME: should suggest removing `ref` too
}
let X(mut _t) = x;
//~^ ERROR cannot move
//~| HELP consider borrowing here
if let Either::One(mut _t) = em { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
while let Either::One(mut _t) = em { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
match em {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(mut _t)
| Either::Two(mut _t) => (),
}
match em {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(mut _t) => (),
Either::Two(ref _t) => (),
// FIXME: should suggest removing `ref` too
}
});
}
fn move_into_fnmut() {
let e = Either::One(X(Y));
let mut em = Either::One(X(Y));
let x = X(Y);
// move into FnMut
2018-08-14 13:56:20 -05:00
consume_fnmut(|| {
let X(_t) = x;
//~^ ERROR cannot move
//~| HELP consider borrowing here
if let Either::One(_t) = e { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
while let Either::One(_t) = e { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
match e {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(_t)
| Either::Two(_t) => (),
}
match e {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(_t) => (),
Either::Two(ref _t) => (),
// FIXME: should suggest removing `ref` too
}
let X(mut _t) = x;
//~^ ERROR cannot move
//~| HELP consider borrowing here
if let Either::One(mut _t) = em { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
while let Either::One(mut _t) = em { }
//~^ ERROR cannot move
//~| HELP consider borrowing here
match em {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(mut _t)
| Either::Two(mut _t) => (),
}
match em {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(mut _t) => (),
Either::Two(ref _t) => (),
// FIXME: should suggest removing `ref` too
}
match em {
//~^ ERROR cannot move
//~| HELP consider borrowing here
Either::One(mut _t) => (),
Either::Two(ref mut _t) => (),
// FIXME: should suggest removing `ref` too
}
});
}