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