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