@@ -170,10 +170,13 @@ pub(crate) fn from_deprecation(deprecation: attrs::Deprecation) -> Deprecation {
170
170
Deprecation { since, note : note. map ( |s| s. to_string ( ) ) }
171
171
}
172
172
173
- impl FromClean < clean:: GenericArgs > for GenericArgs {
173
+ impl FromClean < clean:: GenericArgs > for Option < Box < GenericArgs > > {
174
174
fn from_clean ( args : & clean:: GenericArgs , renderer : & JsonRenderer < ' _ > ) -> Self {
175
175
use clean:: GenericArgs :: * ;
176
- match args {
176
+ if args. is_empty ( ) {
177
+ return None ;
178
+ }
179
+ Some ( Box :: new ( match args {
177
180
AngleBracketed { args, constraints } => GenericArgs :: AngleBracketed {
178
181
args : args. into_json ( renderer) ,
179
182
constraints : constraints. into_json ( renderer) ,
@@ -183,7 +186,7 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
183
186
output : output. as_ref ( ) . map ( |a| a. as_ref ( ) . into_json ( renderer) ) ,
184
187
} ,
185
188
ReturnTypeNotation => GenericArgs :: ReturnTypeNotation ,
186
- }
189
+ } ) )
187
190
}
188
191
}
189
192
@@ -580,7 +583,20 @@ impl FromClean<clean::Path> for Path {
580
583
Path {
581
584
path : path. whole_name ( ) ,
582
585
id : renderer. id_from_item_default ( path. def_id ( ) . into ( ) ) ,
583
- args : path. segments . last ( ) . map ( |args| Box :: new ( args. args . into_json ( renderer) ) ) ,
586
+ args : {
587
+ if let Some ( ( final_seg, rest_segs) ) = path. segments . split_last ( ) {
588
+ // In general, `clean::Path` can hold things like
589
+ // `std::vec::Vec::<u32>::new`, where generic args appear
590
+ // in a middle segment. But for the places where `Path` is
591
+ // used by rustdoc-json-types, generic args can only be
592
+ // used in the final segment, e.g. `std::vec::Vec<u32>`. So
593
+ // check that the non-final segments have no generic args.
594
+ assert ! ( rest_segs. iter( ) . all( |seg| seg. args. is_empty( ) ) ) ;
595
+ final_seg. args . into_json ( renderer)
596
+ } else {
597
+ None // no generics on any segments because there are no segments
598
+ }
599
+ } ,
584
600
}
585
601
}
586
602
}
@@ -591,7 +607,7 @@ impl FromClean<clean::QPathData> for Type {
591
607
592
608
Self :: QualifiedPath {
593
609
name : assoc. name . to_string ( ) ,
594
- args : Box :: new ( assoc. args . into_json ( renderer) ) ,
610
+ args : assoc. args . into_json ( renderer) ,
595
611
self_type : Box :: new ( self_type. into_json ( renderer) ) ,
596
612
trait_ : trait_. as_ref ( ) . map ( |trait_| trait_. into_json ( renderer) ) ,
597
613
}
0 commit comments