@@ -170,10 +170,13 @@ pub(crate) fn from_deprecation(deprecation: attrs::Deprecation) -> Deprecation {
170170    Deprecation  {  since,  note :  note. map ( |s| s. to_string ( ) )  } 
171171} 
172172
173- impl  FromClean < clean:: GenericArgs >  for  GenericArgs  { 
173+ impl  FromClean < clean:: GenericArgs >  for  Option < Box < GenericArgs > >  { 
174174    fn  from_clean ( args :  & clean:: GenericArgs ,  renderer :  & JsonRenderer < ' _ > )  -> Self  { 
175175        use  clean:: GenericArgs :: * ; 
176-         match  args { 
176+         if  args. is_empty ( )  { 
177+             return  None ; 
178+         } 
179+         Some ( Box :: new ( match  args { 
177180            AngleBracketed  {  args,  constraints }  => GenericArgs :: AngleBracketed  { 
178181                args :  args. into_json ( renderer) , 
179182                constraints :  constraints. into_json ( renderer) , 
@@ -183,7 +186,7 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
183186                output :  output. as_ref ( ) . map ( |a| a. as_ref ( ) . into_json ( renderer) ) , 
184187            } , 
185188            ReturnTypeNotation  => GenericArgs :: ReturnTypeNotation , 
186-         } 
189+         } ) ) 
187190    } 
188191} 
189192
@@ -580,7 +583,20 @@ impl FromClean<clean::Path> for Path {
580583        Path  { 
581584            path :  path. whole_name ( ) , 
582585            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+             } , 
584600        } 
585601    } 
586602} 
@@ -591,7 +607,7 @@ impl FromClean<clean::QPathData> for Type {
591607
592608        Self :: QualifiedPath  { 
593609            name :  assoc. name . to_string ( ) , 
594-             args :  Box :: new ( assoc. args . into_json ( renderer) ) , 
610+             args :  assoc. args . into_json ( renderer) , 
595611            self_type :  Box :: new ( self_type. into_json ( renderer) ) , 
596612            trait_ :  trait_. as_ref ( ) . map ( |trait_| trait_. into_json ( renderer) ) , 
597613        } 
0 commit comments