@@ -10,7 +10,6 @@ use std::ops::Index;
1010
1111use base_db:: CrateId ;
1212use cfg:: { CfgExpr , CfgOptions } ;
13- use either:: Either ;
1413use hir_expand:: { name:: Name , HirFileId , InFile } ;
1514use la_arena:: { Arena , ArenaMap } ;
1615use rustc_hash:: FxHashMap ;
@@ -45,7 +44,8 @@ pub struct Body {
4544 ///
4645 /// If this `Body` is for the body of a constant, this will just be
4746 /// empty.
48- pub params : Vec < PatId > ,
47+ pub params : Box < [ PatId ] > ,
48+ pub self_param : Option < BindingId > ,
4949 /// The `ExprId` of the actual body expression.
5050 pub body_expr : ExprId ,
5151 /// Block expressions in this body that may contain inner items.
@@ -55,14 +55,15 @@ pub struct Body {
5555pub type ExprPtr = AstPtr < ast:: Expr > ;
5656pub type ExprSource = InFile < ExprPtr > ;
5757
58- pub type PatPtr = AstPtr < Either < ast:: Pat , ast :: SelfParam > > ;
58+ pub type PatPtr = AstPtr < ast:: Pat > ;
5959pub type PatSource = InFile < PatPtr > ;
6060
6161pub type LabelPtr = AstPtr < ast:: Label > ;
6262pub type LabelSource = InFile < LabelPtr > ;
6363
6464pub type FieldPtr = AstPtr < ast:: RecordExprField > ;
6565pub type FieldSource = InFile < FieldPtr > ;
66+
6667pub type PatFieldPtr = AstPtr < ast:: RecordPatField > ;
6768pub type PatFieldSource = InFile < PatFieldPtr > ;
6869
@@ -88,6 +89,8 @@ pub struct BodySourceMap {
8889 label_map : FxHashMap < LabelSource , LabelId > ,
8990 label_map_back : ArenaMap < LabelId , LabelSource > ,
9091
92+ self_param : Option < InFile < AstPtr < ast:: SelfParam > > > ,
93+
9194 /// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
9295 /// Instead, we use id of expression (`92`) to identify the field.
9396 field_map_back : FxHashMap < ExprId , FieldSource > ,
@@ -215,18 +218,18 @@ impl Body {
215218 fn shrink_to_fit ( & mut self ) {
216219 let Self {
217220 body_expr : _,
221+ params : _,
222+ self_param : _,
218223 block_scopes,
219224 exprs,
220225 labels,
221- params,
222226 pats,
223227 bindings,
224228 binding_owners,
225229 } = self ;
226230 block_scopes. shrink_to_fit ( ) ;
227231 exprs. shrink_to_fit ( ) ;
228232 labels. shrink_to_fit ( ) ;
229- params. shrink_to_fit ( ) ;
230233 pats. shrink_to_fit ( ) ;
231234 bindings. shrink_to_fit ( ) ;
232235 binding_owners. shrink_to_fit ( ) ;
@@ -297,6 +300,7 @@ impl Default for Body {
297300 params : Default :: default ( ) ,
298301 block_scopes : Default :: default ( ) ,
299302 binding_owners : Default :: default ( ) ,
303+ self_param : Default :: default ( ) ,
300304 }
301305 }
302306}
@@ -354,14 +358,12 @@ impl BodySourceMap {
354358 self . pat_map_back . get ( pat) . cloned ( ) . ok_or ( SyntheticSyntax )
355359 }
356360
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
360363 }
361364
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 ( )
365367 }
366368
367369 pub fn label_syntax ( & self , label : LabelId ) -> LabelSource {
@@ -401,6 +403,7 @@ impl BodySourceMap {
401403
402404 fn shrink_to_fit ( & mut self ) {
403405 let Self {
406+ self_param : _,
404407 expr_map,
405408 expr_map_back,
406409 pat_map,
0 commit comments