Skip to content

Commit 75146fd

Browse files
pcwaltonalexcrichton
authored andcommitted
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]
1 parent 5ccf056 commit 75146fd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/middle/check_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
735735
},
736736
None => ()
737737
}
738+
check_legality_of_move_bindings(cx, false, [input.pat]);
738739
}
739740
}
740741

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Issue #12534.
12+
13+
struct A(Box<uint>);
14+
15+
fn f(a @ A(u): A) -> Box<uint> { //~ ERROR cannot bind by-move with sub-bindings
16+
drop(a);
17+
u
18+
}
19+
20+
fn main() {}
21+

0 commit comments

Comments
 (0)