@@ -384,8 +384,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
384
384
fn check_field ( & mut self , span : Span , def : ty:: AdtDef < ' tcx > , field : ty:: FieldDef < ' tcx > ) {
385
385
if def. adt_kind ( ) == ty:: AdtKind :: Struct &&
386
386
!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 ( ) ;
389
391
}
390
392
}
391
393
@@ -425,14 +427,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
425
427
let method = self . tcx . tables . borrow ( ) . method_map [ & method_call] ;
426
428
self . check_method ( expr. span , method. def_id ) ;
427
429
}
428
- hir:: ExprStruct ( .. ) => {
430
+ hir:: ExprStruct ( _ , ref fields , _ ) => {
429
431
let adt = self . tcx . expr_ty ( expr) . ty_adt_def ( ) . unwrap ( ) ;
430
432
let variant = adt. variant_of_def ( self . tcx . expect_def ( expr. id ) ) ;
431
433
// RFC 736: ensure all unmentioned fields are visible.
432
434
// Rather than computing the set of unmentioned fields
433
435
// (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) ;
436
443
}
437
444
}
438
445
hir:: ExprPath ( ..) => {
@@ -491,7 +498,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
491
498
let adt = self . tcx . pat_ty ( pattern) . ty_adt_def ( ) . unwrap ( ) ;
492
499
let variant = adt. variant_of_def ( self . tcx . expect_def ( pattern. id ) ) ;
493
500
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 ) ) ;
495
502
}
496
503
}
497
504
PatKind :: TupleStruct ( _, ref fields, ddpos) => {
0 commit comments