Skip to content

Conditional assignment with multiple if/else appears broken #144911

@CLEckhardt

Description

@CLEckhardt

When attempting a conditional assignment after a statement containing an early return, the compiler seems to think that the assignment type is a return type when using if/else, but this doesn't occur when using the an equivalent match with conditionals.

Example with failing and working code here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=ad9db532628940de405ab21ff4a5a3a4

The playground example error message doesn't show this, but when working on my code, the error message references the early return line. So it would say something like "note: return type inferred to be () here" and reference line 8 in the example. Unfortunately, I can't reproduce that error message hint, nor can I share my code.

This occurs on stable and nightly.

EDIT:
This actually appears to be simpler and not require an early return.

Simpler example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8d8d4dada286cad5934bc728c9ea92c4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions