@@ -48,7 +48,7 @@ use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TypeVisitable};
48
48
use rustc_session:: parse:: feature_err;
49
49
use rustc_span:: hygiene:: DesugaringKind ;
50
50
use rustc_span:: lev_distance:: find_best_match_for_name;
51
- use rustc_span:: source_map:: Span ;
51
+ use rustc_span:: source_map:: { Span , Spanned } ;
52
52
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
53
53
use rustc_span:: { BytePos , Pos } ;
54
54
use rustc_target:: spec:: abi:: Abi :: RustIntrinsic ;
@@ -2170,14 +2170,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2170
2170
E0610 ,
2171
2171
"`{expr_t}` is a primitive type and therefore doesn't have fields" ,
2172
2172
) ;
2173
- if expr_t. is_integral ( )
2174
- && ( field_name
2175
- . strip_prefix ( 'e' )
2176
- . or_else ( || field_name. strip_prefix ( 'E' ) )
2177
- . map ( |prefix| prefix. chars ( ) . all ( |c| c. is_numeric ( ) ) )
2178
- . unwrap_or_default ( )
2179
- || field. name == sym:: f32
2180
- || field. name == sym:: f64)
2173
+ let is_valid_suffix = |field : String | {
2174
+ if field == "f32" || field == "f64" {
2175
+ return true ;
2176
+ }
2177
+ let mut chars = field. chars ( ) . peekable ( ) ;
2178
+ match chars. peek ( ) {
2179
+ Some ( 'e' ) | Some ( 'E' ) => {
2180
+ chars. next ( ) ;
2181
+ if let Some ( c) = chars. peek ( )
2182
+ && !c. is_numeric ( ) && * c != '-' && * c != '+'
2183
+ {
2184
+ return false ;
2185
+ }
2186
+ while let Some ( c) = chars. peek ( ) {
2187
+ if !c. is_numeric ( ) {
2188
+ break ;
2189
+ }
2190
+ chars. next ( ) ;
2191
+ }
2192
+ }
2193
+ _ => ( ) ,
2194
+ }
2195
+ let suffix = chars. collect :: < String > ( ) ;
2196
+ suffix. is_empty ( ) || suffix == "f32" || suffix == "f64"
2197
+ } ;
2198
+ if let ty:: Infer ( ty:: IntVar ( _) ) = expr_t. kind ( )
2199
+ && let ExprKind :: Lit ( Spanned {
2200
+ node : ast:: LitKind :: Int ( _, ast:: LitIntType :: Unsuffixed ) ,
2201
+ ..
2202
+ } ) = base. kind
2203
+ && !base. span . from_expansion ( )
2204
+ && is_valid_suffix ( field_name)
2181
2205
{
2182
2206
err. span_suggestion_verbose (
2183
2207
field. span . shrink_to_lo ( ) ,
0 commit comments