-
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
Account for !
arm in tail match
expr
#117526
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
@@ -139,7 +139,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
&cause, | |||
Some(&arm.body), | |||
arm_ty, | |||
|err| self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm), | |||
|err| { | |||
if let hir::ExprKind::Block(block, _) = arm.body.kind |
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.
Please hide this closure body behind a function!
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.
Done
6bb6f78
to
8e8a73e
Compare
☔ The latest upstream changes (presumably #118143) made this pull request unmergeable. Please resolve the merge conflicts. |
8e8a73e
to
1d8e053
Compare
Sorry, I forgot that I had already looked at this before 🤦 @bors r+ rollup |
Account for `!` arm in tail `match` expr On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix rust-lang#24157.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix rust-lang#24157.
1d8e053
to
8221f9c
Compare
@bors r=b-naber |
Account for `!` arm in tail `match` expr On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix rust-lang#24157.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#111133 (Detect Python-like slicing and suggest how to fix) - rust-lang#114708 (Allow setting `rla` labels via `rustbot`) - rust-lang#117526 (Account for `!` arm in tail `match` expr) - rust-lang#118282 (effects: Run `enforce_context_effects` for all method calls) - rust-lang#118366 (Detect and reject malformed `repr(Rust)` hints) - rust-lang#118375 (Add -Zunpretty=stable-mir output test) r? `@ghost` `@rustbot` modify labels: rollup
Account for `!` arm in tail `match` expr On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix rust-lang#24157.
…llaumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#111133 (Detect Python-like slicing and suggest how to fix) - rust-lang#114708 (Allow setting `rla` labels via `rustbot`) - rust-lang#117526 (Account for `!` arm in tail `match` expr) - rust-lang#118341 (Simplify indenting in THIR printing) - rust-lang#118366 (Detect and reject malformed `repr(Rust)` hints) - rust-lang#118375 (Add -Zunpretty=stable-mir output test) - rust-lang#118381 (rustc_span: Use correct edit distance start length for suggestions) - rust-lang#118384 (Address unused tuple struct fields in rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#111133 (Detect Python-like slicing and suggest how to fix) - rust-lang#114708 (Allow setting `rla` labels via `rustbot`) - rust-lang#117526 (Account for `!` arm in tail `match` expr) - rust-lang#118172 (Add `pretty_terminator` to pretty stable-mir) - rust-lang#118202 (Added linker_arg(s) Linker trait methods for link-arg to be prefixed "-Wl," for cc-like linker args and not verbatim) - rust-lang#118374 (QueryContext: rename try_collect_active_jobs -> collect_active_jobs, change return type from Option<QueryMap> to QueryMap) - rust-lang#118381 (rustc_span: Use correct edit distance start length for suggestions) - rust-lang#118382 (Address unused tuple struct fields in the compiler) - rust-lang#118384 (Address unused tuple struct fields in rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117526 - estebank:issue-24157, r=b-naber Account for `!` arm in tail `match` expr On functions with a default return type that influences the coerced type of `match` arms, check if the failing arm is actually of type `!`. If so, suggest changing the return type so the coercion against the prior arms is successful. ``` error[E0308]: `match` arms have incompatible types --> $DIR/match-tail-expr-never-type-error.rs:9:13 | LL | fn bar(a: bool) { | - help: try adding a return type: `-> i32` LL | / match a { LL | | true => 1, | | - this is found to be of type `{integer}` LL | | false => { LL | | never() | | ^^^^^^^ | | | | | expected integer, found `()` | | this expression is of type `!`, but it get's coerced to `()` due to its surrounding expression LL | | } LL | | } | |_____- `match` arms have incompatible types ``` Fix rust-lang#24157.
On functions with a default return type that influences the coerced type of
match
arms, check if the failing arm is actually of type!
. If so, suggest changing the return type so the coercion against the prior arms is successful.Fix #24157.