]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs
Auto merge of #105145 - Ayush1325:sequential-remote-server, r=Mark-Simulacrum
[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 pub struct S<'a> { url: &'a mut String }
7
8 impl<'a> Drop for S<'a> { fn drop(&mut self) { } }
9
10 fn finish_1(s: S) -> &mut String {
11     s.url
12 }
13 //~^^ ERROR borrow may still be in use when destructor runs
14
15 fn finish_2(s: S) -> &mut String {
16     let p = &mut *s.url; p
17 }
18 //~^^ ERROR borrow may still be in use when destructor runs
19
20 fn finish_3(s: S) -> &mut String {
21     let p: &mut _ = s.url; p
22 }
23 //~^^ ERROR borrow may still be in use when destructor runs
24
25 fn finish_4(s: S) -> &mut String {
26     let p = s.url; p
27 }
28 //~^^ ERROR cannot move out of type `S<'_>`, which implements the `Drop` trait
29
30 fn main() {}