@@ -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 } ;
@@ -2391,37 +2390,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2391
2390
expr,
2392
2391
Some ( span) ,
2393
2392
) ;
2393
+ } else if let ty:: RawPtr ( ty_and_mut) = expr_t. kind ( )
2394
+ && let ty:: Adt ( adt_def, _) = ty_and_mut. ty . kind ( )
2395
+ && let ExprKind :: Field ( base_expr, _) = expr. kind
2396
+ && adt_def. variants ( ) . len ( ) == 1
2397
+ && adt_def
2398
+ . variants ( )
2399
+ . iter ( )
2400
+ . next ( )
2401
+ . unwrap ( )
2402
+ . fields
2403
+ . iter ( )
2404
+ . any ( |f| f. ident ( self . tcx ) == field)
2405
+ {
2406
+ err. multipart_suggestion (
2407
+ "to access the field, dereference first" ,
2408
+ vec ! [
2409
+ ( base_expr. span. shrink_to_lo( ) , "(*" . to_string( ) ) ,
2410
+ ( base_expr. span. shrink_to_hi( ) , ")" . to_string( ) ) ,
2411
+ ] ,
2412
+ Applicability :: MaybeIncorrect ,
2413
+ ) ;
2394
2414
} else {
2395
- let mut found = false ;
2396
-
2397
- if let ty:: RawPtr ( ty_and_mut) = expr_t. kind ( )
2398
- && let ty:: Adt ( adt_def, _) = ty_and_mut. ty . kind ( )
2399
- {
2400
- if adt_def. variants ( ) . len ( ) == 1
2401
- && adt_def
2402
- . variants ( )
2403
- . iter ( )
2404
- . next ( )
2405
- . unwrap ( )
2406
- . fields
2407
- . iter ( )
2408
- . any ( |f| f. ident ( self . tcx ) == field)
2409
- {
2410
- if let Some ( dot_loc) = expr_snippet. rfind ( '.' ) {
2411
- found = true ;
2412
- err. span_suggestion (
2413
- expr. span . with_hi ( expr. span . lo ( ) + BytePos :: from_usize ( dot_loc) ) ,
2414
- "to access the field, dereference first" ,
2415
- format ! ( "(*{})" , & expr_snippet[ 0 ..dot_loc] ) ,
2416
- Applicability :: MaybeIncorrect ,
2417
- ) ;
2418
- }
2419
- }
2420
- }
2421
-
2422
- if !found {
2423
- err. help ( "methods are immutable and cannot be assigned to" ) ;
2424
- }
2415
+ err. help ( "methods are immutable and cannot be assigned to" ) ;
2425
2416
}
2426
2417
2427
2418
err. emit ( ) ;
0 commit comments