@@ -169,10 +169,13 @@ pub(crate) fn from_deprecation(deprecation: attrs::Deprecation) -> Deprecation {
169169 Deprecation { since, note : note. map ( |s| s. to_string ( ) ) }
170170}
171171
172- impl FromClean < clean:: GenericArgs > for GenericArgs {
172+ impl FromClean < clean:: GenericArgs > for Option < Box < GenericArgs > > {
173173 fn from_clean ( args : & clean:: GenericArgs , renderer : & JsonRenderer < ' _ > ) -> Self {
174174 use clean:: GenericArgs :: * ;
175- match args {
175+ if args. is_empty ( ) {
176+ return None ;
177+ }
178+ Some ( Box :: new ( match args {
176179 AngleBracketed { args, constraints } => GenericArgs :: AngleBracketed {
177180 args : args. into_json ( renderer) ,
178181 constraints : constraints. into_json ( renderer) ,
@@ -182,7 +185,7 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
182185 output : output. as_ref ( ) . map ( |a| a. as_ref ( ) . into_json ( renderer) ) ,
183186 } ,
184187 ReturnTypeNotation => GenericArgs :: ReturnTypeNotation ,
185- }
188+ } ) )
186189 }
187190}
188191
@@ -579,7 +582,20 @@ impl FromClean<clean::Path> for Path {
579582 Path {
580583 path : path. whole_name ( ) ,
581584 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+ } ,
583599 }
584600 }
585601}
@@ -590,7 +606,7 @@ impl FromClean<clean::QPathData> for Type {
590606
591607 Self :: QualifiedPath {
592608 name : assoc. name . to_string ( ) ,
593- args : Box :: new ( assoc. args . into_json ( renderer) ) ,
609+ args : assoc. args . into_json ( renderer) ,
594610 self_type : Box :: new ( self_type. into_json ( renderer) ) ,
595611 trait_ : trait_. as_ref ( ) . map ( |trait_| trait_. into_json ( renderer) ) ,
596612 }
0 commit comments