Skip to content

Commit 2a61ba8

Browse files
Add test const-cannot-move-shared-ref.rs
1 parent 59cbdee commit 2a61ba8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Checks whether borrow checking visits constants correctly
2+
3+
struct NonCopy(u8);
4+
5+
const C: () = {
6+
let &moved = &NonCopy(0);
7+
//~^ ERROR cannot move out of a shared reference
8+
};
9+
10+
fn main() { }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0507]: cannot move out of a shared reference
2+
--> $DIR/const-cannot-move-shared-ref.rs:6:18
3+
|
4+
LL | let &moved = &NonCopy(0);
5+
| ----- ^^^^^^^^^^^
6+
| |
7+
| data moved here because `moved` has type `NonCopy`, which does not implement the `Copy` trait
8+
|
9+
help: consider removing the borrow
10+
|
11+
LL - let &moved = &NonCopy(0);
12+
LL + let moved = &NonCopy(0);
13+
|
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)