Skip to content

Commit 1a2f56a

Browse files
committed
gccrs: Fix ICE when doing method resolution on trait predicates
We need to ensure we are adding methods to the possible candidates. Fixes #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 <[email protected]>
1 parent 34b0a68 commit 1a2f56a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

gcc/rust/typecheck/rust-hir-dot-operator.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,11 @@ MethodResolver::get_predicate_items (
472472
if (ty->get_kind () == TyTy::TypeKind::FNDEF)
473473
{
474474
TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
475-
predicate_candidate candidate{lookup, fnty};
476-
predicate_items.push_back (candidate);
475+
if (fnty->is_method ())
476+
{
477+
predicate_candidate candidate{lookup, fnty};
478+
predicate_items.push_back (candidate);
479+
}
477480
}
478481
}
479482

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Tr {
2+
fn foo();
3+
4+
fn bar(&self) {
5+
self.foo()
6+
// { dg-error "no method named .foo. found in the current scope .E0599." "" { target *-*-* } .-1 }
7+
}
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[lang = "sized"]
2+
pub trait Sized {}
3+
4+
#[lang = "fn_once"]
5+
pub trait FnOnce<Args> {
6+
#[lang = "fn_once_output"]
7+
type Output;
8+
9+
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
10+
}
11+
trait Tr {
12+
fn foo();
13+
14+
fn bar(&self) {
15+
(|| self.foo())()
16+
// { dg-error "no method named .foo. found in the current scope .E0599." "" { target *-*-* } .-1 }
17+
}
18+
}

0 commit comments

Comments
 (0)