@@ -50,7 +50,6 @@ use rustc_span::hygiene::DesugaringKind;
50
50
use rustc_span:: lev_distance:: find_best_match_for_name;
51
51
use rustc_span:: source_map:: { Span , Spanned } ;
52
52
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
53
- use rustc_span:: { BytePos , Pos } ;
54
53
use rustc_target:: spec:: abi:: Abi :: RustIntrinsic ;
55
54
use rustc_trait_selection:: infer:: InferCtxtExt ;
56
55
use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
@@ -2398,37 +2397,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2398
2397
expr,
2399
2398
Some ( span) ,
2400
2399
) ;
2400
+ } else if let ty:: RawPtr ( ty_and_mut) = expr_t. kind ( )
2401
+ && let ty:: Adt ( adt_def, _) = ty_and_mut. ty . kind ( )
2402
+ && let ExprKind :: Field ( base_expr, _) = expr. kind
2403
+ && adt_def. variants ( ) . len ( ) == 1
2404
+ && adt_def
2405
+ . variants ( )
2406
+ . iter ( )
2407
+ . next ( )
2408
+ . unwrap ( )
2409
+ . fields
2410
+ . iter ( )
2411
+ . any ( |f| f. ident ( self . tcx ) == field)
2412
+ {
2413
+ err. multipart_suggestion (
2414
+ "to access the field, dereference first" ,
2415
+ vec ! [
2416
+ ( base_expr. span. shrink_to_lo( ) , "(*" . to_string( ) ) ,
2417
+ ( base_expr. span. shrink_to_hi( ) , ")" . to_string( ) ) ,
2418
+ ] ,
2419
+ Applicability :: MaybeIncorrect ,
2420
+ ) ;
2401
2421
} else {
2402
- let mut found = false ;
2403
-
2404
- if let ty:: RawPtr ( ty_and_mut) = expr_t. kind ( )
2405
- && let ty:: Adt ( adt_def, _) = ty_and_mut. ty . kind ( )
2406
- {
2407
- if adt_def. variants ( ) . len ( ) == 1
2408
- && adt_def
2409
- . variants ( )
2410
- . iter ( )
2411
- . next ( )
2412
- . unwrap ( )
2413
- . fields
2414
- . iter ( )
2415
- . any ( |f| f. ident ( self . tcx ) == field)
2416
- {
2417
- if let Some ( dot_loc) = expr_snippet. rfind ( '.' ) {
2418
- found = true ;
2419
- err. span_suggestion (
2420
- expr. span . with_hi ( expr. span . lo ( ) + BytePos :: from_usize ( dot_loc) ) ,
2421
- "to access the field, dereference first" ,
2422
- format ! ( "(*{})" , & expr_snippet[ 0 ..dot_loc] ) ,
2423
- Applicability :: MaybeIncorrect ,
2424
- ) ;
2425
- }
2426
- }
2427
- }
2428
-
2429
- if !found {
2430
- err. help ( "methods are immutable and cannot be assigned to" ) ;
2431
- }
2422
+ err. help ( "methods are immutable and cannot be assigned to" ) ;
2432
2423
}
2433
2424
2434
2425
err. emit ( ) ;
0 commit comments