Drive-by: Rename expr_t to base_ty

This commit is contained in:
Michael Goulet 2022-08-27 20:56:14 +00:00
parent 332cc8fb75
commit dca5f5bf8f

View File

@ -2141,15 +2141,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
field: Ident, field: Ident,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!("check_field(expr: {:?}, base: {:?}, field: {:?})", expr, base, field); debug!("check_field(expr: {:?}, base: {:?}, field: {:?})", expr, base, field);
let expr_t = self.check_expr(base); let base_ty = self.check_expr(base);
let expr_t = self.structurally_resolved_type(base.span, expr_t); let base_ty = self.structurally_resolved_type(base.span, base_ty);
let mut private_candidate = None; let mut private_candidate = None;
let mut autoderef = self.autoderef(expr.span, expr_t); let mut autoderef = self.autoderef(expr.span, base_ty);
while let Some((base_t, _)) = autoderef.next() { while let Some((deref_base_ty, _)) = autoderef.next() {
debug!("base_t: {:?}", base_t); debug!("deref_base_ty: {:?}", deref_base_ty);
match base_t.kind() { match deref_base_ty.kind() {
ty::Adt(base_def, substs) if !base_def.is_enum() => { ty::Adt(base_def, substs) if !base_def.is_enum() => {
debug!("struct named {:?}", base_t); debug!("struct named {:?}", deref_base_ty);
let (ident, def_scope) = let (ident, def_scope) =
self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id); self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id);
let fields = &base_def.non_enum_variant().fields; let fields = &base_def.non_enum_variant().fields;
@ -2197,23 +2197,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (#90483) apply adjustments to avoid ExprUseVisitor from // (#90483) apply adjustments to avoid ExprUseVisitor from
// creating erroneous projection. // creating erroneous projection.
self.apply_adjustments(base, adjustments); self.apply_adjustments(base, adjustments);
self.ban_private_field_access(expr, expr_t, field, did); self.ban_private_field_access(expr, base_ty, field, did);
return field_ty; return field_ty;
} }
if field.name == kw::Empty { if field.name == kw::Empty {
} else if self.method_exists(field, expr_t, expr.hir_id, true) { } else if self.method_exists(field, base_ty, expr.hir_id, true) {
self.ban_take_value_of_method(expr, expr_t, field); self.ban_take_value_of_method(expr, base_ty, field);
} else if !expr_t.is_primitive_ty() { } else if !base_ty.is_primitive_ty() {
self.ban_nonexisting_field(field, base, expr, expr_t); self.ban_nonexisting_field(field, base, expr, base_ty);
} else { } else {
let field_name = field.to_string(); let field_name = field.to_string();
let mut err = type_error_struct!( let mut err = type_error_struct!(
self.tcx().sess, self.tcx().sess,
field.span, field.span,
expr_t, base_ty,
E0610, E0610,
"`{expr_t}` is a primitive type and therefore doesn't have fields", "`{base_ty}` is a primitive type and therefore doesn't have fields",
); );
let is_valid_suffix = |field: &str| { let is_valid_suffix = |field: &str| {
if field == "f32" || field == "f64" { if field == "f32" || field == "f64" {
@ -2251,7 +2251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None None
} }
}; };
if let ty::Infer(ty::IntVar(_)) = expr_t.kind() if let ty::Infer(ty::IntVar(_)) = base_ty.kind()
&& let ExprKind::Lit(Spanned { && let ExprKind::Lit(Spanned {
node: ast::LitKind::Int(_, ast::LitIntType::Unsuffixed), node: ast::LitKind::Int(_, ast::LitIntType::Unsuffixed),
.. ..
@ -2351,32 +2351,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn ban_nonexisting_field( fn ban_nonexisting_field(
&self, &self,
field: Ident, ident: Ident,
base: &'tcx hir::Expr<'tcx>, base: &'tcx hir::Expr<'tcx>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
expr_t: Ty<'tcx>, base_ty: Ty<'tcx>,
) { ) {
debug!( debug!(
"ban_nonexisting_field: field={:?}, base={:?}, expr={:?}, expr_ty={:?}", "ban_nonexisting_field: field={:?}, base={:?}, expr={:?}, base_ty={:?}",
field, base, expr, expr_t ident, base, expr, base_ty
); );
let mut err = self.no_such_field_err(field, expr_t, base.hir_id); let mut err = self.no_such_field_err(ident, base_ty, base.hir_id);
match *expr_t.peel_refs().kind() { match *base_ty.peel_refs().kind() {
ty::Array(_, len) => { ty::Array(_, len) => {
self.maybe_suggest_array_indexing(&mut err, expr, base, field, len); self.maybe_suggest_array_indexing(&mut err, expr, base, ident, len);
} }
ty::RawPtr(..) => { ty::RawPtr(..) => {
self.suggest_first_deref_field(&mut err, expr, base, field); self.suggest_first_deref_field(&mut err, expr, base, ident);
} }
ty::Adt(def, _) if !def.is_enum() => { ty::Adt(def, _) if !def.is_enum() => {
self.suggest_fields_on_recordish(&mut err, def, field, expr.span); self.suggest_fields_on_recordish(&mut err, def, ident, expr.span);
} }
ty::Param(param_ty) => { ty::Param(param_ty) => {
self.point_at_param_definition(&mut err, param_ty); self.point_at_param_definition(&mut err, param_ty);
} }
ty::Opaque(_, _) => { ty::Opaque(_, _) => {
self.suggest_await_on_field_access(&mut err, field, base, expr_t.peel_refs()); self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
} }
ty::FnDef(def_id, _) => { ty::FnDef(def_id, _) => {
self.check_call_constructor(&mut err, base, def_id); self.check_call_constructor(&mut err, base, def_id);
@ -2384,7 +2384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => {} _ => {}
} }
if field.name == kw::Await { if ident.name == kw::Await {
// We know by construction that `<expr>.await` is either on Rust 2015 // We know by construction that `<expr>.await` is either on Rust 2015
// or results in `ExprKind::Await`. Suggest switching the edition to 2018. // or results in `ExprKind::Await`. Suggest switching the edition to 2018.
err.note("to `.await` a `Future`, switch to Rust 2018 or later"); err.note("to `.await` a `Future`, switch to Rust 2018 or later");