@@ -47,6 +47,7 @@ use rustc_errors::ErrorGuaranteed;
47
47
use rustc_hir:: def_id:: DefId ;
48
48
use rustc_middle:: span_bug;
49
49
use rustc_middle:: ty:: { Asyncness , ResolverAstLowering } ;
50
+ use rustc_span:: symbol:: kw;
50
51
use rustc_span:: { Ident , Span , Symbol } ;
51
52
use { rustc_ast as ast, rustc_hir as hir} ;
52
53
@@ -101,10 +102,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
101
102
let sig_id = self . get_delegation_sig_id ( item_id, delegation. id , span, is_in_trait_impl) ;
102
103
match sig_id {
103
104
Ok ( sig_id) => {
105
+ let is_method = self . is_method ( sig_id, span) ;
104
106
let ( param_count, c_variadic) = self . param_count ( sig_id) ;
105
107
let decl = self . lower_delegation_decl ( sig_id, param_count, c_variadic, span) ;
106
108
let sig = self . lower_delegation_sig ( sig_id, decl, span) ;
107
- let body_id = self . lower_delegation_body ( delegation, param_count, span) ;
109
+ let body_id = self . lower_delegation_body ( delegation, is_method , param_count, span) ;
108
110
let ident = self . lower_ident ( delegation. ident ) ;
109
111
let generics = self . lower_delegation_generics ( span) ;
110
112
DelegationResults { body_id, sig, ident, generics }
@@ -234,10 +236,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
234
236
hir:: FnSig { decl, header, span }
235
237
}
236
238
237
- fn generate_param ( & mut self , idx : usize , span : Span ) -> ( hir:: Param < ' hir > , NodeId ) {
239
+ fn generate_param (
240
+ & mut self ,
241
+ is_method : bool ,
242
+ idx : usize ,
243
+ span : Span ,
244
+ ) -> ( hir:: Param < ' hir > , NodeId ) {
238
245
let pat_node_id = self . next_node_id ( ) ;
239
246
let pat_id = self . lower_node_id ( pat_node_id) ;
240
- let ident = Ident :: with_dummy_span ( Symbol :: intern ( & format ! ( "arg{idx}" ) ) ) ;
247
+ // FIXME(cjgillot) AssocItem currently relies on self parameter being exactly named `self`.
248
+ let name = if is_method && idx == 0 {
249
+ kw:: SelfLower
250
+ } else {
251
+ Symbol :: intern ( & format ! ( "arg{idx}" ) )
252
+ } ;
253
+ let ident = Ident :: with_dummy_span ( name) ;
241
254
let pat = self . arena . alloc ( hir:: Pat {
242
255
hir_id : pat_id,
243
256
kind : hir:: PatKind :: Binding ( hir:: BindingMode :: NONE , pat_id, ident, None ) ,
@@ -248,9 +261,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
248
261
( hir:: Param { hir_id : self . next_id ( ) , pat, ty_span : span, span } , pat_node_id)
249
262
}
250
263
251
- fn generate_arg ( & mut self , idx : usize , param_id : HirId , span : Span ) -> hir:: Expr < ' hir > {
264
+ fn generate_arg (
265
+ & mut self ,
266
+ is_method : bool ,
267
+ idx : usize ,
268
+ param_id : HirId ,
269
+ span : Span ,
270
+ ) -> hir:: Expr < ' hir > {
271
+ // FIXME(cjgillot) AssocItem currently relies on self parameter being exactly named `self`.
272
+ let name = if is_method && idx == 0 {
273
+ kw:: SelfLower
274
+ } else {
275
+ Symbol :: intern ( & format ! ( "arg{idx}" ) )
276
+ } ;
252
277
let segments = self . arena . alloc_from_iter ( iter:: once ( hir:: PathSegment {
253
- ident : Ident :: with_dummy_span ( Symbol :: intern ( & format ! ( "arg{idx}" ) ) ) ,
278
+ ident : Ident :: with_dummy_span ( name ) ,
254
279
hir_id : self . next_id ( ) ,
255
280
res : Res :: Local ( param_id) ,
256
281
args : None ,
@@ -264,6 +289,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
264
289
fn lower_delegation_body (
265
290
& mut self ,
266
291
delegation : & Delegation ,
292
+ is_method : bool ,
267
293
param_count : usize ,
268
294
span : Span ,
269
295
) -> BodyId {
@@ -274,7 +300,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
274
300
let mut args: Vec < hir:: Expr < ' _ > > = Vec :: with_capacity ( param_count) ;
275
301
276
302
for idx in 0 ..param_count {
277
- let ( param, pat_node_id) = this. generate_param ( idx, span) ;
303
+ let ( param, pat_node_id) = this. generate_param ( is_method , idx, span) ;
278
304
parameters. push ( param) ;
279
305
280
306
let arg = if let Some ( block) = block
@@ -290,7 +316,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
290
316
this. ident_and_label_to_local_id . insert ( pat_node_id, param. pat . hir_id . local_id ) ;
291
317
this. lower_target_expr ( & block)
292
318
} else {
293
- this. generate_arg ( idx, param. pat . hir_id , span)
319
+ this. generate_arg ( is_method , idx, param. pat . hir_id , span)
294
320
} ;
295
321
args. push ( arg) ;
296
322
}
0 commit comments