@@ -93,7 +93,7 @@ pub type TypeSource = InFile<TypePtr>;
9393pub type LifetimePtr = AstPtr < ast:: Lifetime > ;
9494pub type LifetimeSource = InFile < LifetimePtr > ;
9595
96- #[ derive( Debug , Eq , PartialEq ) ]
96+ #[ derive( Debug , PartialEq , Eq ) ]
9797pub struct ExpressionStore {
9898 pub exprs : Arena < Expr > ,
9999 pub pats : Arena < Pat > ,
@@ -114,7 +114,7 @@ pub struct ExpressionStore {
114114 ident_hygiene : FxHashMap < ExprOrPatId , HygieneId > ,
115115}
116116
117- #[ derive( Debug , Eq , PartialEq , Default ) ]
117+ #[ derive( Debug , Eq , Default ) ]
118118pub struct ExpressionStoreSourceMap {
119119 // AST expressions can create patterns in destructuring assignments. Therefore, `ExprSource` can also map
120120 // to `PatId`, and `PatId` can also map to `ExprSource` (the other way around is unaffected).
@@ -127,19 +127,20 @@ pub struct ExpressionStoreSourceMap {
127127 label_map : FxHashMap < LabelSource , LabelId > ,
128128 label_map_back : ArenaMap < LabelId , LabelSource > ,
129129
130- binding_definitions : FxHashMap < BindingId , SmallVec < [ PatId ; 4 ] > > ,
131-
132- /// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
133- /// Instead, we use id of expression (`92`) to identify the field.
134- field_map_back : FxHashMap < ExprId , FieldSource > ,
135- pat_field_map_back : FxHashMap < PatId , PatFieldSource > ,
136-
137130 types_map_back : ArenaMap < TypeRefId , TypeSource > ,
138131 types_map : FxHashMap < TypeSource , TypeRefId > ,
139132
140133 lifetime_map_back : ArenaMap < LifetimeRefId , LifetimeSource > ,
141134 lifetime_map : FxHashMap < LifetimeSource , LifetimeRefId > ,
142135
136+ binding_definitions :
137+ ArenaMap < BindingId , SmallVec < [ PatId ; 2 * size_of :: < usize > ( ) / size_of :: < PatId > ( ) ] > > ,
138+
139+ /// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
140+ /// Instead, we use id of expression (`92`) to identify the field.
141+ field_map_back : FxHashMap < ExprId , FieldSource > ,
142+ pat_field_map_back : FxHashMap < PatId , PatFieldSource > ,
143+
143144 template_map : Option < Box < FormatTemplate > > ,
144145
145146 pub expansions : FxHashMap < InFile < MacroCallPtr > , MacroCallId > ,
@@ -149,6 +150,43 @@ pub struct ExpressionStoreSourceMap {
149150 pub diagnostics : Vec < ExpressionStoreDiagnostics > ,
150151}
151152
153+ impl PartialEq for ExpressionStoreSourceMap {
154+ fn eq ( & self , other : & Self ) -> bool {
155+ // we only need to compare one of the two mappings
156+ // as the other is a reverse mapping and thus will compare
157+ // the same as normal mapping
158+ let Self {
159+ expr_map : _,
160+ expr_map_back,
161+ pat_map : _,
162+ pat_map_back,
163+ label_map : _,
164+ label_map_back,
165+ types_map_back,
166+ types_map : _,
167+ lifetime_map_back,
168+ lifetime_map : _,
169+ // If this changed, our pattern data must have changed
170+ binding_definitions : _,
171+ // If this changed, our expression data must have changed
172+ field_map_back : _,
173+ // If this changed, our pattern data must have changed
174+ pat_field_map_back : _,
175+ template_map,
176+ expansions,
177+ diagnostics,
178+ } = self ;
179+ * expr_map_back == other. expr_map_back
180+ && * pat_map_back == other. pat_map_back
181+ && * label_map_back == other. label_map_back
182+ && * types_map_back == other. types_map_back
183+ && * lifetime_map_back == other. lifetime_map_back
184+ && * template_map == other. template_map
185+ && * expansions == other. expansions
186+ && * diagnostics == other. diagnostics
187+ }
188+ }
189+
152190/// The body of an item (function, const etc.).
153191#[ derive( Debug , Eq , PartialEq , Default ) ]
154192pub struct ExpressionStoreBuilder {
@@ -698,7 +736,7 @@ impl ExpressionStoreSourceMap {
698736 }
699737
700738 pub fn patterns_for_binding ( & self , binding : BindingId ) -> & [ PatId ] {
701- self . binding_definitions . get ( & binding) . map_or ( & [ ] , Deref :: deref)
739+ self . binding_definitions . get ( binding) . map_or ( & [ ] , Deref :: deref)
702740 }
703741
704742 pub fn node_label ( & self , node : InFile < & ast:: Label > ) -> Option < LabelId > {
0 commit comments