rust/tests/ui/borrowck/borrowck-loan-in-overloaded-op.rs

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

24 lines
416 B
Rust
Raw Normal View History

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