about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-22 15:22:49 +0000
committerbors <bors@rust-lang.org>2024-03-22 15:22:49 +0000
commit2fae357cb87d6ec184a34892394d4e737ecd6030 (patch)
tree2e95d58c16c36d9159307f386ce1912c94bc4fff /tests/ui/pattern
parentf61f45f2336ad473ca152252f81e447ae19e0553 (diff)
parentee57d2b318fc17080740172896269cd9865a17f4 (diff)
downloadrust-2fae357cb87d6ec184a34892394d4e737ecd6030.tar.gz
rust-2fae357cb87d6ec184a34892394d4e737ecd6030.zip
Auto merge of #3394 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/deref-patterns/typeck.rs31
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-114896.fixed10
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-114896.rs (renamed from tests/ui/pattern/issue-114896.rs)3
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-114896.stderr (renamed from tests/ui/pattern/issue-114896.stderr)2
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-122415.fixed11
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-122415.rs11
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-122415.stderr11
7 files changed, 78 insertions, 1 deletions
diff --git a/tests/ui/pattern/deref-patterns/typeck.rs b/tests/ui/pattern/deref-patterns/typeck.rs
new file mode 100644
index 00000000000..ead6dcdbaf0
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/typeck.rs
@@ -0,0 +1,31 @@
+//@ check-pass
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+
+use std::rc::Rc;
+
+fn main() {
+    let vec: Vec<u32> = Vec::new();
+    match vec {
+        deref!([..]) => {}
+        _ => {}
+    }
+    match Box::new(true) {
+        deref!(true) => {}
+        _ => {}
+    }
+    match &Box::new(true) {
+        deref!(true) => {}
+        _ => {}
+    }
+    match &Rc::new(0) {
+        deref!(1..) => {}
+        _ => {}
+    }
+    // FIXME(deref_patterns): fails to typecheck because `"foo"` has type &str but deref creates a
+    // place of type `str`.
+    // match "foo".to_string() {
+    //     box "foo" => {}
+    //     _ => {}
+    // }
+}
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed
new file mode 100644
index 00000000000..086a119eb77
--- /dev/null
+++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.fixed
@@ -0,0 +1,10 @@
+//@ run-rustfix
+#![allow(dead_code)]
+
+fn main() {
+    fn x(a: &char) {
+        let &(mut b) = a;
+        b.make_ascii_uppercase();
+//~^ cannot borrow `b` as mutable, as it is not declared as mutable
+    }
+}
diff --git a/tests/ui/pattern/issue-114896.rs b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs
index cde37f658d6..b4d6b72c01f 100644
--- a/tests/ui/pattern/issue-114896.rs
+++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.rs
@@ -1,3 +1,6 @@
+//@ run-rustfix
+#![allow(dead_code)]
+
 fn main() {
     fn x(a: &char) {
         let &b = a;
diff --git a/tests/ui/pattern/issue-114896.stderr b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr
index 285c9109e1b..68538255edd 100644
--- a/tests/ui/pattern/issue-114896.stderr
+++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr
@@ -1,5 +1,5 @@
 error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
-  --> $DIR/issue-114896.rs:4:9
+  --> $DIR/patkind-ref-binding-issue-114896.rs:7:9
    |
 LL |         let &b = a;
    |             -- help: consider changing this to be mutable: `&(mut b)`
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed
new file mode 100644
index 00000000000..6144f062169
--- /dev/null
+++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.fixed
@@ -0,0 +1,11 @@
+//@ run-rustfix
+#![allow(dead_code)]
+
+fn mutate(_y: &mut i32) {}
+
+fn foo(&(mut x): &i32) {
+    mutate(&mut x);
+    //~^ ERROR cannot borrow `x` as mutable
+}
+
+fn main() {}
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.rs b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs
new file mode 100644
index 00000000000..b9f6416027a
--- /dev/null
+++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.rs
@@ -0,0 +1,11 @@
+//@ run-rustfix
+#![allow(dead_code)]
+
+fn mutate(_y: &mut i32) {}
+
+fn foo(&x: &i32) {
+    mutate(&mut x);
+    //~^ ERROR cannot borrow `x` as mutable
+}
+
+fn main() {}
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr
new file mode 100644
index 00000000000..39283133ac7
--- /dev/null
+++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr
@@ -0,0 +1,11 @@
+error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
+  --> $DIR/patkind-ref-binding-issue-122415.rs:7:12
+   |
+LL | fn foo(&x: &i32) {
+   |        -- help: consider changing this to be mutable: `&(mut x)`
+LL |     mutate(&mut x);
+   |            ^^^^^^ cannot borrow as mutable
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0596`.