From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 9E55E3857BA0; Tue, 16 Jan 2024 18:04:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E55E3857BA0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428293; bh=OmE2zZAksC6xQcXZ7LR2dRbHKBuKRNtRARwGx60ddm4=; h=From:To:Subject:Date:From; b=U4v7Lhe/kA7inGutsINw1u06w30jUBUqPgS+bhgZgAvvoY0yZ2JJYNzWO7ywFa3OQ zL9CkmiZ24WrTK6FWbNzzCKzlE9s6TvUgijMNhNQrc76oKkHxkyhU+RNJYoqRahWPx xu8IBW1zEbnOooE1Bi+lH9T/f2VCW5zZXpxszPok= 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-7861] gccrs: fix ICE when we have unimplemented/invalid trait items X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 4d630984512b6b79d9412378301ae777411685d4 X-Git-Newrev: 46a5df00ab59a9bb816f5865efb9196e31bc18c6 Message-Id: <20240116180453.9E55E3857BA0@sourceware.org> Date: Tue, 16 Jan 2024 18:04:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:46a5df00ab59a9bb816f5865efb9196e31bc18c6 commit r14-7861-g46a5df00ab59a9bb816f5865efb9196e31bc18c6 Author: Philip Herron Date: Sat Jul 29 17:33:47 2023 +0100 gccrs: fix ICE when we have unimplemented/invalid trait items When the resulting trait item is in an error state this means the underlying fields will be null. Fixes #2478 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc: add is_error check gcc/testsuite/ChangeLog: * rust/compile/non_member_const.rs: add missing error message * rust/compile/issue-2478.rs: New test. Signed-off-by: Philip Herron Diff: --- gcc/rust/typecheck/rust-hir-type-check-item.cc | 3 ++- gcc/testsuite/rust/compile/issue-2478.rs | 16 ++++++++++++++++ gcc/testsuite/rust/compile/non_member_const.rs | 6 ++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 98c5c1a4fec..b329ac13179 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -615,7 +615,8 @@ TypeCheckItem::validate_trait_impl_block ( impl_item.get (), self, specified_bound, substitutions); - trait_item_refs.push_back (trait_item_ref.get_raw_item ()); + if (!trait_item_ref.is_error ()) + trait_item_refs.push_back (trait_item_ref.get_raw_item ()); } } diff --git a/gcc/testsuite/rust/compile/issue-2478.rs b/gcc/testsuite/rust/compile/issue-2478.rs new file mode 100644 index 00000000000..7fe4e2d2a94 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2478.rs @@ -0,0 +1,16 @@ +#[lang = "sized"] +pub trait Sized {} + +struct Bar; + +trait Foo { + const N: u32; + + fn M(); +} + +impl Foo for Bar { + // { dg-error "missing N, M in implementation of trait .Foo." "" { target *-*-* } .-1 } + fn N() {} + // { dg-error "method .N. is not a member of trait .Foo." "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/non_member_const.rs b/gcc/testsuite/rust/compile/non_member_const.rs index b9740025266..5812db29e03 100644 --- a/gcc/testsuite/rust/compile/non_member_const.rs +++ b/gcc/testsuite/rust/compile/non_member_const.rs @@ -7,9 +7,7 @@ trait Foo { struct Bar; -impl Foo for Bar { +impl Foo for Bar {// { dg-error "missing N in implementation of trait .Foo." } 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 +}