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.
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.
11 // compile-flags: -Z force-dropflag-checks=on
14 // Quick-and-dirty test to ensure -Z force-dropflag-checks=on works as
15 // expected. Note that the inlined drop-flag is slated for removal
16 // (RFC 320); when that happens, the -Z flag and this test should
19 // See also drop-flag-skip-sanity-check.rs.
22 use std
::process
::Command
;
25 let args
: Vec
<String
> = env
::args().collect();
26 if args
.len() > 1 && args
[1] == "test" {
30 let mut p
= Command
::new(&args
[0]).arg("test").spawn().unwrap();
31 // The invocation should fail due to the drop-flag sanity check.
32 assert
!(!p
.wait().unwrap().success());
40 impl Drop
for Corrupted
{
41 fn drop(&mut self) { println!("dropping"); }
46 let mut c1
= Corrupted { x: 1 }
;
47 let mut c2
= Corrupted { x: 2 }
;
49 let p1
= &mut c1
as *mut Corrupted
as *mut u8;
50 let p2
= &mut c2
as *mut Corrupted
as *mut u8;
51 for i
in 0..std
::mem
::size_of
::<Corrupted
>() {
52 // corrupt everything, *including the drop flag.
54 // (We corrupt via two different means to safeguard
55 // against the hypothetical assignment of the
56 // dtor_needed/dtor_done values to v and v+k. that
57 // happen to match with one of the corruption values
59 *p1
.offset(i
as isize) += 2;
60 *p2
.offset(i
as isize) += 3;
63 // Here, at the end of the scope of `c1` and `c2`, the
64 // drop-glue should detect the corruption of (at least one of)
67 println
!("We should never get here.");