2018-09-17 19:03:54 -05:00
|
|
|
// rust-lang/rust#52059: Regardless of whether you are moving out of a
|
2018-10-22 11:21:55 -05:00
|
|
|
// Drop type or just introducing an inadvertent alias via a borrow of
|
2018-09-17 19:03:54 -05:00
|
|
|
// one of its fields, it is useful to be reminded of the significance
|
|
|
|
// of the fact that the type implements Drop.
|
|
|
|
|
|
|
|
pub struct S<'a> { url: &'a mut String }
|
|
|
|
|
|
|
|
impl<'a> Drop for S<'a> { fn drop(&mut self) { } }
|
|
|
|
|
|
|
|
fn finish_1(s: S) -> &mut String {
|
|
|
|
s.url
|
|
|
|
}
|
|
|
|
//~^^ ERROR borrow may still be in use when destructor runs
|
|
|
|
|
|
|
|
fn finish_2(s: S) -> &mut String {
|
|
|
|
let p = &mut *s.url; p
|
|
|
|
}
|
|
|
|
//~^^ ERROR borrow may still be in use when destructor runs
|
|
|
|
|
|
|
|
fn finish_3(s: S) -> &mut String {
|
|
|
|
let p: &mut _ = s.url; p
|
|
|
|
}
|
|
|
|
//~^^ ERROR borrow may still be in use when destructor runs
|
|
|
|
|
|
|
|
fn finish_4(s: S) -> &mut String {
|
|
|
|
let p = s.url; p
|
|
|
|
}
|
|
|
|
//~^^ ERROR cannot move out of type `S<'_>`, which implements the `Drop` trait
|
|
|
|
|
|
|
|
fn main() {}
|