mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
24 lines
416 B
Rust
24 lines
416 B
Rust
#![feature(box_patterns)]
|
|
|
|
|
|
use std::ops::Add;
|
|
|
|
#[derive(Clone)]
|
|
struct Foo(Box<usize>);
|
|
|
|
impl Add for Foo {
|
|
type Output = Foo;
|
|
|
|
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));
|
|
let _y = {x} + x.clone(); // the `{x}` forces a move to occur
|
|
//~^ ERROR borrow of moved value: `x`
|
|
}
|