Skip to content
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

Desugar IfLet* expr to match #3064

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Desugar IfLet* expr to match #3064

wants to merge 3 commits into from

Commits on Sep 18, 2024

  1. rust: Desugar IfLet* into MatchExpr

    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>
    dkm committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    7f143a0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    59810ca View commit details
    Browse the repository at this point in the history
  3. ci: test getting artifacts

    dkm committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    67028a9 View commit details
    Browse the repository at this point in the history