From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 690713858C5F; Wed, 22 Feb 2023 07:22:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 690713858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677050566; bh=ND5k8dWYXm50g3CUeK6Kd1y+yqH3KCpnZLDotyCnapw=; h=From:To:Subject:Date:From; b=TTwmEg/QgTht/pVgQZA6uP4M0gFgcz+FZS05rX043eQIJlC4M7aKmihwvqN8ps01v CouZbUqK+dLGPko105+4QYuunx6iMc+9WSqGFi7GwCsLnd2/fvmd5Oj/wM7qkfG/Kk 3l1IecTTpljnNoKp9XPlG6a7QwWXLVA8hHSkLlqc= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] parser: Allow `LEFT_SHIFT` to start `parse_type` X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 57b64a64261ed1d1774af61a1e36eeac604abcde X-Git-Newrev: 87e7c9dedacd4d12636e6c626aab14bcecf686f2 Message-Id: <20230222072246.690713858C5F@sourceware.org> Date: Wed, 22 Feb 2023 07:22:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:87e7c9dedacd4d12636e6c626aab14bcecf686f2 commit 87e7c9dedacd4d12636e6c626aab14bcecf686f2 Author: Arthur Cohen Date: Fri Feb 17 14:24:07 2023 +0100 parser: Allow `LEFT_SHIFT` to start `parse_type` Similarly to the last commit, we need to allow `LEFT_SHIFT` tokens to start a qualified path type and split them into two `LEFT_ANGLE` tokens. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_type): Allow LEFT_SHIFT to start a type and then split it in `parse_qualified_path_type` gcc/testsuite/ChangeLog: * rust/compile/parse_associated_type_as_generic_arg3.rs: New test. Diff: --- gcc/rust/parse/rust-parse-impl.h | 15 ++++-- .../parse_associated_type_as_generic_arg3.rs | 59 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3bf26bc6fdc..2cb5e3e7849 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6842,11 +6842,13 @@ Parser::parse_qualified_path_type ( if (locus == Linemap::unknown_location ()) { locus = lexer.peek_token ()->get_locus (); + + if (lexer.peek_token ()->get_id () == LEFT_SHIFT) + lexer.split_current_token (LEFT_ANGLE, LEFT_ANGLE); + + // skip after somewhere? if (!skip_token (LEFT_ANGLE)) - { - // skip after somewhere? - return AST::QualifiedPathType::create_error (); - } + return AST::QualifiedPathType::create_error (); } // parse type (required) @@ -9218,6 +9220,7 @@ Parser::parse_type (bool save_errors) case LEFT_SQUARE: // slice type or array type - requires further disambiguation return parse_slice_or_array_type (); + case LEFT_SHIFT: case LEFT_ANGLE: { // qualified path in type AST::QualifiedPathInType path = parse_qualified_path_in_type (); @@ -10084,6 +10087,7 @@ Parser::parse_type_no_bounds () case LEFT_SQUARE: // slice type or array type - requires further disambiguation return parse_slice_or_array_type (); + case LEFT_SHIFT: case LEFT_ANGLE: { // qualified path in type AST::QualifiedPathInType path = parse_qualified_path_in_type (); @@ -10597,6 +10601,7 @@ Parser::parse_range_pattern_bound () return std::unique_ptr ( new AST::RangePatternBoundPath (std::move (path))); } + case LEFT_SHIFT: case LEFT_ANGLE: { // qualified path in expression AST::QualifiedPathInExpression path @@ -10727,6 +10732,7 @@ Parser::parse_pattern_no_alt () case LEFT_SQUARE: // slice pattern return parse_slice_pattern (); + case LEFT_SHIFT: case LEFT_ANGLE: { // qualified path in expression or qualified range pattern bound AST::QualifiedPathInExpression path @@ -12760,6 +12766,7 @@ Parser::null_denotation (const_TokenPtr tok, * tokens and whatever. */ /* FIXME: could also be path expression (and hence macro expression, * struct/enum expr) */ + case LEFT_SHIFT: case LEFT_ANGLE: { // qualified path // HACK: add outer attrs to path diff --git a/gcc/testsuite/rust/compile/parse_associated_type_as_generic_arg3.rs b/gcc/testsuite/rust/compile/parse_associated_type_as_generic_arg3.rs new file mode 100644 index 00000000000..f1cc9e7dcde --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_associated_type_as_generic_arg3.rs @@ -0,0 +1,59 @@ +// { dg-additional-options "-fsyntax-only" } + +trait Bar { + type B; + + fn bar(); +} + +trait Foo { + type A; + + fn foo(); +} + +trait Toto { + type C; + + fn toto(); +} + +trait Tata { + type D; + fn tata(); +} + +impl Toto for u32 { + type C = f32; + + fn toto() {} +} + +impl Tata for f32 { + type D = u32; + + fn tata() {} +} + +struct S; + +impl Bar for i32 { + type B = u32; + + fn bar() {} +} + +impl Foo for S { + type A = i32; + + fn foo() {} +} + +enum Maybe { + Something(T), + Nothing, +} + +fn foo() -> Maybe<<<<::A as Bar>::B as Toto>::C as Tata>::D> { + Maybe::Something(15) +}