From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 369A9385B529; Thu, 12 Jan 2023 07:44:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 369A9385B529 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673509449; bh=rsokK0KgIRBXyfh/a92fS+JmrdN9PbQm+Kk08pVlk+M=; h=From:To:Subject:Date:From; b=wu9SZZGek7O+oLcfX8jTONMZFuU2e2fv/TGRWg6HEWAizts/gUiA1AcK9dyspmeYe 8z2yq13hhCMtAW/PhgVWiui55x5orxTvf8F2aaKG1/ZA4dYHflhllhPKvglmyh7H8P 2+7xg1ejkAHH0LXJODKQLMJ52npKA6b1MHXQKrH0= 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] rust: add bound parsing in parse_generic_arg. X-Act-Checkin: gcc X-Git-Author: mxlol233 X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 0152926ab36ba52153f3f457f6f3bb02bb274073 X-Git-Newrev: 2f36f38054279e66b1af55995e41dd14e56beb25 Message-Id: <20230112074409.369A9385B529@sourceware.org> Date: Thu, 12 Jan 2023 07:44:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2f36f38054279e66b1af55995e41dd14e56beb25 commit 2f36f38054279e66b1af55995e41dd14e56beb25 Author: mxlol233 Date: Wed Jan 4 21:21:59 2023 +0800 rust: add bound parsing in parse_generic_arg. Signed-off-by: Xiao Ma Diff: --- gcc/rust/parse/rust-parse-impl.h | 17 +++++++++++++++++ gcc/testsuite/rust/compile/bounds.rs | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 864fb86ce06..86124ee658e 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6189,6 +6189,23 @@ Parser::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> bounds + = parse_type_param_bounds (); + + auto type = std::unique_ptr ( + 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 00000000000..ecb10d81f65 --- /dev/null +++ b/gcc/testsuite/rust/compile/bounds.rs @@ -0,0 +1,10 @@ +trait Foo { + type Bar; +} + +trait Copy {} + + +fn c>() where F::Bar: Copy { // { dg-warning "function is never used: 'c'" } +} +