]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-0107-bind-by-move-pattern-guards/feature-gate.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / rfc-0107-bind-by-move-pattern-guards / feature-gate.rs
1 // Check that pattern-guards with move-bound variables is only allowed
2 // with the appropriate set of feature gates. (Note that we require
3 // the code to opt into MIR-borrowck in *some* way before the feature
4 // will work; we use the revision system here to enumerate a number of
5 // ways that opt-in could occur.)
6
7 // gate-test-bind_by_move_pattern_guards
8
9 // revisions: no_gate gate_and_2015 gate_and_2018 gate_and_znll gate_and_feature_nll
10
11 // (We're already testing NLL behavior quite explicitly, no need for compare-mode=nll.)
12 // ignore-compare-mode-nll
13
14 #![feature(rustc_attrs)]
15
16 #![cfg_attr(gate_and_2015, feature(bind_by_move_pattern_guards))]
17 #![cfg_attr(gate_and_2018, feature(bind_by_move_pattern_guards))]
18 #![cfg_attr(gate_and_znll, feature(bind_by_move_pattern_guards))]
19 #![cfg_attr(gate_and_feature_nll, feature(bind_by_move_pattern_guards))]
20
21 #![cfg_attr(gate_and_feature_nll, feature(nll))]
22
23 //[gate_and_2015] edition:2015
24 //[gate_and_2018] edition:2018
25 //[gate_and_znll] compile-flags: -Z borrowck=mir
26
27 struct A { a: Box<i32> }
28
29 fn foo(n: i32) {
30     let x = A { a: Box::new(n) };
31     let _y = match x {
32
33         A { a: v } if *v == 42 => v,
34         //[no_gate]~^ ERROR cannot bind by-move into a pattern guard
35         //[gate_and_2015]~^^ ERROR cannot bind by-move into a pattern guard
36
37         _ => Box::new(0)
38     };
39 }
40
41 #[rustc_error]
42 fn main() {
43     foo(107)
44 }
45 //[gate_and_2018]~^^^ ERROR compilation successful
46 //[gate_and_znll]~^^^^ ERROR compilation successful
47 //[gate_and_feature_nll]~^^^^^ ERROR compilation successful