diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 8b0473b7454c0..54ff6aeb2f35c 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -692,6 +692,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | ty::Slice(_) | ty::RawPtr(_) | ty::Ref(..) + | ty::FnPtr(_) | ty::Never | ty::Tuple(..) => self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty), _ => {} diff --git a/tests/ui/associated-item/associated-item-on-function-pointer.rs b/tests/ui/associated-item/associated-item-on-function-pointer.rs new file mode 100644 index 0000000000000..30ef580df4c0b --- /dev/null +++ b/tests/ui/associated-item/associated-item-on-function-pointer.rs @@ -0,0 +1,34 @@ +// Check that we successfully resolve associated functions and constants defined on +// function pointer types. Regression test for issue #108270. + +// check-pass + +#![feature(rustc_attrs)] +#![rustc_coherence_is_core] + +impl fn() { + const ARITY: usize = 0; + + fn handle() {} + + fn apply(self) { + self() + } +} + +impl for<'src> fn(&'src str) -> bool { + fn execute(self, source: &'static str) -> bool { + self(source) + } +} + +fn main() { + let _: usize = ::ARITY; + ::handle(); + + let f: fn() = main; + f.apply(); + + let predicate: fn(&str) -> bool = |source| !source.is_empty(); + let _ = predicate.execute("..."); +}