Typecheck else expression of let-else to ensure it diverges#3469
Open
CohenArthur wants to merge 2 commits intoRust-GCC:masterfrom
Open
Typecheck else expression of let-else to ensure it diverges#3469CohenArthur wants to merge 2 commits intoRust-GCC:masterfrom
else expression of let-else to ensure it diverges#3469CohenArthur wants to merge 2 commits intoRust-GCC:masterfrom
Conversation
CohenArthur
commented
Mar 5, 2025
Comment on lines
+115
to
+116
| // FIXME: Is that enough? Do we need to do something like | ||
| // `append_reference` here as well? |
Member
Author
There was a problem hiding this comment.
@philberty I'm not sure if there's anything else we need to do here. I was trying to use something like coercion_site(...) but obviously it doesn't work because any type is coercible to !, which is not the behavior we actually want here
Collaborator
There was a problem hiding this comment.
! should be coercible to any other type, but not the other way around
Member
There was a problem hiding this comment.
Ah ok yeah this is enough because all you need to do is check for ! in the else case so yes this is correct! Dont need to do unify or coercion site because it doesnt need to do anything else.
Dont think we support this in codegen
2ab175c to
cfd49f3
Compare
cfd49f3 to
99be28d
Compare
99be28d to
46023d4
Compare
ca2d3a7 to
e80f08c
Compare
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Visit the `else` expression instead of the `init` one if the let is a let-else.
Make sure the `else` expression resolves to the never type. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Check diverging else against `!`. gcc/testsuite/ChangeLog: * rust/compile/let-else-invalid-type.rs: New test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
elseexpression of alet-elsemust always diverge, which we enforce during typecheck. Needs #3468