diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-09-07 17:52:49 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-09-17 13:46:50 +0200 |
| commit | c50884c6157645d22d8fb1ee1beb2c1552d570c7 (patch) | |
| tree | 2543826b998ef8efa49247c50562517b565821d7 | |
| parent | 7d844e871c2b6d3c86adff53792fc36fdd338eb2 (diff) | |
| download | rust-c50884c6157645d22d8fb1ee1beb2c1552d570c7.tar.gz rust-c50884c6157645d22d8fb1ee1beb2c1552d570c7.zip | |
Tests for `feature(bind_by_move_pattern_guards)`.
Apparently copyright notices are no longer necessary apparently. (See #43498 and #53654.)
14 files changed, 208 insertions, 11 deletions
diff --git a/src/test/ui/bind-by-move/bind-by-move-no-guards.rs b/src/test/ui/bind-by-move/bind-by-move-no-guards.rs index bb6060f2543..bc9b3a8de4e 100644 --- a/src/test/ui/bind-by-move/bind-by-move-no-guards.rs +++ b/src/test/ui/bind-by-move/bind-by-move-no-guards.rs @@ -1,13 +1,3 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - use std::sync::mpsc::channel; fn main() { diff --git a/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr b/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr index ed516cd559e..2af2b0d660e 100644 --- a/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr +++ b/src/test/ui/bind-by-move/bind-by-move-no-guards.stderr @@ -1,5 +1,5 @@ error[E0008]: cannot bind by-move into a pattern guard - --> $DIR/bind-by-move-no-guards.rs:18:14 + --> $DIR/bind-by-move-no-guards.rs:8:14 | LL | Some(z) if z.recv().unwrap() => { panic!() }, | ^ moves value into pattern guard diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/bind-by-move-no-guards.rs b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/bind-by-move-no-guards.rs new file mode 100644 index 00000000000..2f3c094ff39 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/bind-by-move-no-guards.rs @@ -0,0 +1,21 @@ +// Adaptation of existing ui test (from way back in +// rust-lang/rust#2329), that starts passing with this feature in +// place. + +// compile-pass + +#![feature(nll)] +#![feature(bind_by_move_pattern_guards)] + +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!() }, + Some(z) => { assert!(!z.recv().unwrap()); }, + None => panic!() + } +} diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2015.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2015.stderr new file mode 100644 index 00000000000..4c17ce23b37 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2015.stderr @@ -0,0 +1,9 @@ +error[E0008]: cannot bind by-move into a pattern guard + --> $DIR/feature-gate.rs:33:16 + | +LL | A { a: v } if *v == 42 => v, + | ^ moves value into pattern guard + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0008`. diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2018.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2018.stderr new file mode 100644 index 00000000000..4bde9b0c8d9 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_2018.stderr @@ -0,0 +1,10 @@ +error: compilation successful + --> $DIR/feature-gate.rs:42:1 + | +LL | / fn main() { +LL | | foo(107) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_feature_nll.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_feature_nll.stderr new file mode 100644 index 00000000000..4bde9b0c8d9 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_feature_nll.stderr @@ -0,0 +1,10 @@ +error: compilation successful + --> $DIR/feature-gate.rs:42:1 + | +LL | / fn main() { +LL | | foo(107) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_znll.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_znll.stderr new file mode 100644 index 00000000000..4bde9b0c8d9 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.gate_and_znll.stderr @@ -0,0 +1,10 @@ +error: compilation successful + --> $DIR/feature-gate.rs:42:1 + | +LL | / fn main() { +LL | | foo(107) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr new file mode 100644 index 00000000000..4c17ce23b37 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.no_gate.stderr @@ -0,0 +1,9 @@ +error[E0008]: cannot bind by-move into a pattern guard + --> $DIR/feature-gate.rs:33:16 + | +LL | A { a: v } if *v == 42 => v, + | ^ moves value into pattern guard + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0008`. diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.rs b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.rs new file mode 100644 index 00000000000..f6df4d07baa --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.rs @@ -0,0 +1,47 @@ +// 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 gate_and_znll gate_and_feature_nll + +// (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))] +#![cfg_attr(gate_and_znll, feature(bind_by_move_pattern_guards))] +#![cfg_attr(gate_and_feature_nll, feature(bind_by_move_pattern_guards))] + +#![cfg_attr(gate_and_feature_nll, feature(nll))] + +//[gate_and_2015] edition:2015 +//[gate_and_2018] edition:2018 +//[gate_and_znll] compile-flags: -Z borrowck=mir + +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 + //[gate_and_2015]~^^ ERROR cannot bind by-move into a pattern guard + + _ => Box::new(0) + }; +} + +#[rustc_error] +fn main() { + foo(107) +} +//[gate_and_2018]~^^^ ERROR compilation successful +//[gate_and_znll]~^^^^ ERROR compilation successful +//[gate_and_feature_nll]~^^^^^ ERROR compilation successful diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-basic-examples.rs b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-basic-examples.rs new file mode 100644 index 00000000000..9a9d11ce1b1 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-basic-examples.rs @@ -0,0 +1,40 @@ +#![feature(nll)] +#![feature(bind_by_move_pattern_guards)] + +// compile-pass + +struct A { a: Box<i32> } + +impl A { + fn get(&self) -> i32 { *self.a } +} + +fn foo(n: i32) { + let x = A { a: Box::new(n) }; + let y = match x { + A { a: v } if *v == 42 => v, + _ => Box::new(0), + }; +} + +fn bar(n: i32) { + let x = A { a: Box::new(n) }; + let y = match x { + A { a: v } if x.get() == 42 => v, + _ => Box::new(0), + }; +} + +fn baz(n: i32) { + let x = A { a: Box::new(n) }; + let y = match x { + A { a: v } if *v.clone() == 42 => v, + _ => Box::new(0), + }; +} + +fn main() { + foo(107); + bar(107); + baz(107); +} diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.rs b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.rs new file mode 100644 index 00000000000..0fec6b273d3 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.rs @@ -0,0 +1,16 @@ +#![feature(nll)] +#![feature(bind_by_move_pattern_guards)] + +enum VecWrapper { A(Vec<i32>) } + +fn foo(x: VecWrapper) -> usize { + match x { + VecWrapper::A(v) if { drop(v); false } => 1, + //~^ ERROR cannot move out of borrowed content + VecWrapper::A(v) => v.len() + } +} + +fn main() { + foo(VecWrapper::A(vec![107])); +} diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.stderr new file mode 100644 index 00000000000..502006e1b3f --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-across-arms.stderr @@ -0,0 +1,9 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/rfc-reject-double-move-across-arms.rs:8:36 + | +LL | VecWrapper::A(v) if { drop(v); false } => 1, + | ^ cannot move out of borrowed content + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.rs b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.rs new file mode 100644 index 00000000000..396bfc1c931 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.rs @@ -0,0 +1,17 @@ +#![feature(nll)] +#![feature(bind_by_move_pattern_guards)] + +struct A { a: Box<i32> } + +fn foo(n: i32) { + let x = A { a: Box::new(n) }; + let _y = match x { + A { a: v } if { drop(v); true } => v, + //~^ ERROR cannot move out of borrowed content + _ => Box::new(0), + }; +} + +fn main() { + foo(107); +} diff --git a/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.stderr b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.stderr new file mode 100644 index 00000000000..dd8f42f7497 --- /dev/null +++ b/src/test/ui/rfc-0107-bind-by-move-pattern-guards/rfc-reject-double-move-in-first-arm.stderr @@ -0,0 +1,9 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/rfc-reject-double-move-in-first-arm.rs:9:30 + | +LL | A { a: v } if { drop(v); true } => v, + | ^ cannot move out of borrowed content + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`. |
