diff --git a/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs new file mode 100644 index 00000000000..fff73c6d0fa --- /dev/null +++ b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs @@ -0,0 +1,33 @@ +// rust-lang/rust#52059: Regardless of whether you are moving out of a +// Drop type or just introducing an inadvertant alias via a borrow of +// one of its fields, it is useful to be reminded of the significance +// of the fact that the type implements Drop. + +#![feature(nll)] +#![allow(dead_code)] + +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() {} diff --git a/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr new file mode 100644 index 00000000000..71c97b7ad6b --- /dev/null +++ b/src/test/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr @@ -0,0 +1,61 @@ +error[E0713]: borrow may still be in use when destructor runs + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:14:5 + | +LL | s.url + | ^^^^^ +LL | } + | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait + | +note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 13:1... + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:13:1 + | +LL | / fn finish_1(s: S) -> &mut String { +LL | | s.url +LL | | } + | |_^ + +error[E0713]: borrow may still be in use when destructor runs + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:19:13 + | +LL | let p = &mut *s.url; p + | ^^^^^^^^^^^ +LL | } + | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait + | +note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 18:1... + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:18:1 + | +LL | / fn finish_2(s: S) -> &mut String { +LL | | let p = &mut *s.url; p +LL | | } + | |_^ + +error[E0713]: borrow may still be in use when destructor runs + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:24:21 + | +LL | let p: &mut _ = s.url; p + | ^^^^^ +LL | } + | - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait + | +note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 23:1... + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:23:1 + | +LL | / fn finish_3(s: S) -> &mut String { +LL | | let p: &mut _ = s.url; p +LL | | } + | |_^ + +error[E0509]: cannot move out of type `S<'_>`, which implements the `Drop` trait + --> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:29:13 + | +LL | let p = s.url; p + | ^^^^^ + | | + | cannot move out of here + | help: consider borrowing here: `&s.url` + +error: aborting due to 4 previous errors + +Some errors occurred: E0509, E0713. +For more information about an error, try `rustc --explain E0509`.