diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-dot-operator.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-2139.rs | 16 |
2 files changed, 21 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); diff --git a/gcc/testsuite/rust/compile/issue-2139.rs b/gcc/testsuite/rust/compile/issue-2139.rs new file mode 100644 index 0000000..780ed58 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2139.rs @@ -0,0 +1,16 @@ +pub trait Foo { + fn foo(); +} + +impl Foo for u16 { + fn foo() { + <u16 as Foo>::foo() + } +} + +fn main() { + let a: u16 = 123; + a.foo(); + // { dg-error "failed to resolve method for .foo." "" { target *-*-* } .-1 } + // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 } +} |