diff options
| author | bors <bors@rust-lang.org> | 2015-07-29 06:47:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-29 06:47:55 +0000 |
| commit | d576ef3d7be3efe28f902bbb3b2197f4553db412 (patch) | |
| tree | c9fba34623e94a9a6222fc2729106e687e12ea30 /src/test | |
| parent | 4b4119d5c082e02f34b8ffb9aff41c8a71f30a13 (diff) | |
| parent | e99b53e1c16b6ab7dcac7ccc841fb9cb9fc75381 (diff) | |
| download | rust-d576ef3d7be3efe28f902bbb3b2197f4553db412.tar.gz rust-d576ef3d7be3efe28f902bbb3b2197f4553db412.zip | |
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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/dropck_misc_variants.rs | 47 | ||||
| -rw-r--r-- | src/test/run-pass/issue-24086.rs | 29 | ||||
| -rw-r--r-- | src/test/run-pass/issue-26641.rs | 15 | ||||
| -rw-r--r-- | src/test/run-pass/issue-27240.rs | 33 |
4 files changed, 124 insertions, 0 deletions
diff --git a/src/test/compile-fail/dropck_misc_variants.rs b/src/test/compile-fail/dropck_misc_variants.rs new file mode 100644 index 00000000000..ee957f20d00 --- /dev/null +++ b/src/test/compile-fail/dropck_misc_variants.rs @@ -0,0 +1,47 @@ +// Copyright 2015 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. + +// check that dropck does the right thing with misc. Ty variants + +use std::fmt; +struct NoisyDrop<T: fmt::Debug>(T); +impl<T: fmt::Debug> Drop for NoisyDrop<T> { + fn drop(&mut self) { + let _ = vec!["0wned"]; + println!("dropping {:?}", self.0) + } +} + +trait Associator { + type As; +} +impl<T: fmt::Debug> Associator for T { + type As = NoisyDrop<T>; +} +struct Wrap<A: Associator>(<A as Associator>::As); + +fn projection() { + let (_w, bomb); + bomb = vec![""]; + _w = Wrap::<&[&str]>(NoisyDrop(&bomb)); + //~^ ERROR `bomb` does not live long enough +} + +fn closure() { + let (_w,v); + v = vec![""]; + _w = { + let u = NoisyDrop(&v); + //~^ ERROR `v` does not live long enough + move || u.0.len() + }; +} + +fn main() { closure(); projection() } diff --git a/src/test/run-pass/issue-24086.rs b/src/test/run-pass/issue-24086.rs new file mode 100644 index 00000000000..0a8324eafe2 --- /dev/null +++ b/src/test/run-pass/issue-24086.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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. + +pub struct Registry<'a> { + listener: &'a mut (), +} + +pub struct Listener<'a> { + pub announce: Option<Box<FnMut(&mut Registry) + 'a>>, + pub remove: Option<Box<FnMut(&mut Registry) + 'a>>, +} + +impl<'a> Drop for Registry<'a> { + fn drop(&mut self) {} +} + +fn main() { + let mut registry_listener = Listener { + announce: None, + remove: None, + }; +} diff --git a/src/test/run-pass/issue-26641.rs b/src/test/run-pass/issue-26641.rs new file mode 100644 index 00000000000..16f1d4626fb --- /dev/null +++ b/src/test/run-pass/issue-26641.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +struct Parser<'a>(Box<FnMut(Parser) + 'a>); + +fn main() { + let _x = Parser(Box::new(|_|{})); +} diff --git a/src/test/run-pass/issue-27240.rs b/src/test/run-pass/issue-27240.rs new file mode 100644 index 00000000000..4e341d31172 --- /dev/null +++ b/src/test/run-pass/issue-27240.rs @@ -0,0 +1,33 @@ +// Copyright 2015 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. + +use std::fmt; +struct NoisyDrop<T: fmt::Debug>(T); +impl<T: fmt::Debug> Drop for NoisyDrop<T> { + fn drop(&mut self) {} +} + +struct Bar<T: fmt::Debug>([*const NoisyDrop<T>; 2]); + +fn fine() { + let (u,b); + u = vec![43]; + b = Bar([&NoisyDrop(&u), &NoisyDrop(&u)]); +} + +struct Bar2<T: fmt::Debug>(*const NoisyDrop<T>, *const NoisyDrop<T>); + +fn lolwut() { + let (u,v); + u = vec![43]; + v = Bar2(&NoisyDrop(&u), &NoisyDrop(&u)); +} + +fn main() { fine(); lolwut() } |
