forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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 rust-lang#91098 - compiler-errors:issue-91058, r=este…
…bank Don't suggest certain fixups (`.field`, `.await`, etc) when reporting errors while matching on arrays When we have a type mismatch with a `cause.code` that is an `ObligationCauseCode::Pattern`, skip suggesting fixes like adding `.await` or accessing a struct's `.field` if the pattern's `root_ty` differs from the `expected` ty. This occurs in situations like this: ```rust struct S(()); fn main() { let array = [S(())]; match array { [()] => {} _ => {} } } ``` I think what's happening here is a layer of `[_; N]` is peeled off of both types and we end up seeing the mismatch between just `S` and `()`, but when we suggest a fixup, that applies to the expression with type `root_ty`. --- Questions: 1. Should this check live here, above all of the suggestions, or should I push this down into every suggestion when we match `ObligationCauseCode`? 2. Any other `ObligationCauseCode`s to check here? 3. Am I overlooking an easier way to get to this same conclusion without pattern matching on `ObligationCauseCode` and comparing `root_ty`? Fixes rust-lang#91058
- Loading branch information
Showing
4 changed files
with
44 additions
and
6 deletions.
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
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,11 @@ | ||
struct S(()); | ||
|
||
fn main() { | ||
let array = [S(())]; | ||
|
||
match array { | ||
[()] => {} | ||
//~^ ERROR mismatched types [E0308] | ||
_ => {} | ||
} | ||
} |
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,11 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-91058.rs:7:10 | ||
| | ||
LL | match array { | ||
| ----- this expression has type `[S; 1]` | ||
LL | [()] => {} | ||
| ^^ expected struct `S`, found `()` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |