@@ -2191,7 +2191,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2191
2191
if let Some ( field_name) =
2192
2192
find_best_match_for_name ( & available_field_names, field. ident . name , None )
2193
2193
{
2194
- err. span_suggestion (
2194
+ err. span_label ( field. ident . span , "unknown field" ) ;
2195
+ err. span_suggestion_verbose (
2195
2196
field. ident . span ,
2196
2197
"a field with a similar name exists" ,
2197
2198
field_name,
@@ -2420,30 +2421,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2420
2421
ty : Ty < ' tcx > ,
2421
2422
) {
2422
2423
let Some ( output_ty) = self . get_impl_future_output_ty ( ty) else {
2424
+ err. span_label ( field_ident. span , "unknown field" ) ;
2423
2425
return ;
2424
2426
} ;
2425
- if let ty:: Adt ( def, _) = output_ty. kind ( ) {
2426
- // no field access on enum type
2427
- if !def. is_enum ( ) {
2428
- if def
2429
- . non_enum_variant ( )
2430
- . fields
2431
- . iter ( )
2432
- . any ( |field| field. ident ( self . tcx ) == field_ident)
2433
- {
2434
- err. span_label (
2435
- field_ident. span ,
2436
- "field not available in `impl Future`, but it is available in its `Output`" ,
2437
- ) ;
2438
- err. span_suggestion_verbose (
2439
- base. span . shrink_to_hi ( ) ,
2440
- "consider `await`ing on the `Future` and access the field of its `Output`" ,
2441
- ".await" ,
2442
- Applicability :: MaybeIncorrect ,
2443
- ) ;
2444
- }
2445
- }
2427
+ let ty:: Adt ( def, _) = output_ty. kind ( ) else {
2428
+ err. span_label ( field_ident. span , "unknown field" ) ;
2429
+ return ;
2430
+ } ;
2431
+ // no field access on enum type
2432
+ if def. is_enum ( ) {
2433
+ err. span_label ( field_ident. span , "unknown field" ) ;
2434
+ return ;
2446
2435
}
2436
+ if !def. non_enum_variant ( ) . fields . iter ( ) . any ( |field| field. ident ( self . tcx ) == field_ident) {
2437
+ err. span_label ( field_ident. span , "unknown field" ) ;
2438
+ return ;
2439
+ }
2440
+ err. span_label (
2441
+ field_ident. span ,
2442
+ "field not available in `impl Future`, but it is available in its `Output`" ,
2443
+ ) ;
2444
+ err. span_suggestion_verbose (
2445
+ base. span . shrink_to_hi ( ) ,
2446
+ "consider `await`ing on the `Future` and access the field of its `Output`" ,
2447
+ ".await" ,
2448
+ Applicability :: MaybeIncorrect ,
2449
+ ) ;
2447
2450
}
2448
2451
2449
2452
fn ban_nonexisting_field (
@@ -2467,16 +2470,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2467
2470
self . suggest_first_deref_field ( & mut err, expr, base, ident) ;
2468
2471
}
2469
2472
ty:: Param ( param_ty) => {
2473
+ err. span_label ( ident. span , "unknown field" ) ;
2470
2474
self . point_at_param_definition ( & mut err, param_ty) ;
2471
2475
}
2472
2476
ty:: Alias ( ty:: Opaque , _) => {
2473
2477
self . suggest_await_on_field_access ( & mut err, ident, base, base_ty. peel_refs ( ) ) ;
2474
2478
}
2475
- _ => { }
2479
+ _ => {
2480
+ err. span_label ( ident. span , "unknown field" ) ;
2481
+ }
2476
2482
}
2477
2483
2478
- err. span_label ( ident. span , "unknown field" ) ;
2479
-
2480
2484
self . suggest_fn_call ( & mut err, base, base_ty, |output_ty| {
2481
2485
if let ty:: Adt ( def, _) = output_ty. kind ( )
2482
2486
&& !def. is_enum ( )
@@ -2635,6 +2639,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2635
2639
field : Ident ,
2636
2640
len : ty:: Const < ' tcx > ,
2637
2641
) {
2642
+ err. span_label ( field. span , "unknown field" ) ;
2638
2643
if let ( Some ( len) , Ok ( user_index) ) =
2639
2644
( len. try_eval_target_usize ( self . tcx , self . param_env ) , field. as_str ( ) . parse :: < u64 > ( ) )
2640
2645
&& let Ok ( base) = self . tcx . sess . source_map ( ) . span_to_snippet ( base. span )
@@ -2657,6 +2662,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2657
2662
base : & hir:: Expr < ' _ > ,
2658
2663
field : Ident ,
2659
2664
) {
2665
+ err. span_label ( field. span , "unknown field" ) ;
2660
2666
if let Ok ( base) = self . tcx . sess . source_map ( ) . span_to_snippet ( base. span ) {
2661
2667
let msg = format ! ( "`{base}` is a raw pointer; try dereferencing it" ) ;
2662
2668
let suggestion = format ! ( "(*{base}).{field}" ) ;
0 commit comments