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 d576ef3

Browse files
committedJul 29, 2015
Auto merge of #27261 - arielb1:drop-sanity-check, r=pnkfelix
This fixes multiple bugs, and as several of these are soundness issue, is a [breaking-change]. r? @pnkfelix
2 parents 4b4119d + e99b53e commit d576ef3

File tree

6 files changed

+315
-254
lines changed

6 files changed

+315
-254
lines changed
 

‎src/librustc_typeck/check/dropck.rs

Lines changed: 190 additions & 253 deletions
Large diffs are not rendered by default.

‎src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn regionck_ensure_component_tys_wf<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
174174
// INTERNALS
175175

176176
pub struct Rcx<'a, 'tcx: 'a> {
177-
fcx: &'a FnCtxt<'a, 'tcx>,
177+
pub fcx: &'a FnCtxt<'a, 'tcx>,
178178

179179
region_bound_pairs: Vec<(ty::Region, GenericKind<'tcx>)>,
180180

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015 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+
// check that dropck does the right thing with misc. Ty variants
12+
13+
use std::fmt;
14+
struct NoisyDrop<T: fmt::Debug>(T);
15+
impl<T: fmt::Debug> Drop for NoisyDrop<T> {
16+
fn drop(&mut self) {
17+
let _ = vec!["0wned"];
18+
println!("dropping {:?}", self.0)
19+
}
20+
}
21+
22+
trait Associator {
23+
type As;
24+
}
25+
impl<T: fmt::Debug> Associator for T {
26+
type As = NoisyDrop<T>;
27+
}
28+
struct Wrap<A: Associator>(<A as Associator>::As);
29+
30+
fn projection() {
31+
let (_w, bomb);
32+
bomb = vec![""];
33+
_w = Wrap::<&[&str]>(NoisyDrop(&bomb));
34+
//~^ ERROR `bomb` does not live long enough
35+
}
36+
37+
fn closure() {
38+
let (_w,v);
39+
v = vec![""];
40+
_w = {
41+
let u = NoisyDrop(&v);
42+
//~^ ERROR `v` does not live long enough
43+
move || u.0.len()
44+
};
45+
}
46+
47+
fn main() { closure(); projection() }

‎src/test/run-pass/issue-24086.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2015 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+
pub struct Registry<'a> {
12+
listener: &'a mut (),
13+
}
14+
15+
pub struct Listener<'a> {
16+
pub announce: Option<Box<FnMut(&mut Registry) + 'a>>,
17+
pub remove: Option<Box<FnMut(&mut Registry) + 'a>>,
18+
}
19+
20+
impl<'a> Drop for Registry<'a> {
21+
fn drop(&mut self) {}
22+
}
23+
24+
fn main() {
25+
let mut registry_listener = Listener {
26+
announce: None,
27+
remove: None,
28+
};
29+
}

‎src/test/run-pass/issue-26641.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
struct Parser<'a>(Box<FnMut(Parser) + 'a>);
12+
13+
fn main() {
14+
let _x = Parser(Box::new(|_|{}));
15+
}

‎src/test/run-pass/issue-27240.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2015 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+
use std::fmt;
12+
struct NoisyDrop<T: fmt::Debug>(T);
13+
impl<T: fmt::Debug> Drop for NoisyDrop<T> {
14+
fn drop(&mut self) {}
15+
}
16+
17+
struct Bar<T: fmt::Debug>([*const NoisyDrop<T>; 2]);
18+
19+
fn fine() {
20+
let (u,b);
21+
u = vec![43];
22+
b = Bar([&NoisyDrop(&u), &NoisyDrop(&u)]);
23+
}
24+
25+
struct Bar2<T: fmt::Debug>(*const NoisyDrop<T>, *const NoisyDrop<T>);
26+
27+
fn lolwut() {
28+
let (u,v);
29+
u = vec![43];
30+
v = Bar2(&NoisyDrop(&u), &NoisyDrop(&u));
31+
}
32+
33+
fn main() { fine(); lolwut() }

0 commit comments

Comments
 (0)
Please sign in to comment.