about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-05-30 14:33:52 +0200
committerGitHub <noreply@github.com>2022-05-30 14:33:52 +0200
commit65bdfe3b41c862dd9413c49dfba884c6622897ab (patch)
treeddc3c7ad0e8d625911aafb0b9b714d403b4b584b /src
parent9bb3832ebd7aa820366598187862fd6370aefd9f (diff)
parent2e25c2346b9cf58c3c30375bd6e6defef1c11f07 (diff)
downloadrust-65bdfe3b41c862dd9413c49dfba884c6622897ab.tar.gz
rust-65bdfe3b41c862dd9413c49dfba884c6622897ab.zip
Rollup merge of #97531 - compiler-errors:for-loop-pat-mismatch, r=davidtwco
Note pattern mismatch coming from `for` loop desugaring

Fixes #97163
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/pattern/for-loop-bad-item.rs20
-rw-r--r--src/test/ui/pattern/for-loop-bad-item.stderr23
2 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/pattern/for-loop-bad-item.rs b/src/test/ui/pattern/for-loop-bad-item.rs
new file mode 100644
index 00000000000..9a56a399b9b
--- /dev/null
+++ b/src/test/ui/pattern/for-loop-bad-item.rs
@@ -0,0 +1,20 @@
+struct Qux(i32);
+
+fn bad() {
+    let mut map = std::collections::HashMap::new();
+    map.insert(('a', 'b'), ('c', 'd'));
+
+    for ((_, _), (&mut c, _)) in &mut map {
+    //~^ ERROR mismatched types
+        if c == 'e' {}
+    }
+}
+
+fn bad2() {
+    for Some(Qux(_)) | None in [Some(""), None] {
+    //~^ ERROR mismatched types
+        todo!();
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/pattern/for-loop-bad-item.stderr b/src/test/ui/pattern/for-loop-bad-item.stderr
new file mode 100644
index 00000000000..9410e4da8d2
--- /dev/null
+++ b/src/test/ui/pattern/for-loop-bad-item.stderr
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+  --> $DIR/for-loop-bad-item.rs:7:19
+   |
+LL |     for ((_, _), (&mut c, _)) in &mut map {
+   |                   ^^^^^^         -------- this is an iterator with items of type `(&(char, char), &mut (char, char))`
+   |                   |
+   |                   expected `char`, found `&mut _`
+   |                   help: you can probably remove the explicit borrow: `c`
+   |
+   = note:           expected type `char`
+           found mutable reference `&mut _`
+
+error[E0308]: mismatched types
+  --> $DIR/for-loop-bad-item.rs:14:14
+   |
+LL |     for Some(Qux(_)) | None in [Some(""), None] {
+   |              ^^^^^^            ---------------- this is an iterator with items of type `Option<&str>`
+   |              |
+   |              expected `str`, found struct `Qux`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.