Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve inherent associated functions & constants defined on function pointer types #108347

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
_ => {}
Expand Down
34 changes: 34 additions & 0 deletions tests/ui/associated-item/associated-item-on-function-pointer.rs
Original file line number Diff line number Diff line change
@@ -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 = <fn()>::ARITY;
<fn()>::handle();

let f: fn() = main;
f.apply();

let predicate: fn(&str) -> bool = |source| !source.is_empty();
let _ = predicate.execute("...");
}