]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust: add bound parsing in parse_generic_arg.
authormxlol233 <mxlol233@outlook.com>
Wed, 4 Jan 2023 13:21:59 +0000 (21:21 +0800)
committermxlol233 <mxlol233@outlook.com>
Wed, 4 Jan 2023 14:18:18 +0000 (22:18 +0800)
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 864fb86ce0625c0c0b299ef46a9e08cc85717efb..86124ee658e6b22e31ab2c2b9de9050db3ba6302 100644 (file)
@@ -6189,6 +6189,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'" }
+}
+