@@ -2141,15 +2141,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21412141 field : Ident ,
21422142 ) -> Ty < ' tcx > {
21432143 debug ! ( "check_field(expr: {:?}, base: {:?}, field: {:?})" , expr, base, field) ;
2144- let expr_t = self . check_expr ( base) ;
2145- let expr_t = self . structurally_resolved_type ( base. span , expr_t ) ;
2144+ let base_ty = self . check_expr ( base) ;
2145+ let base_ty = self . structurally_resolved_type ( base. span , base_ty ) ;
21462146 let mut private_candidate = None ;
2147- let mut autoderef = self . autoderef ( expr. span , expr_t ) ;
2148- while let Some ( ( base_t , _) ) = autoderef. next ( ) {
2149- debug ! ( "base_t : {:?}" , base_t ) ;
2150- match base_t . kind ( ) {
2147+ let mut autoderef = self . autoderef ( expr. span , base_ty ) ;
2148+ while let Some ( ( deref_base_ty , _) ) = autoderef. next ( ) {
2149+ debug ! ( "deref_base_ty : {:?}" , deref_base_ty ) ;
2150+ match deref_base_ty . kind ( ) {
21512151 ty:: Adt ( base_def, substs) if !base_def. is_enum ( ) => {
2152- debug ! ( "struct named {:?}" , base_t ) ;
2152+ debug ! ( "struct named {:?}" , deref_base_ty ) ;
21532153 let ( ident, def_scope) =
21542154 self . tcx . adjust_ident_and_get_scope ( field, base_def. did ( ) , self . body_id ) ;
21552155 let fields = & base_def. non_enum_variant ( ) . fields ;
@@ -2197,23 +2197,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21972197 // (#90483) apply adjustments to avoid ExprUseVisitor from
21982198 // creating erroneous projection.
21992199 self . apply_adjustments ( base, adjustments) ;
2200- self . ban_private_field_access ( expr, expr_t , field, did) ;
2200+ self . ban_private_field_access ( expr, base_ty , field, did) ;
22012201 return field_ty;
22022202 }
22032203
22042204 if field. name == kw:: Empty {
2205- } else if self . method_exists ( field, expr_t , expr. hir_id , true ) {
2206- self . ban_take_value_of_method ( expr, expr_t , field) ;
2207- } else if !expr_t . is_primitive_ty ( ) {
2208- self . ban_nonexisting_field ( field, base, expr, expr_t ) ;
2205+ } else if self . method_exists ( field, base_ty , expr. hir_id , true ) {
2206+ self . ban_take_value_of_method ( expr, base_ty , field) ;
2207+ } else if !base_ty . is_primitive_ty ( ) {
2208+ self . ban_nonexisting_field ( field, base, expr, base_ty ) ;
22092209 } else {
22102210 let field_name = field. to_string ( ) ;
22112211 let mut err = type_error_struct ! (
22122212 self . tcx( ) . sess,
22132213 field. span,
2214- expr_t ,
2214+ base_ty ,
22152215 E0610 ,
2216- "`{expr_t }` is a primitive type and therefore doesn't have fields" ,
2216+ "`{base_ty }` is a primitive type and therefore doesn't have fields" ,
22172217 ) ;
22182218 let is_valid_suffix = |field : & str | {
22192219 if field == "f32" || field == "f64" {
@@ -2251,7 +2251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22512251 None
22522252 }
22532253 } ;
2254- if let ty:: Infer ( ty:: IntVar ( _) ) = expr_t . kind ( )
2254+ if let ty:: Infer ( ty:: IntVar ( _) ) = base_ty . kind ( )
22552255 && let ExprKind :: Lit ( Spanned {
22562256 node : ast:: LitKind :: Int ( _, ast:: LitIntType :: Unsuffixed ) ,
22572257 ..
@@ -2351,40 +2351,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23512351
23522352 fn ban_nonexisting_field (
23532353 & self ,
2354- field : Ident ,
2354+ ident : Ident ,
23552355 base : & ' tcx hir:: Expr < ' tcx > ,
23562356 expr : & ' tcx hir:: Expr < ' tcx > ,
2357- expr_t : Ty < ' tcx > ,
2357+ base_ty : Ty < ' tcx > ,
23582358 ) {
23592359 debug ! (
2360- "ban_nonexisting_field: field={:?}, base={:?}, expr={:?}, expr_ty ={:?}" ,
2361- field , base, expr, expr_t
2360+ "ban_nonexisting_field: field={:?}, base={:?}, expr={:?}, base_ty ={:?}" ,
2361+ ident , base, expr, base_ty
23622362 ) ;
2363- let mut err = self . no_such_field_err ( field , expr_t , base. hir_id ) ;
2363+ let mut err = self . no_such_field_err ( ident , base_ty , base. hir_id ) ;
23642364
2365- match * expr_t . peel_refs ( ) . kind ( ) {
2365+ match * base_ty . peel_refs ( ) . kind ( ) {
23662366 ty:: Array ( _, len) => {
2367- self . maybe_suggest_array_indexing ( & mut err, expr, base, field , len) ;
2367+ self . maybe_suggest_array_indexing ( & mut err, expr, base, ident , len) ;
23682368 }
23692369 ty:: RawPtr ( ..) => {
2370- self . suggest_first_deref_field ( & mut err, expr, base, field ) ;
2370+ self . suggest_first_deref_field ( & mut err, expr, base, ident ) ;
23712371 }
23722372 ty:: Adt ( def, _) if !def. is_enum ( ) => {
2373- self . suggest_fields_on_recordish ( & mut err, def, field , expr. span ) ;
2373+ self . suggest_fields_on_recordish ( & mut err, def, ident , expr. span ) ;
23742374 }
23752375 ty:: Param ( param_ty) => {
23762376 self . point_at_param_definition ( & mut err, param_ty) ;
23772377 }
23782378 ty:: Opaque ( _, _) => {
2379- self . suggest_await_on_field_access ( & mut err, field , base, expr_t . peel_refs ( ) ) ;
2379+ self . suggest_await_on_field_access ( & mut err, ident , base, base_ty . peel_refs ( ) ) ;
23802380 }
23812381 ty:: FnDef ( def_id, _) => {
23822382 self . check_call_constructor ( & mut err, base, def_id) ;
23832383 }
23842384 _ => { }
23852385 }
23862386
2387- if field . name == kw:: Await {
2387+ if ident . name == kw:: Await {
23882388 // We know by construction that `<expr>.await` is either on Rust 2015
23892389 // or results in `ExprKind::Await`. Suggest switching the edition to 2018.
23902390 err. note ( "to `.await` a `Future`, switch to Rust 2018 or later" ) ;
0 commit comments