Skip to content

Commit ffad636

Browse files
committed
Resolve assoc fns & consts defined on fn ptr tys
1 parent bd4a96a commit ffad636

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
692692
| ty::Slice(_)
693693
| ty::RawPtr(_)
694694
| ty::Ref(..)
695+
| ty::FnPtr(_)
695696
| ty::Never
696697
| ty::Tuple(..) => self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty),
697698
_ => {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Check that we successfully resolve associated functions and constants defined on
2+
// function pointer types. Regression test for issue #108270.
3+
4+
// check-pass
5+
6+
#![feature(rustc_attrs)]
7+
#![rustc_coherence_is_core]
8+
9+
impl fn() {
10+
const ARITY: usize = 0;
11+
12+
fn handle() {}
13+
14+
fn apply(self) {
15+
self()
16+
}
17+
}
18+
19+
impl for<'src> fn(&'src str) -> bool {
20+
fn execute(self, source: &'static str) -> bool {
21+
self(source)
22+
}
23+
}
24+
25+
fn main() {
26+
let _: usize = <fn()>::ARITY;
27+
<fn()>::handle();
28+
29+
let f: fn() = main;
30+
f.apply();
31+
32+
let predicate: fn(&str) -> bool = |source| !source.is_empty();
33+
let _ = predicate.execute("...");
34+
}

0 commit comments

Comments
 (0)