From patchwork Wed Apr 5 14:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp347695vqo; Wed, 5 Apr 2023 07:25:00 -0700 (PDT) X-Google-Smtp-Source: AKy350YkIXobAuVa+8u3zODbgSo3tbfATiFGPYXV/SshQaX04qKQb6o86FvAjqOOsO1RC78Co/8E X-Received: by 2002:a17:906:11c5:b0:878:7a0e:5730 with SMTP id o5-20020a17090611c500b008787a0e5730mr3152163eja.56.1680704700736; Wed, 05 Apr 2023 07:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704700; cv=none; d=google.com; s=arc-20160816; b=TrRM9eyqEf/WvMxelUhlEHoBSXV0JFbKNMQoq3EHzCVS9rztcSrEpt7+qYbw81JnW9 8iiNilAlrw9EEE7LLEzcq2opEs1EE9YbEe57BftGQyrVRN8xROcJ+BlMa1JD5u+6Xf6x 5NY+8801zXXmz+9YZ/W2z2aJw4cxLEndezoQjZ1LN8QFcEs3O/m8d8ixe02ljBmSKSD0 ESzvn6d09E88LR42psn0nDmqOQA0acyBMxY8x7r3egnKpwkMBAUw8HcF/+SlxeFKyFai voE1OryjoWc8dzcygMUW+1TqRknyyideN5qqbZE9ShkGkSvlOJKkd6NXgsV1VhKikIDY 2lcg== 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=ksVXP5DhtlfuELVdgKX3CDj/cwEn4Jp/lT+jrZ5kka/NbEr5ulfk+Ns8BFzUC3m6V9 QTnJrrO5bd6Jz9qIom4TYd/QUd4b2J94Hc9sXci5QIQK0lD4QqllKcltiXMB9KJeOlmA 7hb8sNBwJF+dej2W5hnpxvWX2UbLE1QouwaI9kVzq5s8gHfW6mnX6JyDoTz5MAekgn4d 1SnLd0niCpoxAA3OUwG+qUPKU145i+g/SDBCRXLs43iL3OGF5IGQGKXi88wy2DFolZzQ 0gdZE5UXiyzxJfaXatOvxoGy6sl00sMiB+e069/BK47DKr3uo3HX2ic2OYu2gzJhZ8lo fGyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Rkp2472d; 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 d3-20020a1709067f0300b00932e5d0cc46si2095975ejr.930.2023.04.05.07.25.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:25:00 -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=Rkp2472d; 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 97A4038D9077 for ; Wed, 5 Apr 2023 14:11:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 0C680385382B for ; Wed, 5 Apr 2023 14:05:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C680385382B 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-wm1-x32c.google.com with SMTP id s13so20939263wmr.4 for ; Wed, 05 Apr 2023 07:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703542; 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=Rkp2472dfczn+QVixUp4TMN3iOyOoHsOVE7N9u0vKeN9Y3MqnSCc1iGKspLyux1MYQ Ifl5IyH90qxsrZ4bUlXYoc0oR2nRLTVGTbNmO6V0yiAIbhujYEF52SS4EE/9c5rex75+ S4RRY1AjXHQvGfwSsX1rHSoEDLRcN/4j8uzx35USt8rBMBQYbsXudgdpyYjIlfxgrTQe l2DHPOlLhJgIR7Hwd6KALct7zp2bvLOhABoYw7FWaH0kJLT98e/JTOg2NBn4Mh6O0w9f JHZgl1gyBsr+5xu2+V5EhtVi+HaTu/Sp9KAYXcu998sPExAuiAxlFnNj4OTx5JjANCd4 ukug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703542; 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=wFsC4ZrvK5kPI6X14aA2eunQSHlGOe6V20FjAJ0hMdc=; b=AjxqOojTihioJRJEpPxWxI0vhtMeppe/HyO0M/LmxRpMgWZyXvR+nljKoOHQ8NLZsa p5aOhE0TSC1+Fp2PHH97pX/4scPHS9foxpGrkFkbo/y/JDeK8bl/n8KR4vrqPdjkOwbu ggECOALLVDLZwWLCkZAvvYsIbJxdjRiQ3aObYUF3INeMAMzhk1UmbavRuXP8gLITntaM N+zTM1XJ9kAtUk2TQ/KJ9FnINInLlhdG3sH6GFCGpw1wtXtPaqm7t7XHSs0PXE6iHxeS DDazRnHhhpRue3s8U12Czl6kZAEowWW6DbzEq1pN/BEpVdwdszSj88VDVkv30Ox/XWxX HWzQ== X-Gm-Message-State: AAQBX9fhCGCVTb/qO/XsW8Mp1EtLuUCcBvldvz0ABjKYJGp8pC04DReo U9AvLY7NPYE6wZHlBYRwrWmfAI9tkLw+VVSi5A== X-Received: by 2002:a1c:f013:0:b0:3ed:29d9:56ae with SMTP id a19-20020a1cf013000000b003ed29d956aemr4629588wmb.6.1680703542636; Wed, 05 Apr 2023 07:05:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:42 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Abdul Rafey Subject: [committed 21/88] gccrs: fixed compiler error message on wildcard pattern within expression Date: Wed, 5 Apr 2023 16:03:05 +0200 Message-Id: <20230405140411.3016563-22-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=unavailable 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?1762346612173691836?= X-GMAIL-MSGID: =?utf-8?q?1762346612173691836?= From: Abdul Rafey gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::null_denotation): Add proper error when seeing wildcard var on right side of assignment. gcc/testsuite/ChangeLog: * rust/compile/issue-867.rs: New test. Signed-off-by: Abdul Rafey --- gcc/rust/parse/rust-parse-impl.h | 6 ++++++ gcc/testsuite/rust/compile/issue-867.rs | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-867.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index d71bafded63..af749ca9200 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -13021,6 +13021,12 @@ Parser::null_denotation (const_TokenPtr tok, case UNSAFE: return parse_unsafe_block_expr (std::move (outer_attrs), tok->get_locus ()); + case UNDERSCORE: + add_error ( + Error (tok->get_locus (), + "use of %qs is not allowed on the right-side of an assignment", + tok->get_token_description ())); + return nullptr; default: if (!restrictions.expr_can_be_null) add_error (Error (tok->get_locus (), diff --git a/gcc/testsuite/rust/compile/issue-867.rs b/gcc/testsuite/rust/compile/issue-867.rs new file mode 100644 index 00000000000..8e120685c1a --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-867.rs @@ -0,0 +1,8 @@ +fn main() { + let _ = 42; + let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" } + // { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1 } + // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 } + // { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+2 } + // { dg-error {failed to parse item in crate} "" { target *-*-* } .+1 } +}