From patchwork Wed Apr 5 14:03:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp352378vqo; Wed, 5 Apr 2023 07:31:41 -0700 (PDT) X-Google-Smtp-Source: AKy350bqAWc/1knlrTHPxz52Kn9BiGY8ty9RYTGhcAsqSCMYzc9D53gOXLiP0649Fk4X4mOGUxJZ X-Received: by 2002:a05:6402:4c6:b0:502:9289:51e5 with SMTP id n6-20020a05640204c600b00502928951e5mr2032238edw.14.1680705101520; Wed, 05 Apr 2023 07:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705101; cv=none; d=google.com; s=arc-20160816; b=OrAsavtz0q83vn+gkAprxS0Vrc4bJIiEytihe4T2lHUbJHYKL5m29bcC5QE8y/6a4O WCpKkKA6Lh4zcUo/q5W0Po28n7W/IFIib4FNiXooWwJG9H5Momi4S8NVfahQ6vglN1YJ J/dj10PAhb8du4+8rjoVYbF6MFIKLlHOPtmTNpooSRTgEt2GhmBK8s1qsc/tD5glKwaY hdbBL0Wys5MexDaNaZEJicHUaGqb6oGV+5XRwrgrs+si/YxR/VbB/yqLJ92xGVLe018/ QcZAZNCEq1e0WmeKLW+adVJeslb1G6enBT7OpJc/PW6w3i4FaFUPH9i7wHyw5/nAiMo0 Vf/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=hvpaBISMzloHIOsTv1Nshg0m+HtDHpNlmDgJymlIikhCLdg+OGm3PDE5moEyw7I+Ds kvWb279+FK2cSaBtlBucaW+5hNSGMLKf2f6kWbTkLlP/zKtsBMhIeKpLdWQ2zruQmV2N wqydC1SAdAa+45UhVIKFJ0Lg+5CgYaHefBtp1pEaId+kUOOVeVB4LNK7h7YcDlvmD6Ae gC2ViDGUKbA+McTOepjyErnR0GRG6TOPX+vgj9rZxqOH9ktaza+hMZSbaXPfSsT4R4ED LI9gv0uLmXTsp3YdsmYsrPUBJs70f315ii9M/YtqWzeY/UHdT6rFYLdzWDgok20T+mGe tgnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Omdt7fj5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s5-20020aa7c545000000b004fe92442646si2157966edr.497.2023.04.05.07.31.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:31:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Omdt7fj5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 176CE3A47F76 for ; Wed, 5 Apr 2023 14:12:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 26E4E3858D20 for ; Wed, 5 Apr 2023 14:05:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26E4E3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42b.google.com with SMTP id i9so36346031wrp.3 for ; Wed, 05 Apr 2023 07:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703550; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=Omdt7fj5H0Z4ufcWuJJ46RQ8mx7euHOV2oqAGibMiurFGIlgrss37uzIb25mXeOxzn Q07Was52ACHLpsu6WrvU5QLr0W0w+L1sWY1DAGsELOxCi/Whm6unHengOIH/sIaV/gNZ C2ymcqwoNFxG7l2Kg1UunTKVuRGy2Z+ipnuvbQpOJZ6NbZnXHw0ck7TaKH5RyeyuqEcB YurpWUFuily3CINnEa1765UlR6gJvyy6Zr5Jzs72TjKFTE85QJlZa58oax3aPp0uEdRg 2w1RaDIDxcWJHYGnPzs2/LdHEu24wz5UoZCLXxGEFQmRgtpjVA4UY5gAbk1+3NAwwdR6 EZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703550; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LmpZNkxa1VjPJMe703i8g9eO/nZAZKuBclfGJvZQZxY=; b=IFrzb9fGxhvTdEoQ2zbfxKM1XRtEKINO7P3ZLTi5w5bpwwi4c1E8/gI90rpVOVkDmu eIaNVbIfESUQw5TNLtHEbJSg33b3zm4mQ5ROWWmQVuIT4WlJDZ1cjb49lS4M/TP/rBgw 4i/8F0YH3wp0VI3SAeEFkWVHOGPfLnqLBLzagAdBVIM7r0jsOuA9EmpaVKak9cESil3A NkV8rO7aL0Xod28NMiwOm4nZaIgcXLJkzeXe79+qKnQonGlWV9YV1pRsQsgK2LNqtUuf IdO75XczGu0K5xhi6llEX4BPYw/9QeuvutX4SP9F2CDIyaojo6P4/Ad47/ZgtHTrgiGN ZcIw== X-Gm-Message-State: AAQBX9dYPu7/U4oOxyCxqS0brDKM6W42IsaXn5fUCXPXBuVUt276kocE PsNI0YQNrz3bHRVVtYwHS9ixHodaXDMJaxnP/g== X-Received: by 2002:a5d:4388:0:b0:2c7:1c08:121c with SMTP id i8-20020a5d4388000000b002c71c08121cmr4566987wrq.61.1680703550074; Wed, 05 Apr 2023 07:05:50 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:49 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 31/88] gccrs: parser: Improve parsing of complex generic arguments Date: Wed, 5 Apr 2023 16:03:15 +0200 Message-Id: <20230405140411.3016563-32-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762347032787030758?= X-GMAIL-MSGID: =?utf-8?q?1762347032787030758?= From: Arthur Cohen The parser was missing code for handling complex type arguments such as type paths or nested generics. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type paths and nested generics properly. gcc/testsuite/ChangeLog: * rust/compile/parse_complex_generic_application.rs: New test. * rust/compile/parse_complex_generic_application2.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 4 +++- .../parse_complex_generic_application.rs | 17 +++++++++++++++++ .../parse_complex_generic_application2.rs | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/parse_complex_generic_application.rs create mode 100644 gcc/testsuite/rust/compile/parse_complex_generic_application2.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 23b033fb26e..3610790815c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6309,7 +6309,9 @@ Parser::parse_generic_arg () // could either have a valid type or a macro (FIXME: anything else?). So // we need one bit of lookahead to differentiate if this is really auto next_tok = lexer.peek_token (1); - if (next_tok->get_id () == EXCLAM) + if (next_tok->get_id () == LEFT_ANGLE + || next_tok->get_id () == SCOPE_RESOLUTION + || next_tok->get_id () == EXCLAM) { auto type = parse_type (); if (type) diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs new file mode 100644 index 00000000000..d5c7bf488b7 --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs @@ -0,0 +1,17 @@ +pub enum Either { + Left(T), + Right(E), +} + +pub mod err { + pub struct Error; + pub struct ErrorWrap(T); +} + +pub fn foo_err() -> Either<(), err::Error> { + Either::Left(()) +} + +pub fn foo_err_wrap() -> Either<(), err::ErrorWrap> { + Either::Left(()) +} diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs new file mode 100644 index 00000000000..0361931c50c --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs @@ -0,0 +1,10 @@ +pub enum Either { + Left(L), + Right(R), +} + +pub struct Wrap(T); + +pub fn foo_wrap() -> Either<(), Wrap> { + Either::Left(()) +}