Repository navigation
fn-ptr docs were not updated for the change to trait impls #111182
Description
Activity
- addedA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call 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.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.and removedA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
on May 4, 2023 @rustbot claim
the PR which added the trait was #108080
Reacted by mj10021Hi @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 } }
pretty much yeah.
not sure whether it makes sense to differentiate between traits implemented via
FnPtrand 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
Reacted by mj10021- addedT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
on Oct 30, 2024 - removedE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Sep 9, 2025 Now
FnPtris inopsmodule: docs/nightly/std/ops/trait.FnPtr.Just forwarding comment from a PR here:
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 traitFnPtr.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 bypassrustc_deny_explicit_implin the (arguably unlikely) scenario of a user compilingcorethemselves withdocenabled 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_implcheck ifactually_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.
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
rust/library/core/src/primitive_docs.rs
Lines 1574 to 1583 in 6f8c055