about summary refs log tree commit diff
path: root/tests/ui/use/use-after-move-implicity-coerced-object.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/use/use-after-move-implicity-coerced-object.rs')
-rw-r--r--tests/ui/use/use-after-move-implicity-coerced-object.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/use/use-after-move-implicity-coerced-object.rs b/tests/ui/use/use-after-move-implicity-coerced-object.rs
new file mode 100644
index 00000000000..47fbb5bf1c3
--- /dev/null
+++ b/tests/ui/use/use-after-move-implicity-coerced-object.rs
@@ -0,0 +1,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`
+}