diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-06 18:18:42 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-08 11:36:54 +0000 |
commit | 4e0189ed288223f8b376eedd286f5bdff5b35698 (patch) | |
tree | 89ab8d6db72bc19028d9ecb3a1946e8c0aa01ebd /gcc/rust/ast/rust-expr.h | |
parent | 290fc4f416c94a86aa5e3d22b785890a12686972 (diff) | |
download | gcc-4e0189ed288223f8b376eedd286f5bdff5b35698.zip gcc-4e0189ed288223f8b376eedd286f5bdff5b35698.tar.gz gcc-4e0189ed288223f8b376eedd286f5bdff5b35698.tar.bz2 |
Implicit Returns support.
For implict returns we must consider cases with a block having multiple
returns:
HIR::BlockExpr Stmts {
...
return x
}
HIR::BlockExpr final_expression {
x + 1
}
Although the code above is bad this is valid rust code and the rust
compiler correctly identifies the final_expression as unreachable.
This dead code eliminiation is done as part of AST to HIR lowering.
Type resolution examines all blocks to identifiy if they terminate
a function with a return/final expression it must correspond accordngly.
If the block is the final block the resulting termination of the block
must match the return type of the function, else the block must conform
to unit type.
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 8baf7b7..2dbaec8 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -2838,6 +2838,8 @@ public: } } + size_t num_statements () const { return statements.size (); } + // TODO: this mutable getter seems really dodgy. Think up better way. const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; } std::vector<Attribute> &get_inner_attrs () { return inner_attrs; } |