-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit diagnostic suggestion for error when if let used with enum varia…
…nt without being initialized compare the span base id to get the correct expression and add suggestion to it modified: compiler/rustc_infer/src/infer/error_reporting/mod.rs modified: compiler/rustc_span/src/span_encoding.rs modified: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs modified: compiler/rustc_typeck/src/check/compare_method.rs modified: compiler/rustc_typeck/src/check/fn_ctxt/checks.rs new file: src/test/ui/type/issue-101208.rs new file: src/test/ui/type/issue-101208.stderr
- Loading branch information
Yiming Lei
committed
Sep 27, 2022
1 parent
4a14677
commit cdcca2c
Showing
7 changed files
with
108 additions
and
3 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 |
---|---|---|
|
@@ -848,6 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
e, | ||
false, | ||
true, | ||
false, | ||
); | ||
} | ||
} | ||
|
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,10 @@ | ||
enum E { | ||
One(i32, i32) | ||
} | ||
fn main() { | ||
let var = E::One; | ||
if let E::One(var1, var2) = var { | ||
//~^ ERROR 0308 | ||
println!("{var1} {var2}"); | ||
} | ||
} |
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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-101208.rs:6:12 | ||
| | ||
LL | if let E::One(var1, var2) = var { | ||
| ^^^^^^^^^^^^^^^^^^ --- this expression has type `fn(i32, i32) -> E {E::One}` | ||
| | | ||
| expected fn item, found enum `E` | ||
| | ||
= note: expected fn item `fn(i32, i32) -> E {E::One}` | ||
found enum `E` | ||
help: use parentheses to instantiate this tuple variant | ||
| | ||
LL | if let E::One(var1, var2) = var(_,_) { | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |