@@ -2950,8 +2950,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29502950
29512951 if let Some ( ( did, field_ty) ) = private_candidate {
29522952 let struct_path = self . tcx ( ) . item_path_str ( did) ;
2953- let msg = format ! ( "field `{}` of struct `{}` is private" , field. node, struct_path) ;
2954- let mut err = self . tcx ( ) . sess . struct_span_err ( expr. span , & msg) ;
2953+ let mut err = struct_span_err ! ( self . tcx( ) . sess, expr. span, E0616 ,
2954+ "field `{}` of struct `{}` is private" ,
2955+ field. node, struct_path) ;
29552956 // Also check if an accessible method exists, which is often what is meant.
29562957 if self . method_exists ( field. span , field. node , expr_t, expr. id , false ) {
29572958 err. note ( & format ! ( "a method `{}` also exists, perhaps you wish to call it" ,
@@ -2962,10 +2963,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29622963 } else if field. node == keywords:: Invalid . name ( ) {
29632964 self . tcx ( ) . types . err
29642965 } else if self . method_exists ( field. span , field. node , expr_t, expr. id , true ) {
2965- self . type_error_struct ( field. span , |actual| {
2966- format ! ( "attempted to take value of method `{}` on type \
2967- `{}`", field. node, actual)
2968- } , expr_t)
2966+ type_error_struct ! ( self . tcx( ) . sess, field. span, expr_t, E0615 ,
2967+ "attempted to take value of method `{}` on type `{}`" ,
2968+ field. node, expr_t)
29692969 . help ( "maybe a `()` to call it is missing? \
29702970 If not, try an anonymous function")
29712971 . emit ( ) ;
@@ -3080,27 +3080,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30803080
30813081 if let Some ( ( did, field_ty) ) = private_candidate {
30823082 let struct_path = self . tcx ( ) . item_path_str ( did) ;
3083- let msg = format ! ( "field `{}` of struct `{}` is private" , idx. node, struct_path) ;
3084- self . tcx ( ) . sess . span_err ( expr. span , & msg) ;
3083+ struct_span_err ! ( self . tcx( ) . sess, expr. span, E0611 ,
3084+ "field `{}` of tuple-struct `{}` is private" ,
3085+ idx. node, struct_path) . emit ( ) ;
30853086 return field_ty;
30863087 }
30873088
3088- self . type_error_message (
3089- expr. span ,
3090- |actual| {
3091- if tuple_like {
3092- format ! ( "attempted out-of-bounds tuple index `{}` on \
3093- type `{}`",
3094- idx. node,
3095- actual)
3096- } else {
3097- format ! ( "attempted tuple index `{}` on type `{}`, but the \
3098- type was not a tuple or tuple struct",
3099- idx. node,
3100- actual)
3101- }
3102- } ,
3103- expr_t) ;
3089+ if tuple_like {
3090+ type_error_struct ! ( self . tcx( ) . sess, expr. span, expr_t, E0612 ,
3091+ "attempted out-of-bounds tuple index `{}` on type `{}`" ,
3092+ idx. node, expr_t) . emit ( ) ;
3093+ } else {
3094+ type_error_struct ! ( self . tcx( ) . sess, expr. span, expr_t, E0613 ,
3095+ "attempted to access tuple index `{}` on type `{}`, but the type \
3096+ was not a tuple or tuple struct",
3097+ idx. node, expr_t) . emit ( ) ;
3098+ }
31043099
31053100 self . tcx ( ) . types . err
31063101 }
@@ -3201,10 +3196,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32013196 field_type_hint = tcx. types . err ;
32023197 if let Some ( _) = variant. find_field_named ( field. name . node ) {
32033198 let mut err = struct_span_err ! ( self . tcx. sess,
3204- field. name. span,
3205- E0062 ,
3206- "field `{}` specified more than once" ,
3207- field. name. node) ;
3199+ field. name. span,
3200+ E0062 ,
3201+ "field `{}` specified more than once" ,
3202+ field. name. node) ;
32083203
32093204 err. span_label ( field. name . span , "used more than once" ) ;
32103205
@@ -3251,15 +3246,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32513246 . join ( ", " ) ;
32523247
32533248 struct_span_err ! ( tcx. sess, span, E0063 ,
3254- "missing field{} {}{} in initializer of `{}`" ,
3255- if remaining_fields. len( ) == 1 { "" } else { "s" } ,
3256- remaining_fields_names,
3257- truncated_fields_error,
3258- adt_ty)
3259- . span_label ( span, format ! ( "missing {}{}" ,
3260- remaining_fields_names,
3261- truncated_fields_error) )
3262- . emit ( ) ;
3249+ "missing field{} {}{} in initializer of `{}`" ,
3250+ if remaining_fields. len( ) == 1 { "" } else { "s" } ,
3251+ remaining_fields_names,
3252+ truncated_fields_error,
3253+ adt_ty)
3254+ . span_label ( span, format ! ( "missing {}{}" ,
3255+ remaining_fields_names,
3256+ truncated_fields_error) )
3257+ . emit ( ) ;
32633258 }
32643259 }
32653260
@@ -3492,10 +3487,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34923487 oprnd_t = self . make_overloaded_lvalue_return_type ( method) . ty ;
34933488 self . write_method_call ( expr. id , method) ;
34943489 } else {
3495- self . type_error_message ( expr. span , |actual| {
3496- format ! ( "type `{}` cannot be \
3497- dereferenced", actual)
3498- } , oprnd_t) ;
3490+ type_error_struct ! ( tcx. sess, expr. span, oprnd_t, E0614 ,
3491+ "type `{}` cannot be dereferenced" ,
3492+ oprnd_t) . emit ( ) ;
34993493 oprnd_t = tcx. types . err ;
35003494 }
35013495 }
0 commit comments