@@ -1390,33 +1390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13901390 } else if self . method_exists ( field, expr_t, expr. hir_id , true ) {
13911391 self . ban_take_value_of_method ( expr, expr_t, field) ;
13921392 } else if !expr_t. is_primitive_ty ( ) {
1393- let mut err = self . no_such_field_err ( field. span , field, expr_t) ;
1394-
1395- match expr_t. peel_refs ( ) . kind {
1396- ty:: Array ( _, len) => {
1397- self . maybe_suggest_array_indexing ( & mut err, expr, base, field, len) ;
1398- }
1399- ty:: RawPtr ( ..) => {
1400- self . suggest_first_deref_field ( & mut err, expr, base, field) ;
1401- }
1402- ty:: Adt ( def, _) if !def. is_enum ( ) => {
1403- self . suggest_fields_on_recordish ( & mut err, def, field) ;
1404- }
1405- ty:: Param ( param_ty) => {
1406- self . point_at_param_definition ( & mut err, param_ty) ;
1407- }
1408- _ => { }
1409- }
1410-
1411- if field. name == kw:: Await {
1412- // We know by construction that `<expr>.await` is either on Rust 2015
1413- // or results in `ExprKind::Await`. Suggest switching the edition to 2018.
1414- err. note ( "to `.await` a `Future`, switch to Rust 2018" ) ;
1415- err. help ( "set `edition = \" 2018\" ` in `Cargo.toml`" ) ;
1416- err. note ( "for more on editions, read https://doc.rust-lang.org/edition-guide" ) ;
1417- }
1418-
1419- err. emit ( ) ;
1393+ self . ban_nonexisting_field ( field, base, expr, expr_t) ;
14201394 } else {
14211395 type_error_struct ! (
14221396 self . tcx( ) . sess,
@@ -1432,6 +1406,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14321406 self . tcx ( ) . types . err
14331407 }
14341408
1409+ fn ban_nonexisting_field (
1410+ & self ,
1411+ field : ast:: Ident ,
1412+ base : & ' tcx hir:: Expr ,
1413+ expr : & ' tcx hir:: Expr ,
1414+ expr_t : Ty < ' tcx > ,
1415+ ) {
1416+ let mut err = self . no_such_field_err ( field. span , field, expr_t) ;
1417+
1418+ match expr_t. peel_refs ( ) . kind {
1419+ ty:: Array ( _, len) => {
1420+ self . maybe_suggest_array_indexing ( & mut err, expr, base, field, len) ;
1421+ }
1422+ ty:: RawPtr ( ..) => {
1423+ self . suggest_first_deref_field ( & mut err, expr, base, field) ;
1424+ }
1425+ ty:: Adt ( def, _) if !def. is_enum ( ) => {
1426+ self . suggest_fields_on_recordish ( & mut err, def, field) ;
1427+ }
1428+ ty:: Param ( param_ty) => {
1429+ self . point_at_param_definition ( & mut err, param_ty) ;
1430+ }
1431+ _ => { }
1432+ }
1433+
1434+ if field. name == kw:: Await {
1435+ // We know by construction that `<expr>.await` is either on Rust 2015
1436+ // or results in `ExprKind::Await`. Suggest switching the edition to 2018.
1437+ err. note ( "to `.await` a `Future`, switch to Rust 2018" ) ;
1438+ err. help ( "set `edition = \" 2018\" ` in `Cargo.toml`" ) ;
1439+ err. note ( "for more on editions, read https://doc.rust-lang.org/edition-guide" ) ;
1440+ }
1441+
1442+ err. emit ( ) ;
1443+ }
1444+
14351445 fn ban_private_field_access (
14361446 & self ,
14371447 expr : & hir:: Expr ,
0 commit comments