]> git.lizzy.rs Git - rust.git/blob - src/test/ui/no-warn-on-field-replace-issue-34101.rs
Auto merge of #55532 - pnkfelix:rustc_error-survey, r=nikomatsakis
[rust.git] / src / test / ui / no-warn-on-field-replace-issue-34101.rs
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.
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 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`.
17 //
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.
23
24
25
26
27
28
29
30
31 // compile-pass
32
33 struct Foo(String);
34
35 impl Drop for Foo {
36     fn drop(&mut self) {}
37 }
38
39 fn inline() {
40     // (dummy variable so `f` gets assigned `var1` in MIR for both fn's)
41     let _s = ();
42     let mut f = Foo(String::from("foo"));
43     f.0 = String::from("bar");
44 }
45
46 fn outline() {
47     let _s = String::from("foo");
48     let mut f = Foo(_s);
49     f.0 = String::from("bar");
50 }
51
52
53 fn main() {
54     inline();
55     outline();
56 }