@@ -2191,7 +2191,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21912191 if let Some ( field_name) =
21922192 find_best_match_for_name ( & available_field_names, field. ident . name , None )
21932193 {
2194- err. span_suggestion (
2194+ err. span_label ( field. ident . span , "unknown field" ) ;
2195+ err. span_suggestion_verbose (
21952196 field. ident . span ,
21962197 "a field with a similar name exists" ,
21972198 field_name,
@@ -2420,30 +2421,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24202421 ty : Ty < ' tcx > ,
24212422 ) {
24222423 let Some ( output_ty) = self . get_impl_future_output_ty ( ty) else {
2424+ err. span_label ( field_ident. span , "unknown field" ) ;
24232425 return ;
24242426 } ;
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 ;
24462435 }
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+ ) ;
24472450 }
24482451
24492452 fn ban_nonexisting_field (
@@ -2467,16 +2470,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24672470 self . suggest_first_deref_field ( & mut err, expr, base, ident) ;
24682471 }
24692472 ty:: Param ( param_ty) => {
2473+ err. span_label ( ident. span , "unknown field" ) ;
24702474 self . point_at_param_definition ( & mut err, param_ty) ;
24712475 }
24722476 ty:: Alias ( ty:: Opaque , _) => {
24732477 self . suggest_await_on_field_access ( & mut err, ident, base, base_ty. peel_refs ( ) ) ;
24742478 }
2475- _ => { }
2479+ _ => {
2480+ err. span_label ( ident. span , "unknown field" ) ;
2481+ }
24762482 }
24772483
2478- err. span_label ( ident. span , "unknown field" ) ;
2479-
24802484 self . suggest_fn_call ( & mut err, base, base_ty, |output_ty| {
24812485 if let ty:: Adt ( def, _) = output_ty. kind ( )
24822486 && !def. is_enum ( )
@@ -2635,6 +2639,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26352639 field : Ident ,
26362640 len : ty:: Const < ' tcx > ,
26372641 ) {
2642+ err. span_label ( field. span , "unknown field" ) ;
26382643 if let ( Some ( len) , Ok ( user_index) ) =
26392644 ( len. try_eval_target_usize ( self . tcx , self . param_env ) , field. as_str ( ) . parse :: < u64 > ( ) )
26402645 && let Ok ( base) = self . tcx . sess . source_map ( ) . span_to_snippet ( base. span )
@@ -2657,6 +2662,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26572662 base : & hir:: Expr < ' _ > ,
26582663 field : Ident ,
26592664 ) {
2665+ err. span_label ( field. span , "unknown field" ) ;
26602666 if let Ok ( base) = self . tcx . sess . source_map ( ) . span_to_snippet ( base. span ) {
26612667 let msg = format ! ( "`{base}` is a raw pointer; try dereferencing it" ) ;
26622668 let suggestion = format ! ( "(*{base}).{field}" ) ;
0 commit comments