Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez

Improve the function pointer docs

This is #97842 but for function pointers instead of tuples. The concept is basically the same.

* Reduce duplicate impls; show `fn (T₁, T₂, …, Tₙ)` and include a sentence saying that there exists up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

https://notriddle.com/notriddle-rustdoc-test/std/primitive.fn.html
This commit is contained in:
bors 2022-07-19 19:36:57 +00:00
commit 9a7b7d5e50
29 changed files with 278 additions and 106 deletions

View file

@ -4,7 +4,7 @@ enum, union, or trait object.
Erroneous code example:
```compile_fail,E0118
impl fn(u8) { // error: no nominal type found for inherent implementation
impl<T> T { // error: no nominal type found for inherent implementation
fn get_state(&self) -> String {
// ...
}
@ -20,8 +20,8 @@ trait LiveLongAndProsper {
fn get_state(&self) -> String;
}
// and now you can implement it on fn(u8)
impl LiveLongAndProsper for fn(u8) {
// and now you can implement it on T
impl<T> LiveLongAndProsper for T {
fn get_state(&self) -> String {
"He's dead, Jim!".to_owned()
}
@ -33,9 +33,9 @@ For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
Example:
```
struct TypeWrapper(fn(u8));
struct TypeWrapper<T>(T);
impl TypeWrapper {
impl<T> TypeWrapper<T> {
fn get_state(&self) -> String {
"Fascinating!".to_owned()
}