]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/issue-54556-wrap-it-up.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / ui / nll / issue-54556-wrap-it-up.rs
1 // This is testing how the diagnostic from issue #54556 behaves when
2 // the destructor code is attached to a place held in a field of the
3 // temporary being dropped.
4 //
5 // Eventually it would be nice if the diagnostic would actually report
6 // that specific place and its type that implements the `Drop` trait.
7 // But for the short term, it is acceptable to just print out the
8 // whole type of the temporary.
9
10 #![allow(warnings)]
11
12 struct Wrap<'p> { p: &'p mut i32 }
13
14 impl<'p> Drop for Wrap<'p> {
15 fn drop(&mut self) {
16 *self.p += 1;
17 }
18 }
19
20 struct Foo<'p> { a: String, b: Wrap<'p> }
21
22 fn main() {
23 let mut x = 0;
24 let wrap = Wrap { p: &mut x };
25 let s = String::from("str");
26 let foo = Foo { a: s, b: wrap };
27 x = 1; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
28 }