From: Jakub Dupak Date: Tue, 9 Jan 2024 14:45:12 +0000 (+0100) Subject: gccrs: AST: Fix for lifetime parsing X-Git-Tag: basepoints/gcc-15~1519 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37d4cf484618460e7db3d5a69c094510ae9396ce;p=thirdparty%2Fgcc.git gccrs: AST: Fix for lifetime parsing gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing (Parser::parse_where_clause_item): fix parsing (Parser::parse_type_bound_where_clause_item): fix parsing (Parser::parse_trait_bound): fix parsing * parse/rust-parse.h: fix parsing Signed-off-by: Jakub Dupak --- diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c14c75ce70dc..7ea7276dc949 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3756,6 +3756,10 @@ Parser::parse_where_clause () * so won't be here */ std::vector> where_clause_items; + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + /* HACK: where clauses end with a right curly or semicolon or equals in all * uses currently */ const_TokenPtr t = lexer.peek_token (); @@ -3763,7 +3767,7 @@ Parser::parse_where_clause () && t->get_id () != EQUAL) { std::unique_ptr where_clause_item - = parse_where_clause_item (); + = parse_where_clause_item (for_lifetimes); if (where_clause_item == nullptr) { @@ -3791,7 +3795,8 @@ Parser::parse_where_clause () * commas. */ template std::unique_ptr -Parser::parse_where_clause_item () +Parser::parse_where_clause_item ( + const std::vector &outer_for_lifetimes) { // shitty cheat way of determining lifetime or type bound - test for // lifetime @@ -3800,7 +3805,7 @@ Parser::parse_where_clause_item () if (t->get_id () == LIFETIME) return parse_lifetime_where_clause_item (); else - return parse_type_bound_where_clause_item (); + return parse_type_bound_where_clause_item (outer_for_lifetimes); } // Parses a lifetime where clause item. @@ -3834,12 +3839,10 @@ Parser::parse_lifetime_where_clause_item () // Parses a type bound where clause item. template std::unique_ptr -Parser::parse_type_bound_where_clause_item () +Parser::parse_type_bound_where_clause_item ( + const std::vector &outer_for_lifetimes) { - // parse for lifetimes, if it exists - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); + std::vector for_lifetimes = outer_for_lifetimes; std::unique_ptr type = parse_type (); if (type == nullptr) @@ -3853,6 +3856,13 @@ Parser::parse_type_bound_where_clause_item () return nullptr; } + if (lexer.peek_token ()->get_id () == FOR) + { + auto for_lifetimes_inner = parse_for_lifetimes (); + for_lifetimes.insert (for_lifetimes.end (), for_lifetimes_inner.begin (), + for_lifetimes_inner.end ()); + } + // parse type param bounds if they exist std::vector> type_param_bounds = parse_type_param_bounds (); @@ -4029,6 +4039,11 @@ Parser::parse_trait_bound () location_t locus = lexer.peek_token ()->get_locus (); + /* parse optional `for lifetimes`. */ + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + // handle trait bound being in parentheses if (lexer.peek_token ()->get_id () == LEFT_PAREN) { @@ -4043,12 +4058,6 @@ Parser::parse_trait_bound () lexer.skip_token (); } - /* parse for lifetimes, if it exists (although empty for lifetimes is ok to - * handle this) */ - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); - // handle TypePath AST::TypePath type_path = parse_type_path (); diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 3fc86206de7c..02f90217fc2c 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -288,11 +288,13 @@ private: std::unique_ptr parse_function_param (); std::unique_ptr parse_function_return_type (); AST::WhereClause parse_where_clause (); - std::unique_ptr parse_where_clause_item (); + std::unique_ptr parse_where_clause_item ( + const std::vector &global_for_lifetimes); std::unique_ptr parse_lifetime_where_clause_item (); std::unique_ptr - parse_type_bound_where_clause_item (); + parse_type_bound_where_clause_item ( + const std::vector &global_for_lifetimes); std::vector parse_for_lifetimes (); template std::vector>