File tree 1 file changed +16
-3
lines changed
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1164,10 +1164,23 @@ impl HirDisplay for Path {
1164
1164
// Do we actually format expressions?
1165
1165
if generic_args. desugared_from_fn {
1166
1166
// First argument will be a tuple, which already includes the parentheses.
1167
- generic_args. args [ 0 ] . hir_fmt ( f) ?;
1167
+ // If the tuple only contains 1 item, write it manually to avoid the trailing `,`.
1168
+ if let hir_def:: path:: GenericArg :: Type ( TypeRef :: Tuple ( v) ) =
1169
+ & generic_args. args [ 0 ]
1170
+ {
1171
+ if v. len ( ) == 1 {
1172
+ write ! ( f, "(" ) ?;
1173
+ v[ 0 ] . hir_fmt ( f) ?;
1174
+ write ! ( f, ")" ) ?;
1175
+ } else {
1176
+ generic_args. args [ 0 ] . hir_fmt ( f) ?;
1177
+ }
1178
+ }
1168
1179
if let Some ( ret) = & generic_args. bindings [ 0 ] . type_ref {
1169
- write ! ( f, " -> " ) ?;
1170
- ret. hir_fmt ( f) ?;
1180
+ if !matches ! ( ret, TypeRef :: Tuple ( v) if v. is_empty( ) ) {
1181
+ write ! ( f, " -> " ) ?;
1182
+ ret. hir_fmt ( f) ?;
1183
+ }
1171
1184
}
1172
1185
return Ok ( ( ) ) ;
1173
1186
}
You can’t perform that action at this time.
0 commit comments