about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-14 21:35:16 +0000
committerbors <bors@rust-lang.org>2022-08-14 21:35:16 +0000
commitb8c0a01b2b651416f5e7461209ff1a93a98619e4 (patch)
tree6e77649de55a0a57466b0827cb4963fb5d9ecfaf /src/test
parent801821d1560f84e4716fcbd9244ec959320a13d5 (diff)
parent59795d0cb275aef6c9bce021492e56f2a218b5b9 (diff)
downloadrust-b8c0a01b2b651416f5e7461209ff1a93a98619e4.tar.gz
rust-b8c0a01b2b651416f5e7461209ff1a93a98619e4.zip
Auto merge of #100540 - matthiaskrgr:rollup-734hkpt, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #100249 (Fix HorizonOS regression in FileTimes)
 - #100253 (Recover from mutable variable declaration where `mut` is placed before `let`)
 - #100482 (Add Duration rounding change to release note)
 - #100523 ([rustdoc] remove Clean trait)
 - #100524 (Impl `Debug` for some structs of rustbuild)
 - #100526 (Add tests for the drop behavior of some control flow constructs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/drop/drop_order.rs145
-rw-r--r--src/test/ui/parser/issue-100197-mut-let.fixed6
-rw-r--r--src/test/ui/parser/issue-100197-mut-let.rs6
-rw-r--r--src/test/ui/parser/issue-100197-mut-let.stderr8
4 files changed, 165 insertions, 0 deletions
diff --git a/src/test/ui/drop/drop_order.rs b/src/test/ui/drop/drop_order.rs
new file mode 100644
index 00000000000..e42150dcc09
--- /dev/null
+++ b/src/test/ui/drop/drop_order.rs
@@ -0,0 +1,145 @@
+// run-pass
+
+use std::cell::RefCell;
+use std::convert::TryInto;
+
+#[derive(Default)]
+struct DropOrderCollector(RefCell<Vec<u32>>);
+
+struct LoudDrop<'a>(&'a DropOrderCollector, u32);
+
+impl Drop for LoudDrop<'_> {
+    fn drop(&mut self) {
+        println!("{}", self.1);
+        self.0.0.borrow_mut().push(self.1);
+    }
+}
+
+impl DropOrderCollector {
+    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
+        Some(LoudDrop(self, n))
+    }
+
+    fn loud_drop(&self, n: u32) -> LoudDrop {
+        LoudDrop(self, n)
+    }
+
+    fn print(&self, n: u32) {
+        println!("{}", n);
+        self.0.borrow_mut().push(n)
+    }
+
+    fn if_(&self) {
+        if self.option_loud_drop(1).is_some() {
+            self.print(2);
+        }
+
+        if self.option_loud_drop(3).is_none() {
+            unreachable!();
+        } else if self.option_loud_drop(4).is_some() {
+            self.print(5);
+        }
+
+        if {
+            if self.option_loud_drop(7).is_some() && self.option_loud_drop(6).is_some() {
+                self.loud_drop(8);
+                true
+            } else {
+                false
+            }
+        } {
+            self.print(9);
+        }
+    }
+
+    fn if_let(&self) {
+        if let None = self.option_loud_drop(2) {
+            unreachable!();
+        } else {
+            self.print(1);
+        }
+
+        if let Some(_) = self.option_loud_drop(4) {
+            self.print(3);
+        }
+
+        if let Some(_d) = self.option_loud_drop(6) {
+            self.print(5);
+        }
+    }
+
+    fn match_(&self) {
+        match self.option_loud_drop(2) {
+            _any => self.print(1),
+        }
+
+        match self.option_loud_drop(4) {
+            _ => self.print(3),
+        }
+
+        match self.option_loud_drop(6) {
+            Some(_) => self.print(5),
+            _ => unreachable!(),
+        }
+
+        match {
+            let _ = self.loud_drop(7);
+            let _d = self.loud_drop(9);
+            self.print(8);
+            ()
+        } {
+            () => self.print(10),
+        }
+
+        match {
+            match self.option_loud_drop(14) {
+                _ => {
+                    self.print(11);
+                    self.option_loud_drop(13)
+                }
+            }
+        } {
+            _ => self.print(12),
+        }
+
+        match {
+            loop {
+                break match self.option_loud_drop(16) {
+                    _ => {
+                        self.print(15);
+                        self.option_loud_drop(18)
+                    }
+                };
+            }
+        } {
+            _ => self.print(17),
+        }
+    }
+
+    fn assert_sorted(self) {
+        assert!(
+            self.0
+                .into_inner()
+                .into_iter()
+                .enumerate()
+                .all(|(idx, item)| idx + 1 == item.try_into().unwrap())
+        );
+    }
+}
+
+fn main() {
+    println!("-- if --");
+    let collector = DropOrderCollector::default();
+    collector.if_();
+    collector.assert_sorted();
+
+    println!("-- if let --");
+    let collector = DropOrderCollector::default();
+    collector.if_let();
+    collector.assert_sorted();
+
+    println!("-- match --");
+    let collector = DropOrderCollector::default();
+    collector.match_();
+    collector.assert_sorted();
+}
diff --git a/src/test/ui/parser/issue-100197-mut-let.fixed b/src/test/ui/parser/issue-100197-mut-let.fixed
new file mode 100644
index 00000000000..5a895622200
--- /dev/null
+++ b/src/test/ui/parser/issue-100197-mut-let.fixed
@@ -0,0 +1,6 @@
+// run-rustfix
+
+fn main() {
+    let mut _x = 123;
+    //~^ ERROR invalid variable declaration
+}
diff --git a/src/test/ui/parser/issue-100197-mut-let.rs b/src/test/ui/parser/issue-100197-mut-let.rs
new file mode 100644
index 00000000000..71103813a6e
--- /dev/null
+++ b/src/test/ui/parser/issue-100197-mut-let.rs
@@ -0,0 +1,6 @@
+// run-rustfix
+
+fn main() {
+    mut let _x = 123;
+    //~^ ERROR invalid variable declaration
+}
diff --git a/src/test/ui/parser/issue-100197-mut-let.stderr b/src/test/ui/parser/issue-100197-mut-let.stderr
new file mode 100644
index 00000000000..86658e4f39f
--- /dev/null
+++ b/src/test/ui/parser/issue-100197-mut-let.stderr
@@ -0,0 +1,8 @@
+error: invalid variable declaration
+  --> $DIR/issue-100197-mut-let.rs:4:5
+   |
+LL |     mut let _x = 123;
+   |     ^^^^^^^ help: switch the order of `mut` and `let`: `let mut`
+
+error: aborting due to previous error
+