Skip to content

fix: Skip pattern analysis on type mismatches #19875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

ShoyuVanilla
Copy link
Member

@ShoyuVanilla ShoyuVanilla commented May 27, 2025

Fixes #19844

Playing with tracings on rustc, I found that it never enters rustc_pattern_analysis if there exists any typecheck error inside the given body:

We've been doing simillar "skip on type-error" things on the following lines:

// We only include patterns whose type matches the type
// of the scrutinee expression. If we had an InvalidMatchArmPattern
// diagnostic or similar we could raise that in an else
// block here.
//
// When comparing the types, we also have to consider that rustc
// will automatically de-reference the scrutinee expression type if
// necessary.
//
// FIXME we should use the type checker for this.
if (pat_ty == scrut_ty
|| scrut_ty
.as_reference()
.map(|(match_expr_ty, ..)| match_expr_ty == pat_ty)
.unwrap_or(false))
&& types_of_subpatterns_do_match(arm.pat, &self.body, &self.infer)

if self.infer.expr_type_mismatches().next().is_some() {
// FIXME: Due to shortcomings in the current type system implementation, only emit
// this diagnostic if there are no type mismatches in the containing function.
} else if let Expr::MethodCall { receiver, .. } = expr {

But unfortunately not on the line in this PR

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 27, 2025
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 27, 2025
Merged via the queue into rust-lang:master with commit 4f7af13 May 27, 2025
14 checks passed
@ShoyuVanilla ShoyuVanilla deleted the issue-19844 branch May 28, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

internal error: entered unreachable code: trying to compare incompatible constructors Struct and Variant(EnumVariantContiguousIndex(0))
3 participants