Skip to content

Commit 99d0fd9

Browse files
committed
Tweak examples and reference
1 parent 0ff8834 commit 99d0fd9

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

text/0000-rustdoc-json.md

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ types can appear in the output:
197197

198198
To provide various maps/references to items, the JSON output uses unique strings as IDs for each
199199
item. They happen to be the compiler internal DefId for that item, but in the JSON blob they should
200-
be treated as opaque as they aren't guaranteed to be stable across compiler invocations. IDs should
201-
NOT be used to link items from external crates (see [the Resolving IDs section](#resolving-ids)).
200+
be treated as opaque as they aren't guaranteed to be stable across compiler invocations. IDs are
201+
only valid/consistent within a single JSON blob. They cannot be used to resolve references between
202+
the JSON output of different crates (see [the Resolving IDs section](#resolving-ids)).
202203

203204
## Crate
204205

@@ -217,29 +218,30 @@ Name | Type | Description
217218

218219
### Resolving IDs
219220

220-
The `index` field of [Crate](#Crate) contains _almost_ entirely local items, which includes impls
221-
of external traits on local types or local traits on external types. The exception to this is that
222-
external trait definitions are also included in the `index` to allow users to access information
223-
about their methods and associated types/consts.
221+
The crate's `index` contains mostly local items, which includes impls of external traits on local
222+
types or local traits on external types. The exception to this is that external trait definitions
223+
and their associated items are also included in the `index` because this information is useful when
224+
generating the comprehensive list of methods for a type.
224225

225-
This means that many IDs aren't included in the `index`. In these cases the fallback is to look up
226-
the ID in `paths` where it should be present regardless of whether it's local. That gives
227-
[enough information](#ItemSummary) to create cross references or simply provide names without
228-
copying all of the information about external Items into the local crate's JSON output.
226+
This means that many IDs aren't included in the `index` (any reference to a struct, macro, etc.
227+
from a different crate). In these cases the fallback is to look up the ID in the crate's `paths`.
228+
That gives [enough information](#ItemSummary) about the item to create cross references or simply
229+
provide a name without copying all of the information about external items into the local
230+
crate's JSON output.
229231

230232
### ExternalCrate
231233

232234
Name | Type | Description
233235
----------|---------|------------------------------------------------------------------------------
234236
`name` | String | The name of the crate.
235-
`html_root_url` | String | (*Optional*) The`html_root_url` for that crate if they specify one.
237+
`html_root_url` | String | (*Optional*) The `html_root_url` for that crate if they specify one.
236238

237239
### ItemSummary
238240

239241
Name | Type | Description
240242
----------|---------|------------------------------------------------------------------------------
241243
`crate_num` | int | A number corresponding to the crate this Item is from. Used as an key to the `extern_crates` map in [Crate](#Crate). A value of zero represents an Item from the local crate, any other number means that this Item is external.
242-
`path` | [String] | The fully qualified path (e.g. ["std", "io", "lazy", "Lazy"] for `std::io::lazy::Lazy`) this Item.
244+
`path` | [String] | The fully qualified path (e.g. `["std", "io", "lazy", "Lazy"]` for `std::io::lazy::Lazy`) of this Item.
243245
`kind` | String | What type of Item this is (see [Item](#Item)).
244246

245247
## Item
@@ -252,8 +254,9 @@ Name | Type | Description
252254
----------|---------|------------------------------------------------------------------------------
253255
`crate_num` | int | A number corresponding to the crate this Item is from. Used as an key to the `extern_crates` map in [Crate](#Crate). A value of zero represents an Item from the local crate, any other number means that this Item is external.
254256
`name` | String | The name of the Item, if present. Some Items, like impl blocks, do not have names.
255-
`span` | [Span](#Span) | The source location of this Item.
256-
`visibility` | String | `"default"`, `"public"`, `"crate"`, or `"restricted"` (`pub(path)`). TODO: show how the restricted path info is represented.
257+
`span` | [Span](#Span) | (*Optional*) The source location of this Item.
258+
`visibility` | String | `"default"`, `"public"`, `"crate"`, or `"restricted"` (`pub(path)`).
259+
`restricted_path` | String | (*Optional*) If `visitility == "restricted"`, this field contains the path that it's restricted to.
257260
`docs` | String | The extracted documentation text from the Item.
258261
`attrs` | [String] | The attributes (other than doc comments) on the Item, rendered as strings.
259262
`deprecation` | [Deprecation](#Deprecation) | (*Optional*) Information about the Item's deprecation, if present.
@@ -305,7 +308,8 @@ Name | Type | Description
305308
`inner` can be one of the 3 following objects:
306309
- `"plain"` (e.g. `Enum::Variant`)
307310
- `{"tuple": [Type]}` (e.g. `Enum::Variant(u32, String)`)
308-
- `{"struct": Object}` (e.g. `Enum::Variant{foo: u32, bar: String}`) in which case the `Object` is the same as `inner` when `kind == "struct"`.
311+
- `{"struct": Object}` (e.g. `Enum::Variant{foo: u32, bar: String}`) in which case the `Object`
312+
has a single key `"struct"` with a value that's the same object as `inner` when `kind == "struct"`.
309313

310314
### `kind == "trait"`
311315

@@ -334,8 +338,7 @@ Name | Type | Description
334338
--------------|----------|-------------------------------------------------------------------------
335339
`decl` | [FnDecl](#FnDecl) | Information about the method signature, or declaration.
336340
`generics` | [Generics](#Generics) | Information about the method's type parameters and `where` clauses.
337-
`header` | String | `"const"`, `"async"`, `"unsafe"`, or a space separated combination of those
338-
modifiers.
341+
`header` | String | `"const"`, `"async"`, `"unsafe"`, or a space separated combination of those modifiers.
339342
`has_body` | bool | Whether this is just a method signature (in a trait definition) or a method with an actual body.
340343

341344
### `kind == "assoc_const"`
@@ -368,7 +371,7 @@ Name | Type | Description
368371
`items` | [[ID](#ID)] | The list of method, constant, and typedef items contained in this impl block.
369372
`negative` | bool | Whether this is a negative impl (e.g. `!Sized` or `!Send`).
370373
`synthetic` | bool | Whether this is an impl that's implied by the compiler (for autotraits).
371-
`blanket_impl` | [Type](#Type) | TODO
374+
`blanket_impl` | String | (*Optional*) The name of the generic parameter used for the blanket impl, if this impl was produced by one. For example `impl<T, U> Into<U> for T` would result in `blanket_impl == "T"`.
372375

373376
### `kind == "constant"`
374377

@@ -462,8 +465,8 @@ Name | Type | Description
462465

463466
Name | Type | Description
464467
-----------|----------|----------------------------------------------------------------------------
465-
`since` | String | Usually a version number when this Item first became deprecated.
466-
`note` | String | The reason for deprecation and/or what alternatives to use.
468+
`since` | String | (*Optional*) Usually a version number when this Item first became deprecated.
469+
`note` | String | (*Optional*) The reason for deprecation and/or what alternatives to use.
467470

468471
## FnDecl
469472

@@ -477,8 +480,8 @@ Name | Type | Description
477480

478481
Name | Type | Description
479482
-----------|----------|----------------------------------------------------------------------------
480-
`params` | [[GenericParamDef](#GenericParamDef)] | A list of generic parameter definitions (e.g. `<T: Clone + Hash, U: Copy>`)
481-
`where_predicates` | [[WherePredicate](#WherePredicate)] | A list of where predicates (e.g. `where T: Iterator, T::Item: Copy`)
483+
`params` | [[GenericParamDef](#GenericParamDef)] | A list of generic parameter definitions (e.g. `<T: Clone + Hash, U: Copy>`).
484+
`where_predicates` | [[WherePredicate](#WherePredicate)] | A list of where predicates (e.g. `where T: Iterator, T::Item: Copy`).
482485

483486
### Examples
484487

@@ -658,9 +661,9 @@ This is the main kind that represents all user defined types.
658661
Name | Type | Description
659662
-----------|----------|----------------------------------------------------------------------------
660663
`name` | String | The path of this type as written in the code (`"std::iter::Iterator"`, `"::module::Struct"`, etc.).
661-
`args` | [GenericArgs](#GenericArgs) | Any arguments on this type such as `Vec<i32>` or `SomeStruct<'a, 5, u8, B: Copy, C = 'static str>`.
664+
`args` | [GenericArgs](#GenericArgs) | (*Optional*) Any arguments on this type such as `Vec<i32>` or `SomeStruct<'a, 5, u8, B: Copy, C = 'static str>`.
662665
`id` | [ID](#ID) | The ID of the trait/struct/enum/etc. that this type refers to.
663-
`param_names` | [GenericBound](#GenericBound) | (*Optional*) If this type is of the form `dyn Foo + Bar + ...` then this field contains the information about those trait bounds.
666+
`param_names` | [GenericBound](#GenericBound) | If this type is of the form `dyn Foo + Bar + ...` then this field contains those trait bounds.
664667

665668
#### GenericArgs
666669

@@ -683,7 +686,8 @@ Name | Type | Description
683686
Can be one of the 3 following objects:
684687
- `"lifetime": String`
685688
- `"type": Type`
686-
- `"const": Object` where the object is the same as the `inner` field of `Item` when `kind == "constant"`
689+
- `"const": Object` where the object has a single key `"constant"` with value that's the same object as the
690+
`inner` field of `Item` when `kind == "constant"`
687691

688692
#### TypeBinding
689693

@@ -697,9 +701,6 @@ Name | Type | Description
697701

698702
`"inner"'` is a String which is simply the name of a type parameter.
699703

700-
### `kind = "bare_function_decl"`
701-
TODO
702-
703704
### `kind = "tuple"`
704705

705706
`"inner"` is a single list with the Types of each tuple item.
@@ -727,6 +728,15 @@ Used to represent the `!` type, has no fields.
727728

728729
Used to represent `_` in type parameters, has no fields.
729730

731+
### `kind = "function_pointer"`
732+
733+
Name | Type | Description
734+
-----------|----------|----------------------------------------------------------------------------
735+
`is_unsafe` | bool | Whether this is an `unsafe fn`.
736+
`decl` | [FnDecl](#FnDecl) | Information about the function signature, or declaration.
737+
`params` | [[GenericParamDef](#GenericParamDef)] | A list of generic parameter definitions (e.g. `<T: Clone + Hash, U: Copy>`).
738+
`abi` | String | The ABI string on the function.
739+
730740
### `kind = "raw_pointer"`
731741

732742
Name | Type | Description
@@ -744,7 +754,8 @@ Name | Type | Description
744754

745755
### `kind = "qualified_path"`
746756

747-
When a type is qualified by a trait (`<Type as Trait>::Name`) or associated type (`T::Item` where `T: Iterator`).
757+
Used when a type is qualified by a trait (`<Type as Trait>::Name`) or associated type (`T::Item`
758+
where `T: Iterator`).
748759

749760
Name | Type | Description
750761
-----------|----------|----------------------------------------------------------------------------
@@ -862,8 +873,7 @@ pub fn references<'a>(a: &'a mut str) -> &'static MyType {}
862873
"bindings": []
863874
}
864875
},
865-
"param_names": null,
866-
"is_generic": false
876+
"param_names": null
867877
}
868878
}
869879
}
@@ -913,8 +923,7 @@ pub fn generics<T>(a: T, b: impl Iterator<Item = bool>) -> ! {}
913923
]
914924
}
915925
},
916-
"param_names": null,
917-
"is_generic": false
926+
"param_names": null
918927
}
919928
},
920929
"generic_params": [],
@@ -992,8 +1001,7 @@ pub fn generic_args<'a>(x: impl MyTrait<'a, i32, Item = u8, Other = f32>) {
9921001
]
9931002
}
9941003
},
995-
"param_names": null,
996-
"is_generic": false
1004+
"param_names": null
9971005
}
9981006
},
9991007
"generic_params": [],

0 commit comments

Comments
 (0)