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