about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2021-11-02 17:20:21 +0000
committerGary Guo <gary@garyguo.net>2021-11-02 17:22:12 +0000
commitf5560754591532d7cde4c9f5dd51dfbd7670e98f (patch)
tree0ab2dcd3dcb4d3e96ae29aa7e595d54aefe35354 /compiler
parentdb062de72b0a064f45b6f86894cbdc7c0ec68844 (diff)
downloadrust-f5560754591532d7cde4c9f5dd51dfbd7670e98f.tar.gz
rust-f5560754591532d7cde4c9f5dd51dfbd7670e98f.zip
Apply adjustments for field expression even if inaccessible
The adjustments are used later by ExprUseVisitor to build Place projections
and without adjustments it can produce invalid result.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs
index 3846aad2cfc..2d0a4068fbb 100644
--- a/compiler/rustc_typeck/src/check/expr.rs
+++ b/compiler/rustc_typeck/src/check/expr.rs
@@ -1698,15 +1698,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         // Save the index of all fields regardless of their visibility in case
                         // of error recovery.
                         self.write_field_index(expr.hir_id, index);
+                        let adjustments = self.adjust_steps(&autoderef);
                         if field.vis.is_accessible_from(def_scope, self.tcx) {
-                            let adjustments = self.adjust_steps(&autoderef);
                             self.apply_adjustments(base, adjustments);
                             self.register_predicates(autoderef.into_obligations());
 
                             self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
                             return field_ty;
                         }
-                        private_candidate = Some((base_def.did, field_ty));
+                        private_candidate = Some((adjustments, base_def.did, field_ty));
                     }
                 }
                 ty::Tuple(tys) => {
@@ -1729,7 +1729,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         }
         self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
 
-        if let Some((did, field_ty)) = private_candidate {
+        if let Some((adjustments, did, field_ty)) = private_candidate {
+            // (#90483) apply adjustments to avoid ExprUseVisitor from
+            // creating erroneous projection.
+            self.apply_adjustments(base, adjustments);
             self.ban_private_field_access(expr, expr_t, field, did);
             return field_ty;
         }