From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 D897F3858437 for ; Tue, 30 Jan 2024 12:11:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D897F3858437 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 D897F3858437 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-33929364bdaso2692545f8f.2 for ; Tue, 30 Jan 2024 04:11:05 -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=cHaJe+yu2quXk/M4zziV/k1t5Kz3GfkBE5tx1pFASgzkgReG7/vXbeTkNfu/L9Zia9 VOl4Q1LCVLHWo8M5nzznUoZcA2QK4pr+bBwiXQcjEF/Fgua8PKU0m835yt7pAKKHlazc im4iB0mVEcM2jYUD1CPWiQg7HGloSFPiyutLcWKD3aQAVw6N/KFiT+cNAJkogMVGXeCY tO5BpCNpIR/gvHQV0cLM3+nZTSJ7OILmayHj3nQ6r0+LLF07cwaqd4dxpAdbG+Wuu2GK yyzt3DmnWWePv3YdJQDeEgK+Vwt9mQu2ZG+gomzGFOicxIEjOgxBK3ocMyGRzHPmOHGV q4Ug== X-Gm-Message-State: AOJu0YzwZ/fx3N9f1V8/UpofOzUJ0rfvBygQiICFkwDljMadX5QDbWIu UvWcTZGgY8InSIqkVzrj6ixWEMacIEYXX2T8I6vAIG9cVMv1xHde8bH6ev4byA== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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 } -- 2.42.1