forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#107098 - compiler-errors:pat-mismatch-fn-ca…
…ll, r=lcnr Suggest function call on pattern type mismatch Fixes rust-lang#101208 This could definitely be generalized to support more suggestions in pattern matches. We can't use all of [`FnCtxt::emit_type_mismatch_suggestions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/fn_ctxt/struct.FnCtxt.html#method.emit_type_mismatch_suggestions), but it's on my to-do list to play around with more suggestions that would be productive in this position.
- Loading branch information
Showing
6 changed files
with
68 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
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,16 @@ | ||
enum E { | ||
One(i32, i32), | ||
} | ||
|
||
fn main() { | ||
let var = E::One; | ||
if let E::One(var1, var2) = var { | ||
//~^ ERROR mismatched types | ||
//~| HELP use parentheses to construct this tuple variant | ||
println!("{var1} {var2}"); | ||
} | ||
|
||
let Some(x) = Some; | ||
//~^ ERROR mismatched types | ||
//~| HELP use parentheses to construct this tuple variant | ||
} |
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,33 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/suggest-call-on-pat-mismatch.rs:7:12 | ||
| | ||
LL | if let E::One(var1, var2) = var { | ||
| ^^^^^^^^^^^^^^^^^^ --- this expression has type `fn(i32, i32) -> E {E::One}` | ||
| | | ||
| expected enum constructor, found enum `E` | ||
| | ||
= note: expected enum constructor `fn(i32, i32) -> E {E::One}` | ||
found enum `E` | ||
help: use parentheses to construct this tuple variant | ||
| | ||
LL | if let E::One(var1, var2) = var(/* i32 */, /* i32 */) { | ||
| ++++++++++++++++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/suggest-call-on-pat-mismatch.rs:13:9 | ||
| | ||
LL | let Some(x) = Some; | ||
| ^^^^^^^ ---- this expression has type `fn(_) -> Option<_> {Option::<_>::Some}` | ||
| | | ||
| expected enum constructor, found enum `Option` | ||
| | ||
= note: expected enum constructor `fn(_) -> Option<_> {Option::<_>::Some}` | ||
found enum `Option<_>` | ||
help: use parentheses to construct this tuple variant | ||
| | ||
LL | let Some(x) = Some(/* value */); | ||
| +++++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |