-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #97531 - compiler-errors:for-loop-pat-mismatch, r=dav…
…idtwco Note pattern mismatch coming from `for` loop desugaring Fixes #97163
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |