aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authormxlol233 <mxlol233@outlook.com>2023-01-04 21:21:59 +0800
committerArthur Cohen <arthur.cohen@embecosm.com>2023-04-06 10:47:16 +0200
commitef792b9658d6bde0001d7340b10d2d3193ecbc09 (patch)
tree54a19bae05051089fda9bd9c21ded8c15412453e /gcc
parentd9e05700ac3085f29e95d53b3ec59c22adbc7c71 (diff)
downloadgcc-ef792b9658d6bde0001d7340b10d2d3193ecbc09.zip
gcc-ef792b9658d6bde0001d7340b10d2d3193ecbc09.tar.gz
gcc-ef792b9658d6bde0001d7340b10d2d3193ecbc09.tar.bz2
gccrs: rust: add bound parsing in parse_generic_arg.
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h17
-rw-r--r--gcc/testsuite/rust/compile/bounds.rs10
2 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index cbd40ef..959e033 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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
index 0000000..ecb10d8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/bounds.rs
@@ -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'" }
+}
+