Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4b8dc18

Browse files
Andreas JonsonAndreas Jonson
Andreas Jonson
authored and
Andreas Jonson
committedMay 18, 2017
implement feature gate bind_by_move_pattern_guards
implementation of issue rust-lang#15287
1 parent 0ed1ec9 commit 4b8dc18

File tree

7 files changed

+63
-1
lines changed

7 files changed

+63
-1
lines changed
 

‎src/doc/unstable-book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [associated_consts](language-features/associated-consts.md)
1818
- [associated_type_defaults](language-features/associated-type-defaults.md)
1919
- [attr_literals](language-features/attr-literals.md)
20+
- [bind_by_move_pattern_guards](language-features/bind_by_move_pattern_guards.md)
2021
- [box_patterns](language-features/box-patterns.md)
2122
- [box_syntax](language-features/box-syntax.md)
2223
- [catch_expr](language-features/catch-expr.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `bind_by_move_pattern_guards`
2+
3+
The tracking issue for this feature is: [#15287]
4+
5+
[#15287]: https://github.com/rust-lang/rust/issues/15287
6+
7+
------------------------
8+
9+
10+

‎src/librustc_const_eval/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
486486
"cannot bind by-move with sub-bindings")
487487
.span_label(p.span, "binds an already bound by-move value by moving it")
488488
.emit();
489-
} else if has_guard {
489+
} else if has_guard && !cx.tcx.sess.features.borrow().bind_by_move_pattern_guards {
490490
struct_span_err!(cx.tcx.sess, p.span, E0008,
491491
"cannot bind by-move into a pattern guard")
492492
.span_label(p.span, "moves value into pattern guard")

‎src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ declare_features! (
355355

356356
// Allows use of the :vis macro fragment specifier
357357
(active, macro_vis_matcher, "1.18.0", Some(41022)),
358+
359+
// Allows use of pattern guards with Bind-By-Move
360+
(active, bind_by_move_pattern_guards, "1.18.0", Some(15287)),
358361
);
359362

360363
declare_features! (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(bind_by_move_pattern_guards)]
12+
13+
use std::sync::Arc;
14+
fn dispose(_x: Arc<bool>) { }
15+
16+
pub fn main() {
17+
let p = Arc::new(true);
18+
let x = Some(p);
19+
match x {
20+
Some(z) if {dispose(z); true} => { dispose(z); },//~ ERROR use of moved value: `z`
21+
_ => panic!()
22+
}
23+
}
24+

‎src/test/compile-fail/bind-by-move-no-guards.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-bind_by_move_pattern_guards
1112
use std::sync::mpsc::channel;
1213

1314
fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(bind_by_move_pattern_guards)]
12+
13+
use std::sync::Arc;
14+
fn dispose(_x: Arc<bool>) { }
15+
16+
pub fn main() {
17+
let p = Arc::new(true);
18+
let x = Some(p);
19+
match x {
20+
Some(z) if z == true => { dispose(z); },
21+
None => panic!()
22+
}
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.