Skip to content

Fix if_then_some_else_none FP when require type coercion #15267

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

profetia
Copy link
Contributor

@profetia profetia commented Jul 13, 2025

Closes #15257

changelog: [if_then_some_else_none] fix FP when require type coercion

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 13, 2025
Copy link

Lintcheck changes for b6c0d63

Lint Added Removed Changed
clippy::if_then_some_else_none 0 21 2

This comment will be updated if you push new changes

@profetia profetia marked this pull request as draft July 13, 2025 15:14
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 13, 2025
@blyxyas blyxyas added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Jul 13, 2025
@@ -79,6 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
&& !expr.span.in_external_macro(cx.sess().source_map())
&& self.msrv.meets(cx, msrvs::BOOL_THEN)
&& !contains_return(then_block.stmts)
&& !expr_requires_coercion(cx, then_expr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, what do you think about, instead of completely discarding the block if it requires type coercion, we check if we're in a trait item function (we cannot change the signatures of those functions) and if we're in just a normal function, we emit a non-MachineApplicable suggestion with a note about the user will have to modify the return type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if-then-some-else-none changes return type
3 participants