]> git.lizzy.rs Git - rust.git/commitdiff
hir_ty: don't call write_field_resolution when field candidate isn't visible
authorcynecx <me@cynecx.net>
Wed, 24 Mar 2021 22:03:30 +0000 (23:03 +0100)
committercynecx <me@cynecx.net>
Wed, 24 Mar 2021 22:03:38 +0000 (23:03 +0100)
crates/hir_ty/src/infer/expr.rs

index b08880cdf07851155e4f6a9b770c3439eae67688..46d713a7b1d7140deb4791e88b03d1bdd2dedff8 100644 (file)
@@ -459,9 +459,8 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
                         TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
                             let local_id = self.db.struct_data(*s).variant_data.field(name)?;
                             let field = FieldId { parent: (*s).into(), local_id };
-                            let is_visible_in_ctx = is_visible(&field);
-                            self.write_field_resolution(tgt_expr, field);
-                            if is_visible_in_ctx {
+                            if is_visible(&field) {
+                                self.write_field_resolution(tgt_expr, field);
                                 Some(
                                     self.db.field_types((*s).into())[field.local_id]
                                         .clone()
@@ -474,9 +473,8 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
                         TyKind::Adt(AdtId(hir_def::AdtId::UnionId(u)), parameters) => {
                             let local_id = self.db.union_data(*u).variant_data.field(name)?;
                             let field = FieldId { parent: (*u).into(), local_id };
-                            let is_visible_in_ctx = is_visible(&field);
-                            self.write_field_resolution(tgt_expr, field);
-                            if is_visible_in_ctx {
+                            if is_visible(&field) {
+                                self.write_field_resolution(tgt_expr, field);
                                 Some(
                                     self.db.field_types((*u).into())[field.local_id]
                                         .clone()