-
Notifications
You must be signed in to change notification settings - Fork 157
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
Compiler error when compiling the IfLet
expression.
#1177
Comments
AST dump
|
HIR dump
|
@CohenArthur would love to fix this issue but not sure how to proceed. Looks like the AST lowering didn't correctly lower the
|
Yes, that looks like a good assumption. You can look into the AST lowering pass, which is located in I can assign you this issue and you see how you feel about solving it? We can always fix it together or have someone else fix it if it doesn't interest you anymore at some point :) |
Thanks! I'll take a look. |
Hi @antego would you like me to setup a guide for you on this? You have already found one of the main missing pieces which is HIR lowering. Though there are several parts that are need resolved when fixing this issue:
Name resolution will ensure we setup the proper conventions for resolveing the new bindings created in the if-let expr but we also need to ensure that the correct scoping is applied here. HIR lowering you already have a PR out for Type resolution is about setting up all the relevant type information for this bloc. Code generation is all about generating the GENERIC for this. |
Yeah, I've created a draft PR with a commit that I can reference here and ask for the further help 😂
Yes please!
Yeah I've seen that the error happens around the place that iterates through Ribs so I started reading this. But I still feel lost about what is actually happening here. |
@philberty could you please give some pointers for where the code for the name resolution, type resolution and code generation is located? So that I could check how it works for the |
Addresses Rust-GCC#1177.
Addresses Rust-GCC#1177.
Is that right that the name resolution should be implemented in |
Hi, @antego Yep name resolution should be fairly simple here, You should be able to copy how we do name resolution for the if blocks from that file. Though if let statements add a new binding and scope level so you need to declare the pattern so you should be able to see how that is done from rust-ast-resolve-stmt. It's possible to do each of these things in separate PR's so the HIR lowering piece is definitely something that can be merged now independently. |
Addresses Rust-GCC#1177.
1218: Lower IfLet expressions r=CohenArthur a=antego This PR addresses #1177. This change implements the "hir-lowering" part of the plan outlined here #1177 (comment). Co-authored-by: antego <antego@users.noreply.github.com>
1241: Implement name resolution for the IfLet expression. r=philberty a=antego Addresses #1177. Guidance from the ticket #1177: > You should be able to copy how we do name resolution for the if blocks from that file. Though if let statements add a new binding and scope level so you need to declare the pattern so you should be able to see how that is done from rust-ast-resolve-stmt. I don't understand how to modify the block expression resolution so that it can handle the `IfLet` expression. For now, I copied the code from the `MatchExpr` resolution. Not sure how to test it either and what is the desired expected result of the name resolution so I just hope that reviewers will spot the errors. I created this PR in order to get some guidance about how to proceed with it. Thanks! Co-authored-by: antego <antego@users.noreply.github.com>
1279: Implement type checking for the `IfLet` expression. r=philberty a=antego Addresses #1177. This change implements the type check for the `IfLet` expression. This is the adapted type checking code from the `MatchExpr`. Tested on this code ``` enum E { X(u8), } fn main() -> i32 { let mut res = 0; let v = E::X(4); if let E::X(n) = v { res = n; } 0 } ``` Compilation finishes without errors. Next is the implementation of the code generation but I'll need help to find where it's located. Co-authored-by: antego <antego@users.noreply.github.com>
FTR, some work on if-let expr was done in 8664ba4. |
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: * backend/rust-compile-expr.h: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: * checks/errors/borrowck/rust-bir-builder-struct.h: * checks/errors/borrowck/rust-function-collector.h: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): * checks/errors/privacy/rust-privacy-reporter.h: * checks/errors/rust-const-checker.cc (ConstChecker::visit): * checks/errors/rust-const-checker.h: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): * checks/errors/rust-unsafe-checker.h: * hir/rust-ast-lower-block.h: * hir/rust-ast-lower.cc (do_if_let_desugaring): (ASTLoweringIfLetBlock::visit): * hir/rust-ast-lower.h (struct_field_name_exists): (translate_visibility): * hir/rust-hir-dump.cc (Dump::do_ifletexpr): (Dump::visit): * hir/rust-hir-dump.h: * hir/tree/rust-hir-expr.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-full-decls.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-visitor.h: * hir/tree/rust-hir.cc (IfLetExpr::as_string): (IfLetExprConseqElse::as_string): (IfLetExpr::accept_vis): (IfLetExprConseqElse::accept_vis): * hir/tree/rust-hir.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): * typecheck/rust-hir-type-check-expr.h: gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: * backend/rust-compile-expr.h: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: * checks/errors/borrowck/rust-bir-builder-struct.h: * checks/errors/borrowck/rust-function-collector.h: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): * checks/errors/privacy/rust-privacy-reporter.h: * checks/errors/rust-const-checker.cc (ConstChecker::visit): * checks/errors/rust-const-checker.h: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): * checks/errors/rust-unsafe-checker.h: * hir/rust-ast-lower-block.h: * hir/rust-ast-lower.cc (do_if_let_desugaring): (ASTLoweringIfLetBlock::visit): * hir/rust-ast-lower.h (struct_field_name_exists): (translate_visibility): * hir/rust-hir-dump.cc (Dump::do_ifletexpr): (Dump::visit): * hir/rust-hir-dump.h: * hir/tree/rust-hir-expr.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-full-decls.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-visitor.h: * hir/tree/rust-hir.cc (IfLetExpr::as_string): (IfLetExprConseqElse::as_string): (IfLetExpr::accept_vis): (IfLetExprConseqElse::accept_vis): * hir/tree/rust-hir.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): * typecheck/rust-hir-type-check-expr.h: gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: * backend/rust-compile-expr.h: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: * checks/errors/borrowck/rust-bir-builder-struct.h: * checks/errors/borrowck/rust-function-collector.h: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): * checks/errors/privacy/rust-privacy-reporter.h: * checks/errors/rust-const-checker.cc (ConstChecker::visit): * checks/errors/rust-const-checker.h: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): * checks/errors/rust-unsafe-checker.h: * hir/rust-ast-lower-block.h: * hir/rust-ast-lower.cc (do_if_let_desugaring): (ASTLoweringIfLetBlock::visit): * hir/rust-ast-lower.h (struct_field_name_exists): (translate_visibility): * hir/rust-hir-dump.cc (Dump::do_ifletexpr): (Dump::visit): * hir/rust-hir-dump.h: * hir/tree/rust-hir-expr.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-full-decls.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-visitor.h: * hir/tree/rust-hir.cc (IfLetExpr::as_string): (IfLetExprConseqElse::as_string): (IfLetExpr::accept_vis): (IfLetExprConseqElse::accept_vis): * hir/tree/rust-hir.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): * typecheck/rust-hir-type-check-expr.h: gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: * backend/rust-compile-expr.h: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: * checks/errors/borrowck/rust-bir-builder-struct.h: * checks/errors/borrowck/rust-function-collector.h: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): * checks/errors/privacy/rust-privacy-reporter.h: * checks/errors/rust-const-checker.cc (ConstChecker::visit): * checks/errors/rust-const-checker.h: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): * checks/errors/rust-unsafe-checker.h: * hir/rust-ast-lower-block.h: * hir/rust-ast-lower.cc (do_if_let_desugaring): (ASTLoweringIfLetBlock::visit): * hir/rust-ast-lower.h (struct_field_name_exists): (translate_visibility): * hir/rust-hir-dump.cc (Dump::do_ifletexpr): (Dump::visit): * hir/rust-hir-dump.h: * hir/tree/rust-hir-expr.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-full-decls.h (class IfLetExpr): (class IfLetExprConseqElse): * hir/tree/rust-hir-visitor.h: * hir/tree/rust-hir.cc (IfLetExpr::as_string): (IfLetExprConseqElse::as_string): (IfLetExpr::accept_vis): (IfLetExprConseqElse::accept_vis): * hir/tree/rust-hir.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): * typecheck/rust-hir-type-check-expr.h: gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. * rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. * rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes #1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. * rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
related to #1170
Compilation fails for the
IfLet
expression.Code
Meta
Error output
The text was updated successfully, but these errors were encountered: