From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- ...e-52059-report-when-borrow-and-drop-conflict.rs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs (limited to 'tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs') diff --git a/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs b/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs new file mode 100644 index 000000000..7ea1c445d --- /dev/null +++ b/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.rs @@ -0,0 +1,30 @@ +// rust-lang/rust#52059: Regardless of whether you are moving out of a +// Drop type or just introducing an inadvertent 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. + +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() {} -- cgit v1.2.3