Skip to content

Commit

Permalink
Resolve assoc fns & consts defined on fn ptr tys
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Feb 22, 2023
1 parent bd4a96a commit ffad636
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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("...");
}

0 comments on commit ffad636

Please sign in to comment.