]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs
fix merge conflicts
[rust.git] / src / test / ui / nll / issue-52059-report-when-borrow-and-drop-conflict.rs
1 // rust-lang/rust#52059: Regardless of whether you are moving out of a
2 // Drop type or just introducing an inadvertent alias via a borrow of
3 // one of its fields, it is useful to be reminded of the significance
4 // of the fact that the type implements Drop.
5
6 #![feature(nll)]
7
8 pub struct S<'a> { url: &'a mut String }
9
10 impl<'a> Drop for S<'a> { fn drop(&mut self) { } }
11
12 fn finish_1(s: S) -> &mut String {
13     s.url
14 }
15 //~^^ ERROR borrow may still be in use when destructor runs
16
17 fn finish_2(s: S) -> &mut String {
18     let p = &mut *s.url; p
19 }
20 //~^^ ERROR borrow may still be in use when destructor runs
21
22 fn finish_3(s: S) -> &mut String {
23     let p: &mut _ = s.url; p
24 }
25 //~^^ ERROR borrow may still be in use when destructor runs
26
27 fn finish_4(s: S) -> &mut String {
28     let p = s.url; p
29 }
30 //~^^ ERROR cannot move out of type `S<'_>`, which implements the `Drop` trait
31
32 fn main() {}