@@ -10,7 +10,6 @@ use std::ops::Index;
10
10
11
11
use base_db:: CrateId ;
12
12
use cfg:: { CfgExpr , CfgOptions } ;
13
- use either:: Either ;
14
13
use hir_expand:: { name:: Name , HirFileId , InFile } ;
15
14
use la_arena:: { Arena , ArenaMap } ;
16
15
use rustc_hash:: FxHashMap ;
@@ -45,7 +44,8 @@ pub struct Body {
45
44
///
46
45
/// If this `Body` is for the body of a constant, this will just be
47
46
/// empty.
48
- pub params : Vec < PatId > ,
47
+ pub params : Box < [ PatId ] > ,
48
+ pub self_param : Option < BindingId > ,
49
49
/// The `ExprId` of the actual body expression.
50
50
pub body_expr : ExprId ,
51
51
/// Block expressions in this body that may contain inner items.
@@ -55,14 +55,15 @@ pub struct Body {
55
55
pub type ExprPtr = AstPtr < ast:: Expr > ;
56
56
pub type ExprSource = InFile < ExprPtr > ;
57
57
58
- pub type PatPtr = AstPtr < Either < ast:: Pat , ast :: SelfParam > > ;
58
+ pub type PatPtr = AstPtr < ast:: Pat > ;
59
59
pub type PatSource = InFile < PatPtr > ;
60
60
61
61
pub type LabelPtr = AstPtr < ast:: Label > ;
62
62
pub type LabelSource = InFile < LabelPtr > ;
63
63
64
64
pub type FieldPtr = AstPtr < ast:: RecordExprField > ;
65
65
pub type FieldSource = InFile < FieldPtr > ;
66
+
66
67
pub type PatFieldPtr = AstPtr < ast:: RecordPatField > ;
67
68
pub type PatFieldSource = InFile < PatFieldPtr > ;
68
69
@@ -88,6 +89,8 @@ pub struct BodySourceMap {
88
89
label_map : FxHashMap < LabelSource , LabelId > ,
89
90
label_map_back : ArenaMap < LabelId , LabelSource > ,
90
91
92
+ self_param : Option < InFile < AstPtr < ast:: SelfParam > > > ,
93
+
91
94
/// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
92
95
/// Instead, we use id of expression (`92`) to identify the field.
93
96
field_map_back : FxHashMap < ExprId , FieldSource > ,
@@ -215,18 +218,18 @@ impl Body {
215
218
fn shrink_to_fit ( & mut self ) {
216
219
let Self {
217
220
body_expr : _,
221
+ params : _,
222
+ self_param : _,
218
223
block_scopes,
219
224
exprs,
220
225
labels,
221
- params,
222
226
pats,
223
227
bindings,
224
228
binding_owners,
225
229
} = self ;
226
230
block_scopes. shrink_to_fit ( ) ;
227
231
exprs. shrink_to_fit ( ) ;
228
232
labels. shrink_to_fit ( ) ;
229
- params. shrink_to_fit ( ) ;
230
233
pats. shrink_to_fit ( ) ;
231
234
bindings. shrink_to_fit ( ) ;
232
235
binding_owners. shrink_to_fit ( ) ;
@@ -297,6 +300,7 @@ impl Default for Body {
297
300
params : Default :: default ( ) ,
298
301
block_scopes : Default :: default ( ) ,
299
302
binding_owners : Default :: default ( ) ,
303
+ self_param : Default :: default ( ) ,
300
304
}
301
305
}
302
306
}
@@ -354,14 +358,12 @@ impl BodySourceMap {
354
358
self . pat_map_back . get ( pat) . cloned ( ) . ok_or ( SyntheticSyntax )
355
359
}
356
360
357
- pub fn node_pat ( & self , node : InFile < & ast:: Pat > ) -> Option < PatId > {
358
- let src = node. map ( |it| AstPtr :: new ( it) . wrap_left ( ) ) ;
359
- self . pat_map . get ( & src) . cloned ( )
361
+ pub fn self_param_syntax ( & self ) -> Option < InFile < AstPtr < ast:: SelfParam > > > {
362
+ self . self_param
360
363
}
361
364
362
- pub fn node_self_param ( & self , node : InFile < & ast:: SelfParam > ) -> Option < PatId > {
363
- let src = node. map ( |it| AstPtr :: new ( it) . wrap_right ( ) ) ;
364
- self . pat_map . get ( & src) . cloned ( )
365
+ pub fn node_pat ( & self , node : InFile < & ast:: Pat > ) -> Option < PatId > {
366
+ self . pat_map . get ( & node. map ( AstPtr :: new) ) . cloned ( )
365
367
}
366
368
367
369
pub fn label_syntax ( & self , label : LabelId ) -> LabelSource {
@@ -401,6 +403,7 @@ impl BodySourceMap {
401
403
402
404
fn shrink_to_fit ( & mut self ) {
403
405
let Self {
406
+ self_param : _,
404
407
expr_map,
405
408
expr_map_back,
406
409
pat_map,
0 commit comments