@@ -384,8 +384,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
384384 fn check_field ( & mut self , span : Span , def : ty:: AdtDef < ' tcx > , field : ty:: FieldDef < ' tcx > ) {
385385 if def. adt_kind ( ) == ty:: AdtKind :: Struct &&
386386 !field. vis . is_accessible_from ( self . curitem , & self . tcx . map ) {
387- span_err ! ( self . tcx. sess, span, E0451 , "field `{}` of struct `{}` is private" ,
388- field. name, self . tcx. item_path_str( def. did) ) ;
387+ struct_span_err ! ( self . tcx. sess, span, E0451 , "field `{}` of struct `{}` is private" ,
388+ field. name, self . tcx. item_path_str( def. did) )
389+ . span_label ( span, & format ! ( "field `{}` is private" , field. name) )
390+ . emit ( ) ;
389391 }
390392 }
391393
@@ -425,14 +427,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
425427 let method = self . tcx . tables . borrow ( ) . method_map [ & method_call] ;
426428 self . check_method ( expr. span , method. def_id ) ;
427429 }
428- hir:: ExprStruct ( .. ) => {
430+ hir:: ExprStruct ( _ , ref fields , _ ) => {
429431 let adt = self . tcx . expr_ty ( expr) . ty_adt_def ( ) . unwrap ( ) ;
430432 let variant = adt. variant_of_def ( self . tcx . expect_def ( expr. id ) ) ;
431433 // RFC 736: ensure all unmentioned fields are visible.
432434 // Rather than computing the set of unmentioned fields
433435 // (i.e. `all_fields - fields`), just check them all.
434- for field in & variant. fields {
435- self . check_field ( expr. span , adt, field) ;
436+ for field in variant. fields . iter ( ) {
437+ let span = if let Some ( f) = fields. iter ( ) . find ( |f| f. name . node == field. name ) {
438+ f. span
439+ } else {
440+ expr. span
441+ } ;
442+ self . check_field ( span, adt, field) ;
436443 }
437444 }
438445 hir:: ExprPath ( ..) => {
@@ -491,7 +498,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
491498 let adt = self . tcx . pat_ty ( pattern) . ty_adt_def ( ) . unwrap ( ) ;
492499 let variant = adt. variant_of_def ( self . tcx . expect_def ( pattern. id ) ) ;
493500 for field in fields {
494- self . check_field ( pattern . span , adt, variant. field_named ( field. node . name ) ) ;
501+ self . check_field ( field . span , adt, variant. field_named ( field. node . name ) ) ;
495502 }
496503 }
497504 PatKind :: TupleStruct ( _, ref fields, ddpos) => {
0 commit comments