-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E0023: handle expected != pat-tup-type
- Loading branch information
Showing
4 changed files
with
70 additions
and
10 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
21 changes: 21 additions & 0 deletions
21
src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs
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,21 @@ | ||
// Regression test for #67037. | ||
// | ||
// In type checking patterns, E0023 occurs when the tuple pattern and the expected | ||
// tuple pattern have different number of fields. For example, as below, `P()`, | ||
// the tuple struct pattern, has 0 fields, but requires 1 field. | ||
// | ||
// In emitting E0023, we try to see if this is a case of e.g., `Some(a, b, c)` but where | ||
// the scrutinee was of type `Some((a, b, c))`, and suggest that parenthesis be added. | ||
// | ||
// However, we did not account for the expected type being different than the tuple pattern type. | ||
// This caused an issue when the tuple pattern type (`P<T>`) was generic. | ||
// Specifically, we tried deriving the 0th field's type using the `substs` of the expected type. | ||
// When attempting to substitute `T`, there was no such substitution, so "out of range" occured. | ||
|
||
struct U {} // 0 type parameters offered | ||
struct P<T>(T); // 1 type parameter wanted | ||
|
||
fn main() { | ||
let P() = U {}; //~ ERROR mismatched types | ||
//~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 1 field | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
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,22 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 | ||
| | ||
LL | let P() = U {}; | ||
| ^^^ expected struct `U`, found struct `P` | ||
| | ||
= note: expected struct `U` | ||
found struct `P<_>` | ||
|
||
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field | ||
--> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 | ||
| | ||
LL | struct P<T>(T); // 1 type parameter wanted | ||
| --------------- tuple struct defined here | ||
... | ||
LL | let P() = U {}; | ||
| ^^^ expected 1 field, found 0 | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0023, E0308. | ||
For more information about an error, try `rustc --explain E0023`. |