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