diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-06-24 13:41:42 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-24 17:23:41 -0700 |
| commit | 75146fd59cfa45024f70840558914b3de3158afa (patch) | |
| tree | b99fb6c93649d611ed0e491ce7db7e2f290649f1 | |
| parent | 5ccf056a024b0769d7adc22f57eda8d75ae07a58 (diff) | |
librustc: Check function argument patterns for legality of by-move
bindings.
This will break code that incorrectly did things like:
fn f(a @ box b: Box<String>) {}
Fix such code to not rely on undefined behavior.
Closes #12534.
[breaking-change]
| -rw-r--r-- | src/librustc/middle/check_match.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/bind-by-move-no-sub-bindings-fun-args.rs | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 629c7f4dab7..27b826b9d1a 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -735,6 +735,7 @@ fn check_fn(cx: &mut MatchCheckCtxt, }, None => () } + check_legality_of_move_bindings(cx, false, [input.pat]); } } diff --git a/src/test/compile-fail/bind-by-move-no-sub-bindings-fun-args.rs b/src/test/compile-fail/bind-by-move-no-sub-bindings-fun-args.rs new file mode 100644 index 00000000000..0e5b659f125 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-no-sub-bindings-fun-args.rs @@ -0,0 +1,21 @@ +// 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. + +// Issue #12534. + +struct A(Box<uint>); + +fn f(a @ A(u): A) -> Box<uint> { //~ ERROR cannot bind by-move with sub-bindings + drop(a); + u +} + +fn main() {} + |
