diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b54680a61b4d8..b253c0696a0d6 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -281,10 +281,11 @@ #[allow(unused_extern_crates)] extern crate self as core; +#[allow(unused_imports)] +use crate::marker::FnPtr; #[prelude_import] #[allow(unused)] use prelude::v1::*; - #[cfg(not(test))] // See #65860 #[macro_use] mod macros; @@ -453,5 +454,4 @@ pub mod simd { #[unstable(feature = "portable_simd", issue = "86656")] pub use crate::core_simd::simd::*; } - include!("primitive_docs.rs"); diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index 85595b059ad9a..222c0794b756f 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -1655,6 +1655,7 @@ mod prim_ref {} /// * [`Clone`] /// * [`Copy`] /// * [`Send`] +/// * [`Sized`] /// * [`Sync`] /// * [`Unpin`] /// * [`UnwindSafe`] @@ -1674,3 +1675,38 @@ mod prim_fn {} // See src/librustdoc/passes/collect_trait_impls.rs:collect_trait_impls #[doc(hidden)] impl fn(T) -> Ret {} + +// 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 all function pointers. +impl Clone for fn(T) -> Ret { + fn clone(&self) -> Self { + loop {} + } +} + +// 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 all function pointers. +impl Copy for fn(T) -> Ret { + // empty +} + +// Fake impl that's only really used for docs. +#[cfg(doc)] +#[unstable( + feature = "fn_ptr_trait", + issue = "none", + reason = "internal trait for implementing various traits for all function pointers" +)] +#[doc(fake_variadic)] +/// This trait is implemented on all function pointers. +impl FnPtr for fn(T) -> Ret { + fn addr(self) -> *const () { + // empty + } +} diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 571e475c33672..4a85c484db2c7 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -381,6 +381,7 @@ #![feature(const_format_args)] #![feature(custom_test_frameworks)] #![feature(edition_panic)] +#![feature(fn_ptr_trait)] #![feature(format_args_nl)] #![feature(get_many_mut)] #![feature(lazy_cell)] @@ -408,10 +409,11 @@ // Explicitly import the prelude. The compiler uses this same unstable attribute // to import the prelude implicitly when building crates that depend on std. +#[allow(unused_imports)] +use crate::marker::FnPtr; #[prelude_import] #[allow(unused)] use prelude::rust_2021::*; - // Access to Bencher, etc. #[cfg(test)] extern crate test;