@@ -113,6 +113,7 @@ pub struct InferenceResult {
113
113
method_resolutions : FxHashMap < ExprId , Function > ,
114
114
/// For each field access expr, records the field it resolves to.
115
115
field_resolutions : FxHashMap < ExprId , StructField > ,
116
+ variant_resolutions : FxHashMap < ExprId , VariantDef > ,
116
117
/// For each associated item record what it resolves to
117
118
assoc_resolutions : FxHashMap < ExprOrPatId , ImplItem > ,
118
119
diagnostics : Vec < InferenceDiagnostic > ,
@@ -127,6 +128,9 @@ impl InferenceResult {
127
128
pub fn field_resolution ( & self , expr : ExprId ) -> Option < StructField > {
128
129
self . field_resolutions . get ( & expr) . copied ( )
129
130
}
131
+ pub fn variant_resolution ( & self , expr : ExprId ) -> Option < VariantDef > {
132
+ self . variant_resolutions . get ( & expr) . copied ( )
133
+ }
130
134
pub fn assoc_resolutions_for_expr ( & self , id : ExprId ) -> Option < ImplItem > {
131
135
self . assoc_resolutions . get ( & id. into ( ) ) . copied ( )
132
136
}
@@ -170,6 +174,7 @@ struct InferenceContext<'a, D: HirDatabase> {
170
174
obligations : Vec < Obligation > ,
171
175
method_resolutions : FxHashMap < ExprId , Function > ,
172
176
field_resolutions : FxHashMap < ExprId , StructField > ,
177
+ variant_resolutions : FxHashMap < ExprId , VariantDef > ,
173
178
assoc_resolutions : FxHashMap < ExprOrPatId , ImplItem > ,
174
179
type_of_expr : ArenaMap < ExprId , Ty > ,
175
180
type_of_pat : ArenaMap < PatId , Ty > ,
@@ -183,6 +188,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
183
188
InferenceContext {
184
189
method_resolutions : FxHashMap :: default ( ) ,
185
190
field_resolutions : FxHashMap :: default ( ) ,
191
+ variant_resolutions : FxHashMap :: default ( ) ,
186
192
assoc_resolutions : FxHashMap :: default ( ) ,
187
193
type_of_expr : ArenaMap :: default ( ) ,
188
194
type_of_pat : ArenaMap :: default ( ) ,
@@ -213,6 +219,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
213
219
InferenceResult {
214
220
method_resolutions : self . method_resolutions ,
215
221
field_resolutions : self . field_resolutions ,
222
+ variant_resolutions : self . variant_resolutions ,
216
223
assoc_resolutions : self . assoc_resolutions ,
217
224
type_of_expr : expr_types,
218
225
type_of_pat : pat_types,
@@ -232,6 +239,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
232
239
self . field_resolutions . insert ( expr, field) ;
233
240
}
234
241
242
+ fn write_variant_resolution ( & mut self , expr : ExprId , variant : VariantDef ) {
243
+ self . variant_resolutions . insert ( expr, variant) ;
244
+ }
245
+
235
246
fn write_assoc_resolution ( & mut self , id : ExprOrPatId , item : ImplItem ) {
236
247
self . assoc_resolutions . insert ( id, item) ;
237
248
}
@@ -1069,6 +1080,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1069
1080
}
1070
1081
Expr :: StructLit { path, fields, spread } => {
1071
1082
let ( ty, def_id) = self . resolve_variant ( path. as_ref ( ) ) ;
1083
+ if let Some ( variant) = def_id {
1084
+ self . write_variant_resolution ( tgt_expr, variant) ;
1085
+ }
1086
+
1072
1087
let substs = ty. substs ( ) . unwrap_or_else ( Substs :: empty) ;
1073
1088
for ( field_idx, field) in fields. iter ( ) . enumerate ( ) {
1074
1089
let field_ty = def_id
0 commit comments