Skip to content

Commit 0ff8834

Browse files
committed
Fill out more types
1 parent 86663e1 commit 0ff8834

File tree

1 file changed

+97
-61
lines changed

1 file changed

+97
-61
lines changed

text/0000-rustdoc-json.md

Lines changed: 97 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- Feature Name: `rustdoc_json`
22
- Start Date: 2020-06-26
3-
- RFC PR: (leave this empty)
4-
- Rust Issue: (leave this empty)
3+
- RFC PR: [rust-lang/rfcs#2963](https://github.com/rust-lang/rfcs/pull/2963)
4+
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
55

66
# Summary
77
[summary]: #summary
@@ -96,16 +96,14 @@ After running the above command, you should get a `lib.json` file like the follo
9696
"attrs": [],
9797
"kind": "function",
9898
"inner": {
99-
"function_item": {
100-
"decl": {
101-
"inputs": [],
102-
"output": null,
103-
"c_variadic": false
104-
},
105-
"generics": {...},
106-
"header": "",
107-
"abi": "\"Rust\""
108-
}
99+
"decl": {
100+
"inputs": [],
101+
"output": null,
102+
"c_variadic": false
103+
},
104+
"generics": {...},
105+
"header": "",
106+
"abi": "\"Rust\""
109107
}
110108
},
111109
"0:4": {
@@ -121,13 +119,11 @@ After running the above command, you should get a `lib.json` file like the follo
121119
"attrs": [],
122120
"kind": "struct",
123121
"inner": {
124-
"struct_item": {
125-
"struct_type": "unit",
126-
"generics": {...},
127-
"fields_stripped": false,
128-
"fields": [],
129-
"impls": [...]
130-
}
122+
"struct_type": "unit",
123+
"generics": {...},
124+
"fields_stripped": false,
125+
"fields": [],
126+
"impls": [...]
131127
}
132128
},
133129
"0:0": {
@@ -143,13 +139,11 @@ After running the above command, you should get a `lib.json` file like the follo
143139
"attrs": [],
144140
"kind": "module",
145141
"inner": {
146-
"module_item": {
147-
"is_crate": true,
148-
"items": [
149-
"0:4",
150-
"0:3"
151-
]
152-
}
142+
"is_crate": true,
143+
"items": [
144+
"0:4",
145+
"0:3"
146+
]
153147
}
154148
}
155149
},
@@ -165,7 +159,7 @@ After running the above command, you should get a `lib.json` file like the follo
165159
"kind": "struct"
166160
},
167161
...
168-
}
162+
},
169163
"extern_crates": {
170164
"9": {
171165
"name": "backtrace",
@@ -261,7 +255,8 @@ Name | Type | Description
261255
`span` | [Span](#Span) | The source location of this Item.
262256
`visibility` | String | `"default"`, `"public"`, `"crate"`, or `"restricted"` (`pub(path)`). TODO: show how the restricted path info is represented.
263257
`docs` | String | The extracted documentation text from the Item.
264-
`attrs` | [String]| The attributes (other than doc comments) on the Item, rendered as strings.
258+
`attrs` | [String] | The attributes (other than doc comments) on the Item, rendered as strings.
259+
`deprecation` | [Deprecation](#Deprecation) | (*Optional*) Information about the Item's deprecation, if present.
265260
`kind` | String | The kind of Item this is. Determines what fields are in `inner`.
266261
`inner` | Object | The type-specific fields describing this Item. Check the `kind` field to determine what's available.
267262

@@ -271,16 +266,13 @@ Name | Type | Description
271266
---------|--------|--------------------------------------------------------------------------------
272267
`items` | [[ID](#ID)] | The list of Items contained within this module. The order of definitions is preserved.
273268

274-
### `kind == "function" || "foreign_function"`
275-
276-
Foreign functions are `fn`s from an `extern` block
269+
### `kind == "function"`
277270

278271
Name | Type | Description
279272
-----------|----------|----------------------------------------------------------------------------
280273
`decl` | [FnDecl](#FnDecl) | Information about the function signature, or declaration.
281274
`generics` | [Generics](#Generics) | Information about the function's type parameters and `where` clauses.
282-
`header` | String | `"const"`, `"async"`, `"unsafe"`, or a space separated combination of those
283-
modifiers.
275+
`header` | String | `"const"`, `"async"`, `"unsafe"`, or a space separated combination of those modifiers.
284276
`abi` | String | The ABI string on the function. Non-`extern` functions have a `"Rust"` ABI, whereas `extern` functions without an explicit ABI are `"C"`. See [the reference](https://doc.rust-lang.org/reference/items/external-blocks.html#abi) for more details.
285277

286278
### `kind == "struct" || "union"`
@@ -346,6 +338,24 @@ Name | Type | Description
346338
modifiers.
347339
`has_body` | bool | Whether this is just a method signature (in a trait definition) or a method with an actual body.
348340

341+
### `kind == "assoc_const"`
342+
343+
These items only show up in trait _definitions_. When looking at a trait impl item, the item where the associated constant is defined is a `"constant"` item.
344+
345+
Name | Type | Description
346+
--------------|----------|-------------------------------------------------------------------------
347+
`type` | [Type](#Type) | The type of this associated const.
348+
`default` | String | (*Optional*) The stringified expression for the default value, if provided.
349+
350+
### `kind == "assoc_type"`
351+
352+
These items only show up in trait _definitions_. When looking at a trait impl item, the item where the associated type is defined is a `"typedef"` item.
353+
354+
Name | Type | Description
355+
--------------|----------|-------------------------------------------------------------------------
356+
`bounds` | [[GenericBound](#GenericBound)] | The bounds for this associated type.
357+
`default` | [Type](#Type) | (*Optional*) The default for this type, if provided.
358+
349359
### `kind == "impl"`
350360

351361
Name | Type | Description
@@ -384,42 +394,61 @@ Name | Type | Description
384394
`type` | [Type](#Type) | The type on the right hand side of this definition.
385395
`generics` | [Generics](#Generics) | Any generic parameters on the left hand side of this definition.
386396

387-
### `kind == "assoc_const"`
388-
389-
These items only show up in trait _definitions_. When looking at a trait impl item, the item where the associated constant is defined is a `"constant"` item.
390-
391-
Name | Type | Description
392-
--------------|----------|-------------------------------------------------------------------------
393-
`type` | [Type](#Type) | The type of this associated const.
394-
`default` | String | (*Optional*) The stringified expression for the default value, if provided.
397+
### `kind == "opaque_ty"`
395398

396-
### `kind == "assoc_type"`
399+
Represents [trait aliases](https://doc.rust-lang.org/beta/unstable-book/language-features/trait-alias.html)
400+
of the form:
397401

398-
These items only show up in trait _definitions_. When looking at a trait impl item, the item where the associated type is defined is a `"typedef"` item.
402+
```rust
403+
type Foo<T> = Clone + std::fmt::Debug + Into<T>;
404+
```
399405

400406
Name | Type | Description
401407
--------------|----------|-------------------------------------------------------------------------
402-
`bounds` | [[GenericBound](#GenericBound)] | The bounds for this associated type.
403-
`default` | [Type](#Type) | (*Optional*) The default for this type, if provided.
408+
`bounds` | [[GenericBound](#GenericBound)] | The trait bounds on the right hand side.
409+
`generics` | [Generics](#Generics) | Any generic parameters on the type itself.
404410

405411
### `kind == "foreign_type"`
406412

407-
Name | Type | Description
408-
--------------|----------|-------------------------------------------------------------------------
409-
`bounds` | [[GenericBound](#GenericBound)] | The bounds for this associated type.
410-
`default` | [Type](#Type) | (*Optional*) The default for this type, if provided.
413+
`inner` contains no fields. This item represents a type declaration in an extern block (see [here](https://github.com/rust-lang/rfcs/blob/master/text/1861-extern-types.md)
414+
for more details):
415+
416+
```rust
417+
extern {
418+
type Foo;
419+
}
420+
```
411421

412422
### `kind == "extern_crate"`
413-
TODO
423+
424+
Name | Type | Description
425+
---------|----------|-------------------------------------------------------------------------
426+
`name` | String | The name of the extern crate.
427+
`rename` | String | (*Optional*) The renaming of this crate with `extern crate foo as bar`.
428+
414429
### `kind == "import"`
415-
TODO
416-
### `kind == "opaque_ty"`
417-
TODO
430+
431+
Name | Type | Description
432+
---------|----------|-------------------------------------------------------------------------
433+
`source` | String | The full path being imported (e.g. `"super::some_mod::other_mod::Struct"`).
434+
`name` | String | The name of the imported item (may be different from the last segment of `source` due to import renaming: `use source as name`).
435+
`id` | [ID](#ID) | (*Optional*) The ID of the item being imported.
436+
`glob` | bool | Whether this import ends in a glob: `use source::*`.
437+
418438
### `kind == "macro"`
419-
TODO
420-
### `kind == "proc_attribute"`
421-
TODO
422-
### `kind == "proc_derive"`
439+
440+
A `macro_rules!` declarative macro. Contains a single string with the source representation of
441+
the macro with the patterns stripped, for example:
442+
443+
```rust
444+
macro_rules! vec {
445+
() => { ... };
446+
($elem:expr; $n:expr) => { ... };
447+
($($x:expr),+ $(,)?) => { ... };
448+
}
449+
```
450+
451+
TODO: proc macros
423452

424453
## Span
425454

@@ -429,6 +458,13 @@ Name | Type | Description
429458
`begin` | (int, int) | The zero indexed line and column of the first character in this span.
430459
`begin` | (int, int) | The zero indexed line and column of the last character in this span.
431460

461+
## Deprecation
462+
463+
Name | Type | Description
464+
-----------|----------|----------------------------------------------------------------------------
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.
467+
432468
## FnDecl
433469

434470
Name | Type | Description
@@ -589,7 +625,7 @@ Name | Type | Description
589625

590626
Name | Type | Description
591627
-----------|----------|----------------------------------------------------------------------------
592-
`bounds` | [GenericBound](#GenericBound) | The bounds on this parameter.
628+
`bounds` | [[GenericBound](#GenericBound)] | The bounds on this parameter.
593629
`default` | [Type](#Type) | (*Optional*) The default type for this parameter (e.g `PartialEq<Rhs = Self>`).
594630

595631
### WherePredicate
@@ -996,7 +1032,7 @@ pub fn generic_args<'a>(x: impl MyTrait<'a, i32, Item = u8, Other = f32>) {
9961032
available parsers, but selecting a different data format may provide benefits for file size,
9971033
compressibility, speed of conversion, etc. Since the implementation will lean on serde then this
9981034
may be a non-issue as it would be trivial to switch serialization formats.
999-
- **Alternate data structure.** The proposed output very closely mirrors the internal `Clean` AST
1035+
- **Alternate data structure.** The proposed output very closely mirrors the internal `clean` AST
10001036
types in rustdoc. This simplifies the implementation but may not be the optimal structure for
10011037
users. If there are significant improvements then a future RFC could provide the necessary
10021038
refinements, potentially as another alternative output format if necessary.
@@ -1068,9 +1104,9 @@ include spans, but doesn't do any of the other things mentioned here.
10681104
path in the spans, but it's probably preferable to have it just list the filename for single
10691105
files or the path from the crate root for cargo projects.
10701106
- The proposed implementation exposes a strict subset of the information available to the HTML,
1071-
backend: the `Clean` types for Items and some mappings from the `Cache`. Are there other
1107+
backend: the `clean` types for Items and some mappings from the `Cache`. Are there other
10721108
mappings/info from elsewhere that would be helpful to expose to users?
1073-
- There are some items such as attributes that defer to compiler internal symbols in their `Clean`
1109+
- There are some items such as attributes that defer to compiler internal symbols in their `clean`
10741110
representations which would make them problematic to represent faithfully. Is it OK to simply
10751111
stringify these and leave their handling up to the user?
10761112
- Should we specially handle `Deref` trait impls to make it easier for a struct to find the methods

0 commit comments

Comments
 (0)