From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 8697C3858011; Tue, 16 Jan 2024 18:02:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8697C3858011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428133; bh=blUjlBEyErWn3ZbDKDAYLJGKdyjap5a/BAUxhYDrk0c=; h=From:To:Subject:Date:From; b=OjVfx9otnVAtxOLVNHQbRFOLd+FtVfSkELfPeuRL/GC/AovAy1pAfVZXuTFu+KwlG peg7IE72ZpAXH/0znStAc1W94dPtEwVT1MUbTeQCdXTYgGD+/nTOFCLVp5Q61w/fbd DYFqQTfY4BeOHtw/buSKRzNErqn4laMR1cbmM6cE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7830] gccrs: [E0323] Implemented associated const, expected another trait X-Act-Checkin: gcc X-Git-Author: Muhammad Mahad X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 973f4088efa74e3c181169b77c22358ae179d4d6 X-Git-Newrev: 5141707b5b5dcacde76dd0760f6604451f06ef85 Message-Id: <20240116180213.8697C3858011@sourceware.org> Date: Tue, 16 Jan 2024 18:02:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5141707b5b5dcacde76dd0760f6604451f06ef85 commit r14-7830-g5141707b5b5dcacde76dd0760f6604451f06ef85 Author: Muhammad Mahad Date: Tue Jul 18 18:55:32 2023 +0500 gccrs: [E0323] Implemented associated const, expected another trait Refactored Error message similiar to rustc. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): called error function. gcc/testsuite/ChangeLog: * rust/compile/non_member_const.rs: New test. Signed-off-by: Muhammad Mahad Diff: --- gcc/rust/typecheck/rust-hir-type-check-implitem.cc | 6 ++++-- gcc/testsuite/rust/compile/non_member_const.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc index b8a73a73111..189dd8797d1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc @@ -389,12 +389,14 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant) TraitItemReference::TraitItemType::CONST, &raw_trait_item); - // unknown trait item + // unknown trait item - https://doc.rust-lang.org/error_codes/E0323.html if (!found || raw_trait_item->is_error ()) { rich_location r (line_table, constant.get_locus ()); r.add_range (trait_reference.get_locus ()); - rust_error_at (r, "constant %<%s%> is not a member of trait %<%s%>", + rust_error_at (r, ErrorCode ("E0323"), + "item %qs is an associated const, which does not match " + "its trait %qs", constant.get_identifier ().as_string ().c_str (), trait_reference.get_name ().c_str ()); return; diff --git a/gcc/testsuite/rust/compile/non_member_const.rs b/gcc/testsuite/rust/compile/non_member_const.rs new file mode 100644 index 00000000000..b9740025266 --- /dev/null +++ b/gcc/testsuite/rust/compile/non_member_const.rs @@ -0,0 +1,15 @@ +// https://doc.rust-lang.org/error_codes/E0323.html +#![allow(unused)] +fn main() { +trait Foo { + type N; +} + +struct Bar; + +impl Foo for Bar { + const N : u32 = 0; // { dg-error "item .N. is an associated const, which does not match its trait .Foo." } + // error: item `N` is an associated const, which doesn't match its + // trait `` +} +} \ No newline at end of file