@@ -925,6 +925,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
925
925
def : ty:: AdtDef < ' tcx > , // definition of the struct or enum
926
926
field : & ' tcx ty:: FieldDef ,
927
927
in_update_syntax : bool ,
928
+ struct_span : Span ,
928
929
) {
929
930
if def. is_enum ( ) {
930
931
return ;
@@ -936,6 +937,11 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
936
937
if !field. vis . is_accessible_from ( def_id, self . tcx ) {
937
938
self . tcx . dcx ( ) . emit_err ( FieldIsPrivate {
938
939
span,
940
+ struct_span : if self . tcx . sess . source_map ( ) . is_multiline ( span. between ( struct_span) ) {
941
+ Some ( struct_span)
942
+ } else {
943
+ None
944
+ } ,
939
945
field_name : field. name ,
940
946
variant_descr : def. variant_descr ( ) ,
941
947
def_path_str : self . tcx . def_path_str ( def. did ( ) ) ,
@@ -955,6 +961,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
955
961
fields : & [ hir:: ExprField < ' tcx > ] ,
956
962
hir_id : hir:: HirId ,
957
963
span : Span ,
964
+ struct_span : Span ,
958
965
) {
959
966
for ( vf_index, variant_field) in variant. fields . iter_enumerated ( ) {
960
967
let field =
@@ -963,7 +970,7 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
963
970
Some ( field) => ( field. hir_id , field. ident . span , field. span ) ,
964
971
None => ( hir_id, span, span) ,
965
972
} ;
966
- self . check_field ( hir_id, use_ctxt, span, adt, variant_field, true ) ;
973
+ self . check_field ( hir_id, use_ctxt, span, adt, variant_field, true , struct_span ) ;
967
974
}
968
975
}
969
976
}
@@ -990,10 +997,24 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
990
997
// If the expression uses FRU we need to make sure all the unmentioned fields
991
998
// are checked for privacy (RFC 736). Rather than computing the set of
992
999
// unmentioned fields, just check them all.
993
- self . check_expanded_fields ( adt, variant, fields, base. hir_id , base. span ) ;
1000
+ self . check_expanded_fields (
1001
+ adt,
1002
+ variant,
1003
+ fields,
1004
+ base. hir_id ,
1005
+ base. span ,
1006
+ qpath. span ( ) ,
1007
+ ) ;
994
1008
}
995
1009
hir:: StructTailExpr :: DefaultFields ( span) => {
996
- self . check_expanded_fields ( adt, variant, fields, expr. hir_id , span) ;
1010
+ self . check_expanded_fields (
1011
+ adt,
1012
+ variant,
1013
+ fields,
1014
+ expr. hir_id ,
1015
+ span,
1016
+ qpath. span ( ) ,
1017
+ ) ;
997
1018
}
998
1019
hir:: StructTailExpr :: None => {
999
1020
for field in fields {
@@ -1006,6 +1027,7 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
1006
1027
adt,
1007
1028
& variant. fields [ index] ,
1008
1029
false ,
1030
+ qpath. span ( ) ,
1009
1031
) ;
1010
1032
}
1011
1033
}
@@ -1023,7 +1045,15 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
1023
1045
for field in fields {
1024
1046
let ( hir_id, use_ctxt, span) = ( field. hir_id , field. ident . span , field. span ) ;
1025
1047
let index = self . typeck_results ( ) . field_index ( field. hir_id ) ;
1026
- self . check_field ( hir_id, use_ctxt, span, adt, & variant. fields [ index] , false ) ;
1048
+ self . check_field (
1049
+ hir_id,
1050
+ use_ctxt,
1051
+ span,
1052
+ adt,
1053
+ & variant. fields [ index] ,
1054
+ false ,
1055
+ qpath. span ( ) ,
1056
+ ) ;
1027
1057
}
1028
1058
}
1029
1059
0 commit comments