-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[MIR] Phantom unit write after return #31472
Comments
The write here is the empty write at the end of a block - which should not exist if the block is diverging. Unclear whether we should not create the (ill-formed) write when building or remove it in post-processing. |
NB: This write gets removed by simplifycfg (you need to comment the pass out to reproduce the issue). |
This would still pose a problem to analysis passes that want to run before SimplifyCfg. I am adding an early pass for my MIR typeck PR to ameliorate this problem. |
Likely caused by this |
The root cause of the problem is that typeck allows "diverging" blocks to have any kind of return value instead of requiring it to be MIR. I think that clearing the diverging blocks in a post-pass is a better strategy than detecting diverging blocks in HAIR. |
Maybe we should only emit what @nagisa linked to when the actual type of the block is unit? Generally, a missing final expression doesn't necessarily mean fn foo() -> i32 { panic!(); } // OK
fn foo() -> i32 { panic!(); () } // expected `i32`, found `()` - http://is.gd/qVOTyf EDIT: Do we want to omit the unit write even for a block of type unit if the block is diverging? Then what I said wouldn't help. |
As far as I can tell, this was fixed by #47746, where the trailing unit is only added if the return type of the function is the unit type. |
EDIT: I was confused about the issue
The text was updated successfully, but these errors were encountered: