2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-01-11 08:39:32 -06:00
|
|
|
// Assert that `mut self` on an immediate value doesn't
|
|
|
|
// allow mutating the original - issue #10615.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-01-11 08:39:32 -06:00
|
|
|
struct Value {
|
2015-03-25 19:06:52 -05:00
|
|
|
n: isize
|
2014-01-11 08:39:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
fn squared(mut self) -> Value {
|
|
|
|
self.n *= self.n;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let x = Value { n: 3 };
|
|
|
|
let y = x.squared();
|
|
|
|
assert_eq!(x.n, 3);
|
|
|
|
assert_eq!(y.n, 9);
|
|
|
|
}
|