diff options
| author | Martin Nordholts <enselic@gmail.com> | 2022-02-19 09:50:35 +0100 |
|---|---|---|
| committer | Martin Nordholts <enselic@gmail.com> | 2022-03-04 05:54:12 +0100 |
| commit | aa763fcf421e627455aa1de16df1292c8e1bcb9d (patch) | |
| tree | f0380c618dcca64aa91da9bc712991d4406132bb /src/rustdoc-json-types | |
| parent | 6d7684101a51f1c375ec84aef5d2fbdeb214bbc2 (diff) | |
| download | rust-aa763fcf421e627455aa1de16df1292c8e1bcb9d.tar.gz rust-aa763fcf421e627455aa1de16df1292c8e1bcb9d.zip | |
rustdoc-json: Include GenericParamDefKind::Type::synthetic in JSON
The rustdoc JSON for
```
pub fn f(_: impl Clone) {}
```
will effectively be
```
pub fn f<impl Clone: Clone>(_: impl Clone)
```
where a synthetic generic parameter called `impl Clone` with generic
trait bound `Clone` is added to the function declaration.
The generated HTML filters out these generic parameters by doing
`self.params.iter().filter(|p| !p.is_synthetic_type_param())`, because
the synthetic generic parameter is not of interest to regular users.
For the same reason, we should expose whether or not a generic parameter
is synthetic or not also in the rustdoc JSON, so that rustdoc JSON
clients can also have the option to hide synthetic generic parameters.
Diffstat (limited to 'src/rustdoc-json-types')
| -rw-r--r-- | src/rustdoc-json-types/lib.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 40b0de44829..7df880a4ed8 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 12; +pub const FORMAT_VERSION: u32 = 13; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -346,9 +346,41 @@ pub struct GenericParamDef { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "snake_case")] pub enum GenericParamDefKind { - Lifetime { outlives: Vec<String> }, - Type { bounds: Vec<GenericBound>, default: Option<Type> }, - Const { ty: Type, default: Option<String> }, + Lifetime { + outlives: Vec<String>, + }, + Type { + bounds: Vec<GenericBound>, + default: Option<Type>, + /// This is normally `false`, which means that this generic parameter is + /// declared in the Rust source text. + /// + /// If it is `true`, this generic parameter has been introduced by the + /// compiler behind the scenes. + /// + /// # Example + /// + /// Consider + /// + /// ```ignore (pseudo-rust) + /// pub fn f(_: impl Trait) {} + /// ``` + /// + /// The compiler will transform this behind the scenes to + /// + /// ```ignore (pseudo-rust) + /// pub fn f<impl Trait: Trait>(_: impl Trait) {} + /// ``` + /// + /// In this example, the generic parameter named `impl Trait` (and which + /// is bound by `Trait`) is synthetic, because it was not originally in + /// the Rust source text. + synthetic: bool, + }, + Const { + ty: Type, + default: Option<String>, + }, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] |
