-
Notifications
You must be signed in to change notification settings - Fork 177
Typecheck else
expression of let-else
to ensure it diverges
#3469
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
base: master
Are you sure you want to change the base?
Conversation
// FIXME: Is that enough? Do we need to do something like | ||
// `append_reference` here as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!
should be coercible to any other type, but not the other way around
3d1e2a6
to
2ab175c
Compare
gcc/rust/ChangeLog: * ast/rust-stmt.h (class LetStmt): Add optional expression for diverging else. * ast/rust-ast-builder.cc (Builder::let): Use new API.
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_let_stmt): Add new parsing in case of `else` token.
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add handling for diverging else expression.
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-stmt.h: Add handling for diverging else. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
gcc/rust/ChangeLog: * hir/tree/rust-hir-stmt.h (class LetStmt): Add optional diverging else expression. * hir/tree/rust-hir-stmt.cc: Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Add handling for lowering diverging else.
2ab175c
to
cfd49f3
Compare
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.
The
else
expression of alet-else
must always diverge, which we enforce during typecheck. Needs #3468