Skip to content

Commit

Permalink
implement feature gate bind_by_move_pattern_guards
Browse files Browse the repository at this point in the history
implementation of issue rust-lang#15287
  • Loading branch information
Andreas Jonson authored and Andreas Jonson committed May 18, 2017
1 parent 0ed1ec9 commit 4b8dc18
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [associated_consts](language-features/associated-consts.md)
- [associated_type_defaults](language-features/associated-type-defaults.md)
- [attr_literals](language-features/attr-literals.md)
- [bind_by_move_pattern_guards](language-features/bind_by_move_pattern_guards.md)
- [box_patterns](language-features/box-patterns.md)
- [box_syntax](language-features/box-syntax.md)
- [catch_expr](language-features/catch-expr.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `bind_by_move_pattern_guards`

The tracking issue for this feature is: [#15287]

[#15287]: https://github.com/rust-lang/rust/issues/15287

------------------------



2 changes: 1 addition & 1 deletion src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
"cannot bind by-move with sub-bindings")
.span_label(p.span, "binds an already bound by-move value by moving it")
.emit();
} else if has_guard {
} else if has_guard && !cx.tcx.sess.features.borrow().bind_by_move_pattern_guards {
struct_span_err!(cx.tcx.sess, p.span, E0008,
"cannot bind by-move into a pattern guard")
.span_label(p.span, "moves value into pattern guard")
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ declare_features! (

// Allows use of the :vis macro fragment specifier
(active, macro_vis_matcher, "1.18.0", Some(41022)),

// Allows use of pattern guards with Bind-By-Move
(active, bind_by_move_pattern_guards, "1.18.0", Some(15287)),
);

declare_features! (
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/bind-by-move-move-in-guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

#![feature(bind_by_move_pattern_guards)]

use std::sync::Arc;
fn dispose(_x: Arc<bool>) { }

pub fn main() {
let p = Arc::new(true);
let x = Some(p);
match x {
Some(z) if {dispose(z); true} => { dispose(z); },//~ ERROR use of moved value: `z`
_ => panic!()
}
}

1 change: 1 addition & 0 deletions src/test/compile-fail/bind-by-move-no-guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-bind_by_move_pattern_guards
use std::sync::mpsc::channel;

fn main() {
Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/bind-by-move-with-guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2012-2014 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.

#![feature(bind_by_move_pattern_guards)]

use std::sync::Arc;
fn dispose(_x: Arc<bool>) { }

pub fn main() {
let p = Arc::new(true);
let x = Some(p);
match x {
Some(z) if z == true => { dispose(z); },
None => panic!()
}
}

0 comments on commit 4b8dc18

Please sign in to comment.