https://gcc.gnu.org/g:1a2f56a9d529f39ccbd72ec9fa5b5ccb8c3e6737
commit 1a2f56a9d529f39ccbd72ec9fa5b5ccb8c3e6737 Author: Philip Herron <herron.phi...@googlemail.com> Date: Thu Mar 27 14:22:48 2025 +0000 gccrs: Fix ICE when doing method resolution on trait predicates We need to ensure we are adding methods to the possible candidates. Fixes Rust-GCC#3554 gcc/rust/ChangeLog: * typecheck/rust-hir-dot-operator.cc: gcc/testsuite/ChangeLog: * rust/compile/issue-3554-1.rs: New test. * rust/compile/issue-3554-2.rs: New test. Signed-off-by: Philip Herron <herron.phi...@googlemail.com> Diff: --- gcc/rust/typecheck/rust-hir-dot-operator.cc | 7 +++++-- gcc/testsuite/rust/compile/issue-3554-1.rs | 8 ++++++++ gcc/testsuite/rust/compile/issue-3554-2.rs | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc index 31034eed2fbf..e1535a28744f 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.cc +++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc @@ -472,8 +472,11 @@ MethodResolver::get_predicate_items ( if (ty->get_kind () == TyTy::TypeKind::FNDEF) { TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty); - predicate_candidate candidate{lookup, fnty}; - predicate_items.push_back (candidate); + if (fnty->is_method ()) + { + predicate_candidate candidate{lookup, fnty}; + predicate_items.push_back (candidate); + } } } diff --git a/gcc/testsuite/rust/compile/issue-3554-1.rs b/gcc/testsuite/rust/compile/issue-3554-1.rs new file mode 100644 index 000000000000..a66be35d3638 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3554-1.rs @@ -0,0 +1,8 @@ +trait Tr { + fn foo(); + + fn bar(&self) { + self.foo() + // { dg-error "no method named .foo. found in the current scope .E0599." "" { target *-*-* } .-1 } + } +} diff --git a/gcc/testsuite/rust/compile/issue-3554-2.rs b/gcc/testsuite/rust/compile/issue-3554-2.rs new file mode 100644 index 000000000000..e455a8b2cec0 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3554-2.rs @@ -0,0 +1,18 @@ +#[lang = "sized"] +pub trait Sized {} + +#[lang = "fn_once"] +pub trait FnOnce<Args> { + #[lang = "fn_once_output"] + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} +trait Tr { + fn foo(); + + fn bar(&self) { + (|| self.foo())() + // { dg-error "no method named .foo. found in the current scope .E0599." "" { target *-*-* } .-1 } + } +}