]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
parser: Fix handling of multiple left angles in null denotation
authorgoar5670 <mahadelr19@gmail.com>
Sat, 4 Mar 2023 19:13:18 +0000 (22:13 +0300)
committerPhilip Herron <philip.herron@embecosm.com>
Mon, 6 Mar 2023 13:25:08 +0000 (13:25 +0000)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr):
split LEFT_SHIFT before null_denotation.

gcc/testsuite/ChangeLog:

* rust/compile/complex_qualified_path_in_expr.rs : New test.

Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/complex_qualified_path_in_expr.rs [new file with mode: 0644]

index 9b2bea73c998da7d72e09e8004acf4dffdf13749..79dd4e2423cbe0842440862655b174cf9e0ee1b1 100644 (file)
@@ -12650,6 +12650,13 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
          || id == RIGHT_SQUARE)
        return nullptr;
     }
+
+  if (current_token->get_id () == LEFT_SHIFT)
+    {
+      lexer.split_current_token (LEFT_ANGLE, LEFT_ANGLE);
+      current_token = lexer.peek_token ();
+    }
+
   lexer.skip_token ();
 
   // parse null denotation (unary part of expression)
diff --git a/gcc/testsuite/rust/compile/complex_qualified_path_in_expr.rs b/gcc/testsuite/rust/compile/complex_qualified_path_in_expr.rs
new file mode 100644 (file)
index 0000000..6244a6b
--- /dev/null
@@ -0,0 +1,34 @@
+struct S; // { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+impl S {
+  fn f() -> i32 { return 0; }
+  // { dg-warning "associated function is never used" "" { target *-*-* } .-1 }
+}
+
+trait T1 {
+  type A;
+  fn f() -> i32 { return 0; }
+}
+
+impl T1 for S {
+  type A = S;
+}
+
+trait T2 {
+  type B;
+  fn f() -> i32 { return 0; }
+}
+
+impl T2 for S {
+  type B = S;
+}
+
+trait T3 {
+  fn f() -> i32 { return 0; }
+}
+
+impl T3 for S {}
+
+fn main() {
+  let _ = <<S as T1>::A as T2>::f();
+  let _ = <<<S as T1>::A as T2>::B as T3>::f();
+}