-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Point at return type when it influences non-first match
arm
#114819
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
@@ -402,7 +402,7 @@ pub enum ObligationCauseCode<'tcx> { | |||
OpaqueReturnType(Option<(Ty<'tcx>, Span)>), | |||
|
|||
/// Block implicit return | |||
BlockTailExpression(hir::HirId), | |||
BlockTailExpression(hir::HirId, hir::HirId, hir::MatchSource), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make these fields have names?
Some changes might have occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix rust-lang#78124.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me if ci passes
@@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { | |||
}; | |||
|
|||
if true { | |||
//~^ ERROR: this `if` has identical blocks | |||
// FIXME: should emit "this `if` has identical blocks" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why this regressed?
@bors r+ |
…rrors Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix rust-lang#78124.
…rrors Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix rust-lang#78124.
…rrors Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix rust-lang#78124.
@@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { | |||
(Pat::Str("for"), Pat::Str("}")) | |||
}, | |||
ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")), | |||
ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")), | |||
ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be the reason for the Clippy regression. Did the expression e
that is stored in the ExprKind::Match
change by any chance and that's why re-calling expr_search_pat
leads to different results than before? 🤔
(Pretty wild guess)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing in #115122
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#114588 (Improve docs for impl Default for ExitStatus) - rust-lang#114619 (Fix pthread_attr_union layout on Wasi) - rust-lang#114644 (Point out expectation even if we have `TypeError::RegionsInsufficientlyPolymorphic`) - rust-lang#114668 (Deny `FnDef` in patterns) - rust-lang#114819 (Point at return type when it influences non-first `match` arm) - rust-lang#114826 (Fix typos) - rust-lang#114837 (add missing feature(error_in_core)) - rust-lang#114853 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
Fix clippy lint for identical `if`/`else` contraining `?` expressions Follow up to rust-lang#114819.
Fix clippy lint for identical `if`/`else` contraining `?` expressions Follow up to rust-lang#114819.
…rrors Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix rust-lang#78124.
When encountering code like
Point at the return type and not at the prior arm, as that arm has type
!
which isn't influencing the arm corresponding to arm2
.Fix #78124.