diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-14 21:39:09 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-21 13:52:46 +1000 |
| commit | 7fa8901cd090093a57723d3f196c27db3b98ad94 (patch) | |
| tree | fa6a5d9f12aec8ce6746f09a78c12a63d9864ecd /src/rustdoc-json-types | |
| parent | 59a3399148d02d412485999dee78c0e72a54c0a5 (diff) | |
rustdoc_json: represent generic args consistently.
They show up in three places: once as `Option<Box<GenericArgs>>`, once
as `Box<GenericArgs>`, and once as `GenericArgs`. The first option is
best. It is more compact because generic args are often missing. This
commit changes the latter two to the former.
Example output, before and after, for the `AssocItemConstraint` change:
```
{"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}},"binding":{...}}
{"name":"Offset","args":null,"binding":{...}}
```
Example output, before and after, for the `Type::QualifiedPath` change:
```
{"qualified_path":{"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}}, ...}}
{"qualified_path":{"name":"Offset","args":null, ...}}
```
This reduces JSON output size, but not by much (e.g. 0.5%), because
`AssocItemConstraint` and `Type::QualifiedPath` are uncommon.
Diffstat (limited to 'src/rustdoc-json-types')
| -rw-r--r-- | src/rustdoc-json-types/lib.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 0404f3ff034..c9b4da183a3 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc // will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line // are deliberately not in a doc comment, because they need not be in public docs.) // -// Latest feature: Pretty printing of cold attributes changed -pub const FORMAT_VERSION: u32 = 50; +// Latest feature: improve handling of generic args +pub const FORMAT_VERSION: u32 = 51; /// The root of the emitted JSON blob. /// @@ -362,7 +362,7 @@ pub struct AssocItemConstraint { /// The name of the associated type/constant. pub name: String, /// Arguments provided to the associated type/constant. - pub args: GenericArgs, + pub args: Option<Box<GenericArgs>>, /// The kind of bound applied to the associated type/constant. pub binding: AssocItemConstraintKind, } @@ -1118,7 +1118,7 @@ pub enum Type { /// <core::slice::IterMut<'static, u32> as BetterIterator>::Item<'static> /// // ^^^^^^^^^ /// ``` - args: Box<GenericArgs>, + args: Option<Box<GenericArgs>>, /// The type with which this type is associated. /// /// ```ignore (incomplete expression) |
