2015-02-10 15:52:00 -06:00
|
|
|
#![feature(box_patterns)]
|
2021-08-24 19:39:40 -05:00
|
|
|
|
2015-01-07 15:35:56 -06:00
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::Add;
|
2014-05-05 20:56:44 -05:00
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Clone)]
|
2018-12-16 21:21:47 -06:00
|
|
|
struct Foo(Box<usize>);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2018-12-16 21:21:47 -06:00
|
|
|
impl Add for Foo {
|
|
|
|
type Output = Foo;
|
2014-12-31 14:45:13 -06:00
|
|
|
|
2018-12-16 21:21:47 -06:00
|
|
|
fn add(self, f: Foo) -> Foo {
|
|
|
|
let Foo(box i) = self;
|
|
|
|
let Foo(box j) = f;
|
2021-08-24 19:39:40 -05:00
|
|
|
Foo(Box::new(i + j))
|
2012-09-19 20:00:26 -05:00
|
|
|
}
|
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
|
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = Foo(Box::new(3));
|
2014-12-01 16:52:10 -06:00
|
|
|
let _y = {x} + x.clone(); // the `{x}` forces a move to occur
|
2019-04-22 02:40:08 -05:00
|
|
|
//~^ ERROR borrow of moved value: `x`
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|