1 // Copyright 2016 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 // Issue 34101: Circa 2016-06-05, `fn inline` below issued an
12 // erroneous warning from the elaborate_drops pass about moving out of
13 // a field in `Foo`, which has a destructor (and thus cannot have
14 // content moved out of it). The reason that the warning is erroneous
15 // in this case is that we are doing a *replace*, not a move, of the
16 // content in question, and it is okay to replace fields within `Foo`.
18 // Another more subtle problem was that the elaborate_drops was
19 // creating a separate drop flag for that internally replaced content,
20 // even though the compiler should enforce an invariant that any drop
21 // flag for such subcontent of `Foo` will always have the same value
22 // as the drop flag for `Foo` itself.
24 // This test is structured in a funny way; we cannot test for emission
25 // of the warning in question via the lint system, and therefore
26 // `#![deny(warnings)]` does nothing to detect it.
28 // So instead we use `#[rustc_error]` and put the test into
29 // `compile_fail`, where the emitted warning *will* be caught.
31 #![feature(rustc_attrs)]
40 // (dummy variable so `f` gets assigned `var1` in MIR for both fn's)
42 let mut f = Foo(String::from("foo"));
43 f.0 = String::from("bar");
47 let _s = String::from("foo");
49 f.0 = String::from("bar");
53 fn main() { //~ ERROR compilation successful