diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-04-20 12:44:31 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-04-26 15:02:44 +0000 |
commit | ddcd571a67fb205f7e168a3c3cd4e63080ed026b (patch) | |
tree | ad02629c13e6c21909b39be2979c3f498a604b31 /gcc/rust | |
parent | 34a5eebc1b98b6519d590c3b165c3bae1afa5fbb (diff) | |
download | gcc-ddcd571a67fb205f7e168a3c3cd4e63080ed026b.zip gcc-ddcd571a67fb205f7e168a3c3cd4e63080ed026b.tar.gz gcc-ddcd571a67fb205f7e168a3c3cd4e63080ed026b.tar.bz2 |
gccrs: Fix ICE during method resolution
We were missing a check for trait item selection to ensure they are
actually methods and remove assertion to check if the trait item is a
function this is a valid error check not an assertion.
Fixes #2139
gcc/rust/ChangeLog:
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): verify it is a method
gcc/testsuite/ChangeLog:
* rust/compile/issue-2139.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-dot-operator.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc index 084ef88..29c3e4c 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.cc +++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc @@ -240,8 +240,12 @@ MethodResolver::select (TyTy::BaseType &receiver) const HIR::Trait *trait = trait_ref->get_hir_trait_ref (); HIR::TraitItem *item = item_ref->get_hir_trait_item (); - rust_assert (item->get_item_kind () == HIR::TraitItem::TraitItemKind::FUNC); + if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC) + return true; + HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item); + if (!func->get_decl ().is_method ()) + return true; TyTy::BaseType *ty = item_ref->get_tyty (); rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF); |