summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-16492.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/ui/issues/issue-16492.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/issues/issue-16492.rs')
-rw-r--r--tests/ui/issues/issue-16492.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/ui/issues/issue-16492.rs b/tests/ui/issues/issue-16492.rs
new file mode 100644
index 000000000..7fa808237
--- /dev/null
+++ b/tests/ui/issues/issue-16492.rs
@@ -0,0 +1,67 @@
+// run-pass
+#![allow(non_snake_case)]
+
+use std::rc::Rc;
+use std::cell::Cell;
+
+struct Field {
+ number: usize,
+ state: Rc<Cell<usize>>
+}
+
+impl Field {
+ fn new(number: usize, state: Rc<Cell<usize>>) -> Field {
+ Field {
+ number: number,
+ state: state
+ }
+ }
+}
+
+impl Drop for Field {
+ fn drop(&mut self) {
+ println!("Dropping field {}", self.number);
+ assert_eq!(self.state.get(), self.number);
+ self.state.set(self.state.get()+1);
+ }
+}
+
+struct NoDropImpl {
+ _one: Field,
+ _two: Field,
+ _three: Field
+}
+
+struct HasDropImpl {
+ _one: Field,
+ _two: Field,
+ _three: Field
+}
+
+impl Drop for HasDropImpl {
+ fn drop(&mut self) {
+ println!("HasDropImpl.drop()");
+ assert_eq!(self._one.state.get(), 0);
+ self._one.state.set(1);
+ }
+}
+
+pub fn main() {
+ let state = Rc::new(Cell::new(1));
+ let noImpl = NoDropImpl {
+ _one: Field::new(1, state.clone()),
+ _two: Field::new(2, state.clone()),
+ _three: Field::new(3, state.clone())
+ };
+ drop(noImpl);
+ assert_eq!(state.get(), 4);
+
+ state.set(0);
+ let hasImpl = HasDropImpl {
+ _one: Field::new(1, state.clone()),
+ _two: Field::new(2, state.clone()),
+ _three: Field::new(3, state.clone())
+ };
+ drop(hasImpl);
+ assert_eq!(state.get(), 4);
+}