@@ -2303,77 +2303,82 @@ impl HirDisplayWithTypesMap for Path {
23032303 if let Some ( generic_args) = segment. args_and_bindings {
23042304 // We should be in type context, so format as `Foo<Bar>` instead of `Foo::<Bar>`.
23052305 // Do we actually format expressions?
2306- if generic_args. desugared_from_fn {
2307- // First argument will be a tuple, which already includes the parentheses.
2308- // If the tuple only contains 1 item, write it manually to avoid the trailing `,`.
2309- let tuple = match generic_args. args [ 0 ] {
2310- hir_def:: path:: GenericArg :: Type ( ty) => match & types_map[ ty] {
2311- TypeRef :: Tuple ( it) => Some ( it) ,
2306+ match generic_args. parenthesized {
2307+ hir_def:: path:: GenericArgsParentheses :: ReturnTypeNotation => {
2308+ write ! ( f, "(..)" ) ?;
2309+ }
2310+ hir_def:: path:: GenericArgsParentheses :: ParenSugar => {
2311+ // First argument will be a tuple, which already includes the parentheses.
2312+ // If the tuple only contains 1 item, write it manually to avoid the trailing `,`.
2313+ let tuple = match generic_args. args [ 0 ] {
2314+ hir_def:: path:: GenericArg :: Type ( ty) => match & types_map[ ty] {
2315+ TypeRef :: Tuple ( it) => Some ( it) ,
2316+ _ => None ,
2317+ } ,
23122318 _ => None ,
2313- } ,
2314- _ => None ,
2315- } ;
2316- if let Some ( v) = tuple {
2317- if v. len ( ) == 1 {
2318- write ! ( f, "(" ) ?;
2319- v[ 0 ] . hir_fmt ( f, types_map) ?;
2320- write ! ( f, ")" ) ?;
2321- } else {
2322- generic_args. args [ 0 ] . hir_fmt ( f, types_map) ?;
2319+ } ;
2320+ if let Some ( v) = tuple {
2321+ if v. len ( ) == 1 {
2322+ write ! ( f, "(" ) ?;
2323+ v[ 0 ] . hir_fmt ( f, types_map) ?;
2324+ write ! ( f, ")" ) ?;
2325+ } else {
2326+ generic_args. args [ 0 ] . hir_fmt ( f, types_map) ?;
2327+ }
23232328 }
2324- }
2325- if let Some ( ret) = generic_args . bindings [ 0 ] . type_ref {
2326- if ! matches ! ( & types_map [ ret ] , TypeRef :: Tuple ( v ) if v . is_empty ( ) ) {
2327- write ! ( f, " -> " ) ?;
2328- ret . hir_fmt ( f , types_map ) ? ;
2329+ if let Some ( ret ) = generic_args . bindings [ 0 ] . type_ref {
2330+ if ! matches ! ( & types_map [ ret] , TypeRef :: Tuple ( v ) if v . is_empty ( ) ) {
2331+ write ! ( f , " -> " ) ? ;
2332+ ret . hir_fmt ( f, types_map ) ?;
2333+ }
23292334 }
23302335 }
2331- return Ok ( ( ) ) ;
2332- }
2333-
2334- let mut first = true ;
2335- // Skip the `Self` bound if exists. It's handled outside the loop.
2336- for arg in & generic_args. args [ generic_args. has_self_type as usize ..] {
2337- if first {
2338- first = false ;
2339- write ! ( f, "<" ) ?;
2340- } else {
2341- write ! ( f, ", " ) ?;
2342- }
2343- arg. hir_fmt ( f, types_map) ?;
2344- }
2345- for binding in generic_args. bindings . iter ( ) {
2346- if first {
2347- first = false ;
2348- write ! ( f, "<" ) ?;
2349- } else {
2350- write ! ( f, ", " ) ?;
2351- }
2352- write ! ( f, "{}" , binding. name. display( f. db. upcast( ) , f. edition( ) ) ) ?;
2353- match & binding. type_ref {
2354- Some ( ty) => {
2355- write ! ( f, " = " ) ?;
2356- ty. hir_fmt ( f, types_map) ?
2336+ hir_def:: path:: GenericArgsParentheses :: No => {
2337+ let mut first = true ;
2338+ // Skip the `Self` bound if exists. It's handled outside the loop.
2339+ for arg in & generic_args. args [ generic_args. has_self_type as usize ..] {
2340+ if first {
2341+ first = false ;
2342+ write ! ( f, "<" ) ?;
2343+ } else {
2344+ write ! ( f, ", " ) ?;
2345+ }
2346+ arg. hir_fmt ( f, types_map) ?;
23572347 }
2358- None => {
2359- write ! ( f, ": " ) ?;
2360- f. write_joined (
2361- binding. bounds . iter ( ) . map ( TypesMapAdapter :: wrap ( types_map) ) ,
2362- " + " ,
2363- ) ?;
2348+ for binding in generic_args. bindings . iter ( ) {
2349+ if first {
2350+ first = false ;
2351+ write ! ( f, "<" ) ?;
2352+ } else {
2353+ write ! ( f, ", " ) ?;
2354+ }
2355+ write ! ( f, "{}" , binding. name. display( f. db. upcast( ) , f. edition( ) ) ) ?;
2356+ match & binding. type_ref {
2357+ Some ( ty) => {
2358+ write ! ( f, " = " ) ?;
2359+ ty. hir_fmt ( f, types_map) ?
2360+ }
2361+ None => {
2362+ write ! ( f, ": " ) ?;
2363+ f. write_joined (
2364+ binding. bounds . iter ( ) . map ( TypesMapAdapter :: wrap ( types_map) ) ,
2365+ " + " ,
2366+ ) ?;
2367+ }
2368+ }
23642369 }
2365- }
2366- }
23672370
2368- // There may be no generic arguments to print, in case of a trait having only a
2369- // single `Self` bound which is converted to `<Ty as Trait>::Assoc`.
2370- if !first {
2371- write ! ( f, ">" ) ?;
2372- }
2371+ // There may be no generic arguments to print, in case of a trait having only a
2372+ // single `Self` bound which is converted to `<Ty as Trait>::Assoc`.
2373+ if !first {
2374+ write ! ( f, ">" ) ?;
2375+ }
23732376
2374- // Current position: `<Ty as Trait<Args>|`
2375- if generic_args. has_self_type {
2376- write ! ( f, ">" ) ?;
2377+ // Current position: `<Ty as Trait<Args>|`
2378+ if generic_args. has_self_type {
2379+ write ! ( f, ">" ) ?;
2380+ }
2381+ }
23772382 }
23782383 }
23792384 }
0 commit comments