@@ -18,7 +18,8 @@ use rustc_ast_pretty::pprust::state::MacHeader;
18
18
use rustc_ast_pretty:: pprust:: { Comments , PrintState } ;
19
19
use rustc_hir:: {
20
20
BindingMode , ByRef , ConstArgKind , GenericArg , GenericBound , GenericParam , GenericParamKind ,
21
- HirId , LifetimeParamKind , Node , PatKind , PreciseCapturingArg , RangeEnd , Term , TyPatKind ,
21
+ HirId , ImplicitSelfKind , LifetimeParamKind , Node , PatKind , PreciseCapturingArg , RangeEnd , Term ,
22
+ TyPatKind ,
22
23
} ;
23
24
use rustc_span:: source_map:: SourceMap ;
24
25
use rustc_span:: { FileName , Ident , Span , Symbol , kw} ;
@@ -2086,6 +2087,28 @@ impl<'a> State<'a> {
2086
2087
self . print_pat ( arg. pat ) ;
2087
2088
}
2088
2089
2090
+ fn print_implicit_self ( & mut self , implicit_self_kind : & hir:: ImplicitSelfKind ) {
2091
+ match implicit_self_kind {
2092
+ ImplicitSelfKind :: Imm => {
2093
+ self . word ( "self" ) ;
2094
+ }
2095
+ ImplicitSelfKind :: Mut => {
2096
+ self . print_mutability ( hir:: Mutability :: Mut , false ) ;
2097
+ self . word ( "self" ) ;
2098
+ }
2099
+ ImplicitSelfKind :: RefImm => {
2100
+ self . word ( "&" ) ;
2101
+ self . word ( "self" ) ;
2102
+ }
2103
+ ImplicitSelfKind :: RefMut => {
2104
+ self . word ( "&" ) ;
2105
+ self . print_mutability ( hir:: Mutability :: Mut , false ) ;
2106
+ self . word ( "self" ) ;
2107
+ }
2108
+ ImplicitSelfKind :: None => unreachable ! ( ) ,
2109
+ }
2110
+ }
2111
+
2089
2112
fn print_arm ( & mut self , arm : & hir:: Arm < ' _ > ) {
2090
2113
// I have no idea why this check is necessary, but here it
2091
2114
// is :(
@@ -2151,27 +2174,33 @@ impl<'a> State<'a> {
2151
2174
// Make sure we aren't supplied *both* `arg_names` and `body_id`.
2152
2175
assert ! ( arg_names. is_empty( ) || body_id. is_none( ) ) ;
2153
2176
let mut i = 0 ;
2154
- let mut print_arg = |s : & mut Self | {
2155
- if let Some ( arg_name) = arg_names. get ( i) {
2156
- s. word ( arg_name. to_string ( ) ) ;
2157
- s. word ( ":" ) ;
2158
- s. space ( ) ;
2159
- } else if let Some ( body_id) = body_id {
2160
- s. ann . nested ( s, Nested :: BodyParamPat ( body_id, i) ) ;
2161
- s. word ( ":" ) ;
2162
- s. space ( ) ;
2177
+ let mut print_arg = |s : & mut Self , ty : Option < & hir:: Ty < ' _ > > | {
2178
+ if i == 0 && decl. implicit_self . has_implicit_self ( ) {
2179
+ s. print_implicit_self ( & decl. implicit_self ) ;
2180
+ } else {
2181
+ if let Some ( arg_name) = arg_names. get ( i) {
2182
+ s. word ( arg_name. to_string ( ) ) ;
2183
+ s. word ( ":" ) ;
2184
+ s. space ( ) ;
2185
+ } else if let Some ( body_id) = body_id {
2186
+ s. ann . nested ( s, Nested :: BodyParamPat ( body_id, i) ) ;
2187
+ s. word ( ":" ) ;
2188
+ s. space ( ) ;
2189
+ }
2190
+ if let Some ( ty) = ty {
2191
+ s. print_type ( ty) ;
2192
+ }
2163
2193
}
2164
2194
i += 1 ;
2165
2195
} ;
2166
2196
self . commasep ( Inconsistent , decl. inputs , |s, ty| {
2167
2197
s. ibox ( INDENT_UNIT ) ;
2168
- print_arg ( s) ;
2169
- s. print_type ( ty) ;
2198
+ print_arg ( s, Some ( ty) ) ;
2170
2199
s. end ( ) ;
2171
2200
} ) ;
2172
2201
if decl. c_variadic {
2173
2202
self . word ( ", " ) ;
2174
- print_arg ( self ) ;
2203
+ print_arg ( self , None ) ;
2175
2204
self . word ( "..." ) ;
2176
2205
}
2177
2206
self . pclose ( ) ;
@@ -2284,7 +2313,9 @@ impl<'a> State<'a> {
2284
2313
GenericBound :: Use ( args, _) => {
2285
2314
self . word ( "use <" ) ;
2286
2315
2287
- self . commasep ( Inconsistent , args, |s, arg| s. print_precise_capturing_arg ( * arg) ) ;
2316
+ self . commasep ( Inconsistent , * args, |s, arg| {
2317
+ s. print_precise_capturing_arg ( * arg)
2318
+ } ) ;
2288
2319
2289
2320
self . word ( ">" ) ;
2290
2321
}
@@ -2300,10 +2331,23 @@ impl<'a> State<'a> {
2300
2331
}
2301
2332
2302
2333
fn print_generic_params ( & mut self , generic_params : & [ GenericParam < ' _ > ] ) {
2303
- if !generic_params. is_empty ( ) {
2334
+ let is_lifetime_elided = |generic_param : & GenericParam < ' _ > | {
2335
+ matches ! (
2336
+ generic_param. kind,
2337
+ GenericParamKind :: Lifetime { kind: LifetimeParamKind :: Elided ( _) }
2338
+ )
2339
+ } ;
2340
+
2341
+ // We don't want to show elided lifetimes as they are compiler-inserted and not
2342
+ // expressible in surface level Rust.
2343
+ if !generic_params. is_empty ( ) && !generic_params. iter ( ) . all ( is_lifetime_elided) {
2304
2344
self . word ( "<" ) ;
2305
2345
2306
- self . commasep ( Inconsistent , generic_params, |s, param| s. print_generic_param ( param) ) ;
2346
+ self . commasep (
2347
+ Inconsistent ,
2348
+ generic_params. iter ( ) . filter ( |gp| !is_lifetime_elided ( gp) ) ,
2349
+ |s, param| s. print_generic_param ( param) ,
2350
+ ) ;
2307
2351
2308
2352
self . word ( ">" ) ;
2309
2353
}
0 commit comments