diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 98c5c1a4fec0..b329ac131790 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 000000000000..7fe4e2d2a94b --- /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 b9740025266e..5812db29e038 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 +}