summaryrefslogtreecommitdiffstats
path: root/src/test/ui/nll/issue-54556-wrap-it-up.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/nll/issue-54556-wrap-it-up.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/nll/issue-54556-wrap-it-up.rs')
-rw-r--r--src/test/ui/nll/issue-54556-wrap-it-up.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/nll/issue-54556-wrap-it-up.rs b/src/test/ui/nll/issue-54556-wrap-it-up.rs
new file mode 100644
index 000000000..11dbef0d8
--- /dev/null
+++ b/src/test/ui/nll/issue-54556-wrap-it-up.rs
@@ -0,0 +1,28 @@
+// This is testing how the diagnostic from issue #54556 behaves when
+// the destructor code is attached to a place held in a field of the
+// temporary being dropped.
+//
+// Eventually it would be nice if the diagnostic would actually report
+// that specific place and its type that implements the `Drop` trait.
+// But for the short term, it is acceptable to just print out the
+// whole type of the temporary.
+
+#![allow(warnings)]
+
+struct Wrap<'p> { p: &'p mut i32 }
+
+impl<'p> Drop for Wrap<'p> {
+ fn drop(&mut self) {
+ *self.p += 1;
+ }
+}
+
+struct Foo<'p> { a: String, b: Wrap<'p> }
+
+fn main() {
+ let mut x = 0;
+ let wrap = Wrap { p: &mut x };
+ let s = String::from("str");
+ let foo = Foo { a: s, b: wrap };
+ x = 1; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
+}