diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-07-29 17:33:47 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-07-29 17:27:20 +0000 |
commit | 5a378edb750eed4816f4bb1d8b531ca9dd7ef6e2 (patch) | |
tree | e55b792992997531f8a1ce3c03d5852a49b0c025 | |
parent | 7ce263e17a59c44d057bfb1ed6a8ab1c4d837f28 (diff) | |
download | gcc-5a378edb750eed4816f4bb1d8b531ca9dd7ef6e2.zip gcc-5a378edb750eed4816f4bb1d8b531ca9dd7ef6e2.tar.gz gcc-5a378edb750eed4816f4bb1d8b531ca9dd7ef6e2.tar.bz2 |
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 <herron.philip@googlemail.com>
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-item.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2478.rs | 16 | ||||
-rw-r--r-- | 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 85b26ae..798bc95 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 0000000..7fe4e2d --- /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 b974002..5812db2 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 `<Bar as Foo>` } -}
\ No newline at end of file +} |