Skip to content

Commit 30a060c

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163448 b: refs/heads/snap-stage3 c: dff2b39 h: refs/heads/master v: v3
1 parent 9ccfabe commit 30a060c

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 949b55e58e8a26e5c05cc5350dee8017e7653ad5
4+
refs/heads/snap-stage3: dff2b395d21e8e6f322a3de2e68d20451afc08f3
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that move restrictions are enforced on overloaded binary operations
12+
13+
fn double_move<T: Add<T, ()>>(x: T) {
14+
x
15+
+
16+
x; //~ ERROR: use of moved value
17+
}
18+
19+
fn move_then_borrow<T: Add<T, ()> + Clone>(x: T) {
20+
x
21+
+
22+
x.clone(); //~ ERROR: use of moved value
23+
}
24+
25+
fn move_borrowed<T: Add<T, ()>>(x: T, mut y: T) {
26+
let m = &x;
27+
let n = &mut y;
28+
29+
x //~ ERROR: cannot move out of `x` because it is borrowed
30+
+
31+
y; //~ ERROR: cannot move out of `y` because it is borrowed
32+
}
33+
34+
fn illegal_dereference<T: Add<T, ()>>(mut x: T, y: T) {
35+
let m = &mut x;
36+
let n = &y;
37+
38+
*m //~ ERROR: cannot move out of dereference of `&mut`-pointer
39+
+
40+
*n; //~ ERROR: cannot move out of dereference of `&`-pointer
41+
}
42+
43+
struct Foo;
44+
45+
impl<'a, 'b> Add<&'b Foo, ()> for &'a mut Foo {
46+
fn add(self, _: &Foo) {}
47+
}
48+
49+
impl<'a, 'b> Add<&'b mut Foo, ()> for &'a Foo {
50+
fn add(self, _: &mut Foo) {}
51+
}
52+
53+
fn mut_plus_immut() {
54+
let mut f = Foo;
55+
56+
&mut f
57+
+
58+
&f; //~ ERROR: cannot borrow `f` as immutable because it is also borrowed as mutable
59+
}
60+
61+
fn immut_plus_mut() {
62+
let mut f = Foo;
63+
64+
&f
65+
+
66+
&mut f; //~ ERROR: cannot borrow `f` as mutable because it is also borrowed as immutable
67+
}
68+
69+
fn main() {}

0 commit comments

Comments
 (0)