@@ -2141,15 +2141,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2141
2141
field : Ident ,
2142
2142
) -> Ty < ' tcx > {
2143
2143
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 ) ;
2146
2146
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 ( ) {
2151
2151
ty:: Adt ( base_def, substs) if !base_def. is_enum ( ) => {
2152
- debug ! ( "struct named {:?}" , base_t ) ;
2152
+ debug ! ( "struct named {:?}" , deref_base_ty ) ;
2153
2153
let ( ident, def_scope) =
2154
2154
self . tcx . adjust_ident_and_get_scope ( field, base_def. did ( ) , self . body_id ) ;
2155
2155
let fields = & base_def. non_enum_variant ( ) . fields ;
@@ -2197,23 +2197,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2197
2197
// (#90483) apply adjustments to avoid ExprUseVisitor from
2198
2198
// creating erroneous projection.
2199
2199
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) ;
2201
2201
return field_ty;
2202
2202
}
2203
2203
2204
2204
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 ) ;
2209
2209
} else {
2210
2210
let field_name = field. to_string ( ) ;
2211
2211
let mut err = type_error_struct ! (
2212
2212
self . tcx( ) . sess,
2213
2213
field. span,
2214
- expr_t ,
2214
+ base_ty ,
2215
2215
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" ,
2217
2217
) ;
2218
2218
let is_valid_suffix = |field : & str | {
2219
2219
if field == "f32" || field == "f64" {
@@ -2251,7 +2251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2251
2251
None
2252
2252
}
2253
2253
} ;
2254
- if let ty:: Infer ( ty:: IntVar ( _) ) = expr_t . kind ( )
2254
+ if let ty:: Infer ( ty:: IntVar ( _) ) = base_ty . kind ( )
2255
2255
&& let ExprKind :: Lit ( Spanned {
2256
2256
node : ast:: LitKind :: Int ( _, ast:: LitIntType :: Unsuffixed ) ,
2257
2257
..
@@ -2351,40 +2351,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2351
2351
2352
2352
fn ban_nonexisting_field (
2353
2353
& self ,
2354
- field : Ident ,
2354
+ ident : Ident ,
2355
2355
base : & ' tcx hir:: Expr < ' tcx > ,
2356
2356
expr : & ' tcx hir:: Expr < ' tcx > ,
2357
- expr_t : Ty < ' tcx > ,
2357
+ base_ty : Ty < ' tcx > ,
2358
2358
) {
2359
2359
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
2362
2362
) ;
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 ) ;
2364
2364
2365
- match * expr_t . peel_refs ( ) . kind ( ) {
2365
+ match * base_ty . peel_refs ( ) . kind ( ) {
2366
2366
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) ;
2368
2368
}
2369
2369
ty:: RawPtr ( ..) => {
2370
- self . suggest_first_deref_field ( & mut err, expr, base, field ) ;
2370
+ self . suggest_first_deref_field ( & mut err, expr, base, ident ) ;
2371
2371
}
2372
2372
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 ) ;
2374
2374
}
2375
2375
ty:: Param ( param_ty) => {
2376
2376
self . point_at_param_definition ( & mut err, param_ty) ;
2377
2377
}
2378
2378
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 ( ) ) ;
2380
2380
}
2381
2381
ty:: FnDef ( def_id, _) => {
2382
2382
self . check_call_constructor ( & mut err, base, def_id) ;
2383
2383
}
2384
2384
_ => { }
2385
2385
}
2386
2386
2387
- if field . name == kw:: Await {
2387
+ if ident . name == kw:: Await {
2388
2388
// We know by construction that `<expr>.await` is either on Rust 2015
2389
2389
// or results in `ExprKind::Await`. Suggest switching the edition to 2018.
2390
2390
err. note ( "to `.await` a `Future`, switch to Rust 2018 or later" ) ;
0 commit comments