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

Inherent associated functions and constants defined on function pointer types won't be found #108270

Closed
fmease opened this issue Feb 20, 2023 · 5 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) A-resolve Area: Name resolution C-bug Category: This is a bug. F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Feb 20, 2023

Since only core & std are allowed to define functions and constants on function pointer types (like fn() or for<'a> fn(&'a ()) -> bool) and since they maybe never will, this issue is of low priority. For other primitive types like !, (), bool etc., inherent associated functions and constants are correctly resolved.

#![feature(rustc_attrs)]
#![rustc_coherence_is_core]

impl fn() {
    const X: () = ();
}

fn user() {
    <fn()>::X; //~ ERROR no associated item named `X` found for fn pointer `fn()` in the current scope
}

Note that the perma-unstable attribute #![rustc_coherence_is_core] is used in the reproducer which doesn't come with any language or stability guarantees. However, this issue is not about it but about the fact that core which uses this attribute internally and std (which can use #[rustc_allow_incoherent_impl]) would not be able to properly define associated items on those types. For the same reason, I'm not labeling this as requires-nightly.

@rustbot label T-compiler A-resolve A-associated-items

@fmease fmease added the C-bug Category: This is a bug. label Feb 20, 2023
@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 20, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Feb 22, 2023

@fmease: my understanding is that this just requires to assemble candidates for incoherent impls as well, just like method candidate assembly does.

@fmease
Copy link
Member Author

fmease commented Feb 22, 2023

@compiler-errors Note that this not about inherent associated types but functions & constants. So we need to modify method candidate assembly itself.

I think we just need to add | ty::FnPtr(..) here in assemble_probe haha:

| ty::Tuple(..) => self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty),

I'm gonna do that later once I have access to my machine.
@rustbot claim

@compiler-errors
Copy link
Member

@fmease oh lol, i just saw your name and thought inherent associated types. cool, good luck

@fmease
Copy link
Member Author

fmease commented Feb 22, 2023

The IAT counterpart is #106719 fyi ^^

@workingjubilee workingjubilee added the F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. label Mar 14, 2023
@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-resolve Area: Name resolution C-bug Category: This is a bug. F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants