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

Added traits implemented by FnPtr to fn docs with example function #112106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -453,5 +454,4 @@ pub mod simd {
#[unstable(feature = "portable_simd", issue = "86656")]
pub use crate::core_simd::simd::*;
}

include!("primitive_docs.rs");
36 changes: 36 additions & 0 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ mod prim_ref {}
/// * [`Clone`]
/// * [`Copy`]
/// * [`Send`]
/// * [`Sized`]
/// * [`Sync`]
/// * [`Unpin`]
/// * [`UnwindSafe`]
Expand All @@ -1674,3 +1675,38 @@ mod prim_fn {}
// See src/librustdoc/passes/collect_trait_impls.rs:collect_trait_impls
#[doc(hidden)]
impl<Ret, T> 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<Ret, T> 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<Ret, T> 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<Ret, T> FnPtr for fn(T) -> Ret {
fn addr(self) -> *const () {
// empty
}
}
4 changes: 3 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down
Loading