diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-12-16 15:23:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 15:23:39 +0000 |
commit | a8a345642a2a150a35b68e2f19b90abf105700c5 (patch) | |
tree | cab130a5d112eac9d1490a98139831cfd8f3a717 /gcc/rust/hir | |
parent | e8d91e9e0825b4d1a4e46531142fdc0c83c761db (diff) | |
parent | 45edfc2b265cffab529d2cd70b37af559bd02c21 (diff) | |
download | gcc-a8a345642a2a150a35b68e2f19b90abf105700c5.zip gcc-a8a345642a2a150a35b68e2f19b90abf105700c5.tar.gz gcc-a8a345642a2a150a35b68e2f19b90abf105700c5.tar.bz2 |
Merge #839
839: Add typechecking for match-expr r=philberty a=philberty
This adds in the type checking pass for the match expression including static
analysis for errors such as:
- error[E0532]: expected tuple struct or tuple variant, found struct variant `Foo::D`
- error[E0027]: pattern does not mention fields `x`, `y`
- error[E0026]: variant `Foo::D` does not have a field named `b`
- error[E0532]: expected tuple struct or tuple variant, found struct variant `Foo::D`
Addresses #190
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 0e5d97b..e50e210 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -3614,15 +3614,9 @@ struct MatchArm { private: AST::AttrVec outer_attrs; - // MatchArmPatterns patterns; - std::vector<std::unique_ptr<Pattern> > match_arm_patterns; // inlined - - // bool has_match_arm_guard; - // inlined from MatchArmGuard + std::vector<std::unique_ptr<Pattern> > match_arm_patterns; std::unique_ptr<Expr> guard_expr; - // TODO: should this store location data? - public: // Returns whether the MatchArm has a match arm guard expression bool has_match_arm_guard () const { return guard_expr != nullptr; } @@ -3679,6 +3673,11 @@ public: } std::string as_string () const; + + std::vector<std::unique_ptr<Pattern> > &get_patterns () + { + return match_arm_patterns; + } }; /* A "match case" - a correlated match arm and resulting expression. Not @@ -3718,6 +3717,9 @@ public: std::string as_string () const; Analysis::NodeMapping get_mappings () const { return mappings; } + + MatchArm &get_arm () { return arm; } + std::unique_ptr<Expr> &get_expr () { return expr; } }; #if 0 @@ -3868,6 +3870,15 @@ public: void accept_vis (HIRVisitor &vis) override; + std::unique_ptr<Expr> &get_scrutinee_expr () + { + rust_assert (branch_value != nullptr); + return branch_value; + } + + const std::vector<MatchCase> &get_match_cases () const { return match_arms; } + std::vector<MatchCase> &get_match_cases () { return match_arms; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ |