From 75146fd59cfa45024f70840558914b3de3158afa Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 24 Jun 2014 13:41:42 -0700 Subject: [PATCH] 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) {} Fix such code to not rely on undefined behavior. Closes #12534. [breaking-change] --- src/librustc/middle/check_match.rs | 1 + .../bind-by-move-no-sub-bindings-fun-args.rs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/compile-fail/bind-by-move-no-sub-bindings-fun-args.rs 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue #12534. + +struct A(Box); + +fn f(a @ A(u): A) -> Box { //~ ERROR cannot bind by-move with sub-bindings + drop(a); + u +} + +fn main() {} + -- 2.44.0