Skip to content

Commit e9a7eb4

Browse files
Add test borrow-check.rs
1 parent 7332e03 commit e9a7eb4

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check whether the borrow checker runs in guard patterns
2+
3+
#![feature(guard_patterns)]
4+
5+
struct NonCopy(u8);
6+
7+
pub fn probe(
8+
(_ if const {
9+
let x = NonCopy(0);
10+
let y = x;
11+
let z = x;
12+
//~^ ERROR use of moved value: `x` [E0382]
13+
true
14+
}): u8,
15+
) {}
16+
17+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0382]: use of moved value: `x`
2+
--> $DIR/borrow-check.rs:11:13
3+
|
4+
LL | let x = NonCopy(0);
5+
| - move occurs because `x` has type `NonCopy`, which does not implement the `Copy` trait
6+
LL | let y = x;
7+
| - value moved here
8+
LL | let z = x;
9+
| ^ value used here after move
10+
|
11+
note: if `NonCopy` implemented `Clone`, you could clone the value
12+
--> $DIR/borrow-check.rs:5:1
13+
|
14+
LL | struct NonCopy(u8);
15+
| ^^^^^^^^^^^^^^ consider implementing `Clone` for this type
16+
...
17+
LL | let y = x;
18+
| - you could clone this value
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)