]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: rust: add bound parsing in parse_generic_arg.
authormxlol233 <mxlol233@outlook.com>
Wed, 4 Jan 2023 13:21:59 +0000 (21:21 +0800)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:16 +0000 (10:47 +0200)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/bounds.rs [new file with mode: 0644]

index cbd40efcc9bcb3b2cddcd7c1c9d244be4b6bbfb3..959e0338a1024f4eb02b3cf69365204a11c5e2f0 100644 (file)
@@ -6198,6 +6198,23 @@ Parser<ManagedTokenSource>::parse_generic_arg ()
            else
              return AST::GenericArg::create_error ();
          }
+       else if (next_tok->get_id () == COLON)
+         {
+           lexer.skip_token (); // skip ident
+           lexer.skip_token (); // skip colon
+
+           auto tok = lexer.peek_token ();
+           std::vector<std::unique_ptr<AST::TypeParamBound>> bounds
+             = parse_type_param_bounds ();
+
+           auto type = std::unique_ptr<AST::TraitObjectType> (
+             new AST::TraitObjectType (std::move (bounds), tok->get_locus (),
+                                       false));
+           if (type)
+             return AST::GenericArg::create_type (std::move (type));
+           else
+             return AST::GenericArg::create_error ();
+         }
        lexer.skip_token ();
        return AST::GenericArg::create_ambiguous (tok->get_str (),
                                                  tok->get_locus ());
diff --git a/gcc/testsuite/rust/compile/bounds.rs b/gcc/testsuite/rust/compile/bounds.rs
new file mode 100644 (file)
index 0000000..ecb10d8
--- /dev/null
@@ -0,0 +1,10 @@
+trait Foo {
+    type Bar;
+}
+
+trait Copy {}
+
+
+fn c<F: Foo<Bar: Foo>>() where F::Bar: Copy { // { dg-warning "function is never used: 'c'" }
+}
+