rust/src/test/ui/borrowck/borrowck-loan-in-overloaded-op.rs

24 lines
426 B
Rust
Raw Normal View History

#![feature(box_patterns)]
#![feature(box_syntax)]
use std::ops::Add;
#[derive(Clone)]
struct Foo(Box<usize>);
impl Add for Foo {
type Output = Foo;
2014-12-31 14:45:13 -06:00
fn add(self, f: Foo) -> Foo {
let Foo(box i) = self;
let Foo(box j) = f;
Foo(box (i + j))
}
}
fn main() {
let x = Foo(box 3);
2014-12-01 16:52:10 -06:00
let _y = {x} + x.clone(); // the `{x}` forces a move to occur
//~^ ERROR use of moved value: `x`
}