-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
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