From patchwork Tue Jan 30 12:06:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=ZQGpRKhF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TPPSh2Vxcz23dQ for ; Tue, 30 Jan 2024 23:22:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC834385802A for ; Tue, 30 Jan 2024 12:22:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 1FA843858025 for ; Tue, 30 Jan 2024 12:11:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FA843858025 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1FA843858025 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; cv=none; b=wzmSLQ5FoiMps2+PzTUnY3iEK3jpCZ1K92q3+Iq3vB/tmnE7VILbKaJJGT8QhoLCvbHIsf01Vmb5FK54n1KjJoKo9M4TNEoVbAKDXRVrM0TwxuwFBKR08AE0yhOjv6PC7tuRBRayzKNcc764llZKCK/9bHIzOBxHajk+ERWHrck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; c=relaxed/simple; bh=qySKkAy2xXtzOvTSeqNMvV8Q6r96ejExksDQ5XUJIUk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mdIELmDFnBc3JWKK2lE7cMRE2qK/fNNnyZY0Eo22LtayCTgawMNnsoQ1WmHleVxB/KccLSpFxg9c8sFacpwAZBadiBHCgTSBCU1IAHzpg7bTqmOfKWeJ4vbk0+pAXS934cakO63yEdG4vmawoeNANaos+wkTNu/97P8alnDJLhs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-337d05b8942so3297309f8f.3 for ; Tue, 30 Jan 2024 04:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616664; x=1707221464; darn=gcc.gnu.org; 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=hoWOQVO7lwBw2MZmFyW3YYka2iOC8wpdlZetPxAgbjo=; b=ZQGpRKhFE+EzbxZuX+F/eXU6x8CelDoE9cVXr0gVb08xbQaAsMmtU+PjLPZ/zU8ZE4 BiZh6SQ00o0t18c9GxtgUqdxrQR31qAP154l06HHRMUl36khGG/kk05iSRNAqucreTL7 DuQ9fGza1szIgH6nOwQgXyFRwEV5GYK8atsDZUg4DGRvWLvuqmU+YoiH4UcNfsukSFtw CaByUG7bIeanmfbZw2JQJs0ofKTpU9GvdGu3ALpCEYS9FWHNf+jpDd2fQpxtcHWgZnWh tYkb0X+2vyO10LfTG9iOd7zJL70qT5O4Kx9EtiWNLUG783qVpsS2caIplABI80GuEP+H C5mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616664; x=1707221464; 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=hoWOQVO7lwBw2MZmFyW3YYka2iOC8wpdlZetPxAgbjo=; b=Vp/jvY+SdmSbpCa2EUiopaY5U2hIuS8ub6u4YPKr7D4myRa32BgzbJjHyqIPwcEZcH TD3Qsc9VljeLk+zr+G4RTaCm0oKRd5TITUAe26yG5MvOupTeoAxNd840+7XcLhVc+vt+ ZBGPjI6aDaCNblJ/BLgmJLLw+4uuexMwF1wWwz2iPmXzW23KSbCvgIXDveNHGWON2fAo kGzeWu2jpT8MHQGdmghyIt9lUZpfv0Bq6QWEzusH1/SVIACpFfei4gYPgkFTKfXWxA9X t80RxSfqn4op7PCVBFx/ADhU2DhlS9zwcb4APObYrMJ+KsV9e42OeMqpIDIUg5eMASTt 6d3w== X-Gm-Message-State: AOJu0Yzoz2FmsAObTPbLUjbbs9fTUA5bnmw5ORixtvBrvZnHiIoctK0l 183LZEOZlrDGLxk/+JOjinsOEPWBwP2tzivJipqyGjfJex3emGPdyc2uun1/uqnwZ9BtSt0wWPE vMw== X-Google-Smtp-Source: AGHT+IHwrg/5h9iUs6DUNiWnEvAY1S2BPO9CnQFxRQlkxRjfZzoiyPEP0vdFyY37VQCwHkMSN5ZjSw== X-Received: by 2002:a5d:5982:0:b0:33a:f51c:8a8a with SMTP id n2-20020a5d5982000000b0033af51c8a8amr3303416wri.45.1706616664742; Tue, 30 Jan 2024 04:11:04 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:04 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 020/101] gccrs: Add check for associated items on auto traits Date: Tue, 30 Jan 2024 13:06:36 +0100 Message-ID: <20240130121026.807464-23-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 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, T_SCC_BODY_TEXT_LINE 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.30 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+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Pierre-Emmanuel Patry Reject rust code with associated items on auto traits. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto trait associated item check in AST validation pass. * parse/rust-parse-impl.h: Remove old error emission done during parsing pass. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_invalid.rs: Update old test with updated error message. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 7 +++++++ gcc/rust/parse/rust-parse-impl.h | 12 ------------ gcc/testsuite/rust/compile/auto_trait_invalid.rs | 5 +++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index aeae6035db8..673290959f4 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -109,6 +109,13 @@ ASTValidation::visit (AST::Trait &trait) rust_error_at (trait.get_type_param_bounds ()[0]->get_locus (), ErrorCode::E0568, "auto traits cannot have super traits"); + if (trait.has_trait_items ()) + { + rust_error_at (trait.get_identifier ().get_locus (), ErrorCode::E0380, + "auto traits cannot have methods or associated items"); + for (const auto &item : trait.get_trait_items ()) + Error::Hint (item->get_locus (), "remove this item").emit (); + } } AST::ContextualASTVisitor::visit (trait); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index de17412c3b6..45c72e495c2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4989,18 +4989,6 @@ Parser::parse_trait (AST::Visibility vis, return nullptr; } - if (is_auto_trait && !trait_items.empty ()) - { - add_error (Error (locus, ErrorCode::E0380, - "auto traits cannot have associated items")); - - // FIXME: unsure if this should be done at parsing time or not - for (const auto &item : trait_items) - add_error (Error::Hint (item->get_locus (), "remove this item")); - - return nullptr; - } - trait_items.shrink_to_fit (); return std::unique_ptr ( new AST::Trait (std::move (ident), is_unsafe, is_auto_trait, diff --git a/gcc/testsuite/rust/compile/auto_trait_invalid.rs b/gcc/testsuite/rust/compile/auto_trait_invalid.rs index 66e45531f5d..3be2acbb53b 100644 --- a/gcc/testsuite/rust/compile/auto_trait_invalid.rs +++ b/gcc/testsuite/rust/compile/auto_trait_invalid.rs @@ -2,7 +2,9 @@ #![feature(optin_builtin_traits)] -unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated items" } +auto trait Invalid { + // { dg-error "auto traits cannot have methods or associated items" "" { target *-*-* } .-1 } + fn foo(); // { dg-message "remove this item" } fn bar() {} // { dg-message "remove this item" } @@ -13,4 +15,3 @@ unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated it const BAR: i32 = 15; // { dg-message "remove this item" } } -// { dg-error "failed to parse item in crate" "" {target *-*-* } .+1 }