Skip to content

Commit

Permalink
move_ref_patterns: introduce tests
Browse files Browse the repository at this point in the history
bindings_after_at: harden tests
  • Loading branch information
Centril committed Feb 2, 2020
1 parent 7af9ff3 commit d984f12
Show file tree
Hide file tree
Showing 50 changed files with 1,919 additions and 541 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions src/test/ui/drop/dynamic-drop-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// edition:2018
// ignore-wasm32-bare compiled with panic=abort by default

#![feature(move_ref_pattern)]

#![allow(unused)]

use std::{
Expand Down Expand Up @@ -227,6 +229,12 @@ async fn subslice_pattern_reassign(a: Rc<Allocator>) {
a.alloc().await;
}

async fn move_ref_pattern(a: Rc<Allocator>) {
let mut tup = (a.alloc().await, a.alloc().await, a.alloc().await, a.alloc().await);
let (ref _a, ref mut _b, _c, mut _d) = tup;
a.alloc().await;
}

fn run_test<F, G>(cx: &mut Context<'_>, ref f: F)
where
F: Fn(Rc<Allocator>) -> G,
Expand Down Expand Up @@ -322,4 +330,6 @@ fn main() {
run_test(context, |a| subslice_pattern_from_end_with_drop(a, false, true));
run_test(context, |a| subslice_pattern_from_end_with_drop(a, false, false));
run_test(context, |a| subslice_pattern_reassign(a));

run_test(context, |a| move_ref_pattern(a));
}
8 changes: 8 additions & 0 deletions src/test/ui/drop/dynamic-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ignore-wasm32-bare compiled with panic=abort by default

#![feature(generators, generator_trait, untagged_unions)]
#![feature(move_ref_pattern)]

#![allow(unused_assignments)]
#![allow(unused_variables)]
Expand Down Expand Up @@ -290,6 +291,11 @@ fn subslice_mixed_min_lengths(a: &Allocator, c: i32) {
}
}

fn move_ref_pattern(a: &Allocator) {
let mut tup = (a.alloc(), a.alloc(), a.alloc(), a.alloc());
let (ref _a, ref mut _b, _c, mut _d) = tup;
}

fn panic_after_return(a: &Allocator) -> Ptr<'_> {
// Panic in the drop of `p` or `q` can leak
let exceptions = vec![8, 9];
Expand Down Expand Up @@ -453,6 +459,8 @@ fn main() {
run_test(|a| subslice_mixed_min_lengths(a, 6));
run_test(|a| subslice_mixed_min_lengths(a, 7));

run_test(|a| move_ref_pattern(a));

run_test(|a| {
panic_after_return(a);
});
Expand Down
9 changes: 0 additions & 9 deletions src/test/ui/error-codes/E0009.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/error-codes/E0009.stderr

This file was deleted.

20 changes: 0 additions & 20 deletions src/test/ui/issues/issue-53840.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/ui/moves/move-out-of-slice-2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(slice_patterns, unsized_locals)]
#![feature(unsized_locals)]

struct A;
#[derive(Clone, Copy)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@
// where one side is by-ref and the other is by-move.

#![feature(bindings_after_at)]
#![feature(move_ref_pattern)]

struct X { x: () }
struct X {
x: (),
}

fn main() {
let x = Some(X { x: () });
match x {
Some(ref _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
None => panic!()
Some(ref _y @ _z) => {} //~ ERROR cannot move out of `_y` because it is borrowed
None => panic!(),
}

let x = Some(X { x: () });
match x {
Some(_z @ ref _y) => { }, //~ ERROR cannot bind by-move with sub-bindings
Some(_z @ ref _y) => {}
//~^ ERROR borrow of moved value
None => panic!()
//~| ERROR borrow of moved value
None => panic!(),
}

let mut x = Some(X { x: () });
match x {
Some(ref mut _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
None => panic!()
Some(ref mut _y @ _z) => {} //~ ERROR cannot move out of `_y` because it is borrowed
None => panic!(),
}

let mut x = Some(X { x: () });
match x {
Some(_z @ ref mut _y) => { }, //~ ERROR cannot bind by-move with sub-bindings
Some(_z @ ref mut _y) => {}
//~^ ERROR borrow of moved value
None => panic!()
//~| ERROR borrow of moved value
None => panic!(),
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
error[E0009]: cannot bind by-move and by-ref in the same pattern
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:12:23
error: cannot move out of `_y` because it is borrowed
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:15:14
|
LL | Some(ref _y @ _z) => { },
| ---------^^
LL | Some(ref _y @ _z) => {}
| ------^^^--
| | |
| | by-move pattern here
| by-ref pattern here
| | move out of `_y` occurs here
| borrow of `_y` occurs here

error[E0007]: cannot bind by-move with sub-bindings
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:18:14
error: borrow of moved value: `_z`
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:21:14
|
LL | Some(_z @ ref _y) => { },
| ^^^^^^^^^^^ binds an already bound by-move value by moving it
LL | Some(_z @ ref _y) => {}
| --^^^------
| | |
| | value borrowed here after move
| value moved here
| move occurs because `_z` has type `X` which does implement the `Copy` trait

error[E0009]: cannot bind by-move and by-ref in the same pattern
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:25:27
error: cannot move out of `_y` because it is borrowed
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:29:14
|
LL | Some(ref mut _y @ _z) => { },
| -------------^^
LL | Some(ref mut _y @ _z) => {}
| ----------^^^--
| | |
| | by-move pattern here
| by-ref pattern here
| | move out of `_y` occurs here
| borrow of `_y` occurs here

error[E0007]: cannot bind by-move with sub-bindings
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:31:14
error: borrow of moved value: `_z`
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:14
|
LL | Some(_z @ ref mut _y) => { },
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
LL | Some(_z @ ref mut _y) => {}
| --^^^----------
| | |
| | value borrowed here after move
| value moved here
| move occurs because `_z` has type `X` which does implement the `Copy` trait

error[E0382]: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:18:19
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:21:19
|
LL | Some(_z @ ref _y) => { },
LL | Some(_z @ ref _y) => {}
| -----^^^^^^
| | |
| | value borrowed here after move
Expand All @@ -40,9 +48,9 @@ LL | Some(_z @ ref _y) => { },
= note: move occurs because value has type `X`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:31:19
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:19
|
LL | Some(_z @ ref mut _y) => { },
LL | Some(_z @ ref mut _y) => {}
| -----^^^^^^^^^^
| | |
| | value borrowed here after move
Expand All @@ -52,5 +60,4 @@ LL | Some(_z @ ref mut _y) => { },

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0007, E0009, E0382.
For more information about an error, try `rustc --explain E0007`.
For more information about this error, try `rustc --explain E0382`.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// See issue #12534.

#![feature(bindings_after_at)]
#![feature(move_ref_pattern)]

fn main() {}

struct A(Box<u8>);

fn f(a @ A(u): A) -> Box<u8> {
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
//~^ ERROR use of moved value
drop(a);
u
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
error[E0007]: cannot bind by-move with sub-bindings
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:9:6
|
LL | fn f(a @ A(u): A) -> Box<u8> {
| ^^^^^^^^ binds an already bound by-move value by moving it

error[E0382]: use of moved value
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:9:12
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:10:12
|
LL | fn f(a @ A(u): A) -> Box<u8> {
| ------^-
Expand All @@ -14,7 +8,6 @@ LL | fn f(a @ A(u): A) -> Box<u8> {
| value moved here
| move occurs because value has type `A`, which does not implement the `Copy` trait

error: aborting due to 2 previous errors
error: aborting due to previous error

Some errors have detailed explanations: E0007, E0382.
For more information about an error, try `rustc --explain E0007`.
For more information about this error, try `rustc --explain E0382`.
Loading

0 comments on commit d984f12

Please sign in to comment.