Skip to content

fn-ptr docs were not updated for the change to trait impls #111182

Description

@lcnr

Location

https://doc.rust-lang.org/nightly/std/primitive.fn.html#trait-implementations-1

Summary

we now implement all of these traits for all function pointers. We should change the documentation to mention that.

we may also want to add a dummy impl for rustdoc for https://doc.rust-lang.org/nightly/std/marker/trait.FnPtr.html, similar to

// Fake impl that's only really used for docs.
#[cfg(doc)]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(fake_variadic)]
/// This trait is implemented on function pointers with any number of arguments.
impl<Ret, T> Clone for fn(T) -> Ret {
fn clone(&self) -> Self {
loop {}
}
}

Activity

  1. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    and removed
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on May 4, 2023
  2. mj10021 commented on May 5, 2023

    @mj10021
    Contributor

    @rustbot claim

  3. lcnr commented on May 5, 2023

    @lcnr
    ContributorAuthor

    the PR which added the trait was #108080

  4. mj10021 commented on May 11, 2023

    @mj10021
    Contributor

    Hi @lcnr ! Sorry it took me a bit to get to this after I claimed it. Just want to make sure I'm understanding correctly what the documentation should look like:

    All function pointers implement FnPtr, which means they all implement:

    ConstParamTy
    Destruct
    DiscriminantKind
    FnPtr
    PointerLike
    StructuralEq
    StructuralPartialEq
    Tuple
    Unsize
    Copy
    Send
    Sized
    Sync
    Unpin
    

    (pulled from the FnPtr docs), and so those traits should be included in the function pointer doc? And then would the dummy impl look something like this:

    // Fake impl that's only really used for docs.
    #[cfg(doc)]
    #[unstable(feature = "fn_ptr_trait")]
    #[doc(fake_variadic)]
    /// This trait is implemented on function pointers with any number of arguments. 
    impl<Ret, T> FnPtr for fn(T) -> Ret {
        fn addr(&self) -> *const () {
            // empty
        }
    }
  5. lcnr commented on May 16, 2023

    @lcnr
    ContributorAuthor

    pretty much yeah.

    not sure whether it makes sense to differentiate between traits implemented via FnPtr and traits implemented via builtin impls.

    I personally don't think we should mention traits which are currently still unstable, that's something we can discuss further after you opened the PR

  6. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Oct 30, 2024
  7. removed
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Sep 9, 2025
  8. boozook commented on Aug 25, 2026

    @boozook

    Now FnPtr is in ops module: docs/nightly/std/ops/trait.FnPtr.

  9. clarfonthey commented on Sep 22, 2026

    @clarfonthey
    Contributor

    Just forwarding comment from a PR here:

    #112106 (comment)

    Sorry for not getting back to you. I've discussed this with Guillaume and a T-compiler member a while ago. This error is intentional to uphold some soundness invariants of the trait solver and caused by the #[rustc_deny_explicit_impl] on trait FnPtr.

    While we could theoretically turn it into a #[cfg_attr(not(doc), rustc_deny_explicit_impl)] to make your PR compile, I guess I would advice against this since it would make it possible to bypass rustc_deny_explicit_impl in the (arguably unlikely) scenario of a user compiling core themselves with doc enabled manually (e.g. with -Zbuild-std + --cfg doc).

    An alternative to that would be patching the trait solver(s) to skip the rustc_deny_explicit_impl check if actually_rustdoc.

    I'm not super happy about any of these options (there are more sophisticated ones like introducing more internal attributes etc.).

    So it doesn't get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions