rust/tests/ui/use/use-after-move-implicity-coerced-object.rs

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

31 lines
545 B
Rust
Raw Normal View History

use std::fmt;
struct Number {
n: i64
}
impl fmt::Display for Number {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.n)
}
}
struct List {
2019-05-28 18:46:13 +00:00
list: Vec<Box<dyn ToString + 'static>> }
impl List {
2019-05-28 18:46:13 +00:00
fn push(&mut self, n: Box<dyn ToString + 'static>) {
self.list.push(n);
}
}
fn main() {
let n: Box<_> = Number { n: 42 }.into();
let mut l: Box<_> = List { list: Vec::new() }.into();
l.push(n);
let x = n.to_string();
//~^ ERROR: borrow of moved value: `n`
}