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