summaryrefslogtreecommitdiffstats
path: root/tests/ui/use/use-after-move-implicity-coerced-object.rs
blob: 47fbb5bf1c362c4e453b0bf5bc7bbb8586c4ca8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 {
    list: Vec<Box<dyn ToString + 'static>> }

impl List {
    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`
}