@@ -2384,6 +2384,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2384
2384
arg_count,
2385
2385
if arg_count == 1 { " was" } else { "s were" } ) ,
2386
2386
error_code) ;
2387
+
2388
+ err. span_label ( sp, & format ! ( "expected {}{} parameter{}" ,
2389
+ if variadic { "at least " } else { "" } ,
2390
+ expected_count,
2391
+ if expected_count == 1 { "" } else { "s" } ) ) ;
2392
+
2387
2393
let input_types = fn_inputs. iter ( ) . map ( |i| format ! ( "{:?}" , i) ) . collect :: < Vec < String > > ( ) ;
2388
2394
if input_types. len ( ) > 0 {
2389
2395
err. note ( & format ! ( "the following parameter type{} expected: {}" ,
@@ -3063,6 +3069,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3063
3069
remaining_fields. insert ( field. name , field) ;
3064
3070
}
3065
3071
3072
+ let mut seen_fields = FnvHashMap ( ) ;
3073
+
3066
3074
let mut error_happened = false ;
3067
3075
3068
3076
// Typecheck each field.
@@ -3071,13 +3079,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3071
3079
3072
3080
if let Some ( v_field) = remaining_fields. remove ( & field. name . node ) {
3073
3081
expected_field_type = self . field_ty ( field. span , v_field, substs) ;
3082
+
3083
+ seen_fields. insert ( field. name . node , field. span ) ;
3074
3084
} else {
3075
3085
error_happened = true ;
3076
3086
expected_field_type = tcx. types . err ;
3077
3087
if let Some ( _) = variant. find_field_named ( field. name . node ) {
3078
- span_err ! ( self . tcx. sess, field. name. span, E0062 ,
3079
- "field `{}` specified more than once" ,
3080
- field. name. node) ;
3088
+ let mut err = struct_span_err ! ( self . tcx. sess,
3089
+ field. name. span,
3090
+ E0062 ,
3091
+ "field `{}` specified more than once" ,
3092
+ field. name. node) ;
3093
+
3094
+ err. span_label ( field. name . span , & format ! ( "used more than once" ) ) ;
3095
+
3096
+ if let Some ( prev_span) = seen_fields. get ( & field. name . node ) {
3097
+ err. span_label ( * prev_span, & format ! ( "first use of `{}`" , field. name. node) ) ;
3098
+ }
3099
+
3100
+ err. emit ( ) ;
3081
3101
} else {
3082
3102
self . report_unknown_field ( adt_ty, variant, field, ast_fields) ;
3083
3103
}
@@ -3147,9 +3167,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3147
3167
} ;
3148
3168
if variant. is_none ( ) || variant. unwrap ( ) . kind == ty:: VariantKind :: Tuple {
3149
3169
// Reject tuple structs for now, braced and unit structs are allowed.
3150
- span_err ! ( self . tcx. sess, span, E0071 ,
3151
- "`{}` does not name a struct or a struct variant" ,
3152
- pprust:: path_to_string( path) ) ;
3170
+ struct_span_err ! ( self . tcx. sess, path. span, E0071 ,
3171
+ "`{}` does not name a struct or a struct variant" ,
3172
+ pprust:: path_to_string( path) )
3173
+ . span_label ( path. span , & format ! ( "not a struct" ) )
3174
+ . emit ( ) ;
3175
+
3153
3176
return None ;
3154
3177
}
3155
3178
0 commit comments