Update tests wrt. bind_by_by_move_pattern_guards stabilization.

This commit is contained in:
Mazdak Farrokhzad 2019-07-30 01:25:30 +02:00
parent 0356813b27
commit 642993e6dc
33 changed files with 35 additions and 218 deletions

View file

@ -1989,7 +1989,6 @@ When matching on a variable it cannot be mutated in the match guards, as this
could cause the match to be non-exhaustive:
```compile_fail,E0510
#![feature(bind_by_move_pattern_guards)]
let mut x = Some(0);
match x {
None => (),

View file

@ -8,8 +8,6 @@
// all of the bindings for that scope.
// * No drop flags are used.
#![feature(nll, bind_by_move_pattern_guards)]
fn complicated_match(cond: bool, items: (bool, bool, String)) -> i32 {
match items {
(false, a, s) | (a, false, s) if if cond { return 3 } else { a } => 1,

View file

@ -1,13 +0,0 @@
use std::sync::mpsc::channel;
fn main() {
let (tx, rx) = channel();
let x = Some(rx);
tx.send(false);
match x {
Some(z) if z.recv().unwrap() => { panic!() },
//~^ ERROR cannot bind by-move into a pattern guard
Some(z) => { assert!(!z.recv().unwrap()); },
None => panic!()
}
}

View file

@ -1,11 +0,0 @@
error[E0008]: cannot bind by-move into a pattern guard
--> $DIR/bind-by-move-no-guards.rs:8:14
|
LL | Some(z) if z.recv().unwrap() => { panic!() },
| ^ moves value into pattern guard
|
= help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0008`.

View file

@ -8,12 +8,9 @@ fn foo() -> isize {
let mut x = Enum::A(&mut n);
match x {
Enum::A(_) if { x = Enum::B(false); false } => 1,
//~^ ERROR cannot assign in a pattern guard
//~| ERROR cannot assign `x` in match guard
//~^ ERROR cannot assign `x` in match guard
Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
//~^ ERROR cannot mutably borrow in a pattern guard
//~| ERROR cannot assign in a pattern guard
//~| ERROR cannot mutably borrow `x` in match guard
//~^ ERROR cannot mutably borrow `x` in match guard
Enum::A(p) => *p,
Enum::B(_) => 2,
}

View file

@ -1,23 +1,3 @@
error[E0302]: cannot assign in a pattern guard
--> $DIR/borrowck-mutate-in-guard.rs:10:25
|
LL | Enum::A(_) if { x = Enum::B(false); false } => 1,
| ^^^^^^^^^^^^^^^^^^ assignment in pattern guard
error[E0301]: cannot mutably borrow in a pattern guard
--> $DIR/borrowck-mutate-in-guard.rs:13:38
|
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
| ^ borrowed mutably in pattern guard
|
= help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable
error[E0302]: cannot assign in a pattern guard
--> $DIR/borrowck-mutate-in-guard.rs:13:41
|
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
| ^^^^^^^^^^^^^^^^^^^ assignment in pattern guard
error[E0510]: cannot assign `x` in match guard
--> $DIR/borrowck-mutate-in-guard.rs:10:25
|
@ -27,7 +7,7 @@ LL | Enum::A(_) if { x = Enum::B(false); false } => 1,
| ^^^^^^^^^^^^^^^^^^ cannot assign
error[E0510]: cannot mutably borrow `x` in match guard
--> $DIR/borrowck-mutate-in-guard.rs:13:33
--> $DIR/borrowck-mutate-in-guard.rs:12:33
|
LL | match x {
| - value is immutable in match guard
@ -35,7 +15,6 @@ LL | match x {
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1,
| ^^^^^^ cannot mutably borrow
error: aborting due to 5 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0301, E0302, E0510.
For more information about an error, try `rustc --explain E0301`.
For more information about this error, try `rustc --explain E0510`.

View file

@ -1,7 +0,0 @@
fn main() {
match Some("hi".to_string()) {
Some(s) if s.len() == 0 => {},
//~^ ERROR E0008
_ => {},
}
}

View file

@ -1,11 +0,0 @@
error[E0008]: cannot bind by-move into a pattern guard
--> $DIR/E0008.rs:3:14
|
LL | Some(s) if s.len() == 0 => {},
| ^ moves value into pattern guard
|
= help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0008`.

View file

@ -1,7 +1,7 @@
fn main() {
match Some(()) {
None => { },
option if option.take().is_none() => {}, //~ ERROR E0301
option if option.take().is_none() => {},
Some(_) => { } //~^ ERROR E0596
}
}

View file

@ -1,11 +1,3 @@
error[E0301]: cannot mutably borrow in a pattern guard
--> $DIR/E0301.rs:4:19
|
LL | option if option.take().is_none() => {},
| ^^^^^^ borrowed mutably in pattern guard
|
= help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable
error[E0596]: cannot borrow `option` as mutable, as it is immutable for the pattern guard
--> $DIR/E0301.rs:4:19
|
@ -14,7 +6,6 @@ LL | option if option.take().is_none() => {},
|
= note: variables bound in patterns are immutable until the end of the pattern guard
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors have detailed explanations: E0301, E0596.
For more information about an error, try `rustc --explain E0301`.
For more information about this error, try `rustc --explain E0596`.

View file

@ -1,7 +1,7 @@
fn main() {
match Some(()) {
None => { },
option if { option = None; false } => { }, //~ ERROR E0302
option if { option = None; false } => { },
//~^ ERROR cannot assign to `option`, as it is immutable for the pattern guard
Some(_) => { }
}

View file

@ -1,9 +1,3 @@
error[E0302]: cannot assign in a pattern guard
--> $DIR/E0302.rs:4:21
|
LL | option if { option = None; false } => { },
| ^^^^^^^^^^^^^ assignment in pattern guard
error[E0594]: cannot assign to `option`, as it is immutable for the pattern guard
--> $DIR/E0302.rs:4:21
|
@ -12,6 +6,5 @@ LL | option if { option = None; false } => { },
|
= note: variables bound in patterns are immutable until the end of the pattern guard
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0302`.

View file

@ -5,8 +5,6 @@
// See further discussion on rust-lang/rust#24535,
// rust-lang/rfcs#1006, and rust-lang/rfcs#107
#![feature(bind_by_move_pattern_guards)]
fn main() {
rust_issue_24535();
rfcs_issue_1006_1();

View file

@ -5,8 +5,6 @@
// reject it. But I want to make sure that we continue to reject it
// (under NLL) even when that conservaive check goes away.
#![feature(bind_by_move_pattern_guards)]
fn main() {
let mut b = &mut true;
match b {

View file

@ -1,5 +1,5 @@
error[E0596]: cannot borrow `r` as mutable, as it is immutable for the pattern guard
--> $DIR/issue-27282-reborrow-ref-mut-in-guard.rs:14:25
--> $DIR/issue-27282-reborrow-ref-mut-in-guard.rs:12:25
|
LL | ref mut r if { (|| { let bar = &mut *r; **bar = false; })();
| ^^ - mutable borrow occurs due to use of `r` in closure

View file

@ -3,8 +3,6 @@
// run-pass
#![feature(bind_by_move_pattern_guards)]
// Test that z always point to the same temporary.
fn referent_stability() {
let p;

View file

@ -1,8 +1,6 @@
// Test that we have enough false edges to avoid exposing the exact matching
// algorithm in borrow checking.
#![feature(bind_by_move_pattern_guards)]
fn guard_always_precedes_arm(y: i32) {
let mut x;
// x should always be initialized, as the only way to reach the arm is

View file

@ -1,11 +1,11 @@
error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/match-cfg-fake-edges.rs:23:13
--> $DIR/match-cfg-fake-edges.rs:21:13
|
LL | x;
| ^ use of possibly-uninitialized `x`
error[E0382]: use of moved value: `x`
--> $DIR/match-cfg-fake-edges.rs:37:13
--> $DIR/match-cfg-fake-edges.rs:35:13
|
LL | let x = String::new();
| - move occurs because `x` has type `std::string::String`, which does not implement the `Copy` trait

View file

@ -5,8 +5,6 @@
// Test that we don't allow mutating the value being matched on in a way that
// changes which patterns it matches, until we have chosen an arm.
#![feature(bind_by_move_pattern_guards)]
fn ok_mutation_in_guard(mut q: i32) {
match q {
// OK, mutation doesn't change which patterns g matches

View file

@ -1,5 +1,5 @@
error[E0510]: cannot assign `q` in match guard
--> $DIR/match-guards-partially-borrow.rs:57:13
--> $DIR/match-guards-partially-borrow.rs:55:13
|
LL | match q {
| - value is immutable in match guard
@ -8,7 +8,7 @@ LL | q = true;
| ^^^^^^^^ cannot assign
error[E0510]: cannot assign `r` in match guard
--> $DIR/match-guards-partially-borrow.rs:69:13
--> $DIR/match-guards-partially-borrow.rs:67:13
|
LL | match r {
| - value is immutable in match guard
@ -17,7 +17,7 @@ LL | r = true;
| ^^^^^^^^ cannot assign
error[E0510]: cannot assign `t` in match guard
--> $DIR/match-guards-partially-borrow.rs:93:13
--> $DIR/match-guards-partially-borrow.rs:91:13
|
LL | match t {
| - value is immutable in match guard
@ -26,7 +26,7 @@ LL | t = true;
| ^^^^^^^^ cannot assign
error[E0510]: cannot mutably borrow `x.0` in match guard
--> $DIR/match-guards-partially-borrow.rs:107:22
--> $DIR/match-guards-partially-borrow.rs:105:22
|
LL | match x {
| - value is immutable in match guard
@ -35,7 +35,7 @@ LL | Some(ref mut r) => *r = None,
| ^^^^^^^^^ cannot mutably borrow
error[E0506]: cannot assign to `t` because it is borrowed
--> $DIR/match-guards-partially-borrow.rs:119:13
--> $DIR/match-guards-partially-borrow.rs:117:13
|
LL | s if {
| - borrow of `t` occurs here
@ -46,7 +46,7 @@ LL | } => (), // What value should `s` have in the arm?
| - borrow later used here
error[E0510]: cannot assign `y` in match guard
--> $DIR/match-guards-partially-borrow.rs:130:13
--> $DIR/match-guards-partially-borrow.rs:128:13
|
LL | match *y {
| -- value is immutable in match guard
@ -55,7 +55,7 @@ LL | y = &true;
| ^^^^^^^^^ cannot assign
error[E0510]: cannot assign `z` in match guard
--> $DIR/match-guards-partially-borrow.rs:141:13
--> $DIR/match-guards-partially-borrow.rs:139:13
|
LL | match z {
| - value is immutable in match guard
@ -64,7 +64,7 @@ LL | z = &true;
| ^^^^^^^^^ cannot assign
error[E0510]: cannot assign `a` in match guard
--> $DIR/match-guards-partially-borrow.rs:153:13
--> $DIR/match-guards-partially-borrow.rs:151:13
|
LL | match a {
| - value is immutable in match guard
@ -73,7 +73,7 @@ LL | a = &true;
| ^^^^^^^^^ cannot assign
error[E0510]: cannot assign `b` in match guard
--> $DIR/match-guards-partially-borrow.rs:164:13
--> $DIR/match-guards-partially-borrow.rs:162:13
|
LL | match b {
| - value is immutable in match guard

View file

@ -4,8 +4,6 @@
// run-pass
#![feature(bind_by_move_pattern_guards)]
use std::sync::mpsc::channel;
fn main() {

View file

@ -1,10 +0,0 @@
error: compilation successful
--> $DIR/feature-gate.rs:36:1
|
LL | / fn main() {
LL | | foo(107)
LL | | }
| |_^
error: aborting due to previous error

View file

@ -1,10 +0,0 @@
error: compilation successful
--> $DIR/feature-gate.rs:36:1
|
LL | / fn main() {
LL | | foo(107)
LL | | }
| |_^
error: aborting due to previous error

View file

@ -1,10 +0,0 @@
error: compilation successful
--> $DIR/feature-gate.rs:41:1
|
LL | / fn main() {
LL | | foo(107)
LL | | }
| |_^
error: aborting due to previous error

View file

@ -1,10 +0,0 @@
error: compilation successful
--> $DIR/feature-gate.rs:41:1
|
LL | / fn main() {
LL | | foo(107)
LL | | }
| |_^
error: aborting due to previous error

View file

@ -1,11 +0,0 @@
error[E0008]: cannot bind by-move into a pattern guard
--> $DIR/feature-gate.rs:28:16
|
LL | A { a: v } if *v == 42 => v,
| ^ moves value into pattern guard
|
= help: add `#![feature(bind_by_move_pattern_guards)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0008`.

View file

@ -1,40 +0,0 @@
// Check that pattern-guards with move-bound variables is only allowed
// with the appropriate set of feature gates. (Note that we require
// the code to opt into MIR-borrowck in *some* way before the feature
// will work; we use the revision system here to enumerate a number of
// ways that opt-in could occur.)
// gate-test-bind_by_move_pattern_guards
// revisions: no_gate gate_and_2015 gate_and_2018
// (We're already testing NLL behavior quite explicitly, no need for compare-mode=nll.)
// ignore-compare-mode-nll
#![feature(rustc_attrs)]
#![cfg_attr(gate_and_2015, feature(bind_by_move_pattern_guards))]
#![cfg_attr(gate_and_2018, feature(bind_by_move_pattern_guards))]
//[gate_and_2015] edition:2015
//[gate_and_2018] edition:2018
struct A { a: Box<i32> }
fn foo(n: i32) {
let x = A { a: Box::new(n) };
let _y = match x {
A { a: v } if *v == 42 => v,
//[no_gate]~^ ERROR cannot bind by-move into a pattern guard
_ => Box::new(0)
};
}
#[rustc_error]
fn main() {
foo(107)
}
//[gate_and_2015]~^^^ ERROR compilation successful
//[gate_and_2018]~^^^^ ERROR compilation successful

View file

@ -0,0 +1,11 @@
// This test used to emit E0008 but now passed since `bind_by_move_pattern_guards`
// have been stabilized.
// check-pass
fn main() {
match Some("hi".to_string()) {
Some(s) if s.len() == 0 => {},
_ => {},
}
}

View file

@ -1,5 +1,3 @@
#![feature(bind_by_move_pattern_guards)]
// run-pass
struct A { a: Box<i32> }

View file

@ -1,5 +1,3 @@
#![feature(bind_by_move_pattern_guards)]
enum VecWrapper { A(Vec<i32>) }
fn foo(x: VecWrapper) -> usize {

View file

@ -1,5 +1,5 @@
error[E0507]: cannot move out of `v` in pattern guard
--> $DIR/rfc-reject-double-move-across-arms.rs:7:36
--> $DIR/rfc-reject-double-move-across-arms.rs:5:36
|
LL | VecWrapper::A(v) if { drop(v); false } => 1,
| ^ move occurs because `v` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait

View file

@ -1,5 +1,3 @@
#![feature(bind_by_move_pattern_guards)]
struct A { a: Box<i32> }
fn foo(n: i32) {

View file

@ -1,5 +1,5 @@
error[E0507]: cannot move out of `v` in pattern guard
--> $DIR/rfc-reject-double-move-in-first-arm.rs:8:30
--> $DIR/rfc-reject-double-move-in-first-arm.rs:6:30
|
LL | A { a: v } if { drop(v); true } => v,
| ^ move occurs because `v` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait