@@ -2952,30 +2952,34 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29522952 . emit ( ) ;
29532953 self . tcx ( ) . types . err
29542954 } else {
2955- let mut err = self . type_error_struct ( field. span , |actual| {
2956- format ! ( "no field `{}` on type `{}`" ,
2957- field. node, actual)
2958- } , expr_t) ;
2959- match expr_t. sty {
2960- ty:: TyAdt ( def, _) if !def. is_enum ( ) => {
2961- if let Some ( suggested_field_name) =
2962- Self :: suggest_field_name ( def. struct_variant ( ) , field, vec ! [ ] ) {
2963- err. span_label ( field. span ,
2964- format ! ( "did you mean `{}`?" , suggested_field_name) ) ;
2965- } else {
2966- err. span_label ( field. span ,
2967- "unknown field" ) ;
2968- } ;
2969- }
2970- ty:: TyRawPtr ( ..) => {
2971- err. note ( & format ! ( "`{0}` is a native pointer; perhaps you need to deref with \
2972- `(*{0}).{1}`",
2973- self . tcx. hir. node_to_pretty_string( base. id) ,
2974- field. node) ) ;
2955+ if !expr_t. is_primitive_ty ( ) {
2956+ let mut err = type_error_struct ! ( self . tcx( ) . sess, field. span, expr_t, E0609 ,
2957+ "no field `{}` on type `{}`" ,
2958+ field. node, expr_t) ;
2959+ match expr_t. sty {
2960+ ty:: TyAdt ( def, _) if !def. is_enum ( ) => {
2961+ if let Some ( suggested_field_name) =
2962+ Self :: suggest_field_name ( def. struct_variant ( ) , field, vec ! [ ] ) {
2963+ err. span_label ( field. span ,
2964+ format ! ( "did you mean `{}`?" , suggested_field_name) ) ;
2965+ } else {
2966+ err. span_label ( field. span , "unknown field" ) ;
2967+ } ;
2968+ }
2969+ ty:: TyRawPtr ( ..) => {
2970+ err. note ( & format ! ( "`{0}` is a native pointer; perhaps you need to deref \
2971+ with `(*{0}).{1}`",
2972+ self . tcx. hir. node_to_pretty_string( base. id) ,
2973+ field. node) ) ;
2974+ }
2975+ _ => { }
29752976 }
2976- _ => { }
2977- }
2978- err. emit ( ) ;
2977+ err
2978+ } else {
2979+ type_error_struct ! ( self . tcx( ) . sess, field. span, expr_t, E0610 ,
2980+ "`{}` is a primitive type and therefore doesn't have fields" ,
2981+ expr_t)
2982+ } . emit ( ) ;
29792983 self . tcx ( ) . types . err
29802984 }
29812985 }
0 commit comments