@@ -917,51 +917,46 @@ impl<'a> Resolver<'a> {
917
917
err. emit ( ) ;
918
918
}
919
919
920
- crate fn report_privacy_error ( & self , privacy_error : & PrivacyError < ' _ > ) {
921
- let PrivacyError { ident, binding, .. } = * privacy_error;
922
- let session = & self . session ;
923
- let mk_struct_span_error = |is_constructor| {
924
- let mut descr = binding. res ( ) . descr ( ) . to_string ( ) ;
925
- if is_constructor {
926
- descr += " constructor" ;
927
- }
928
- if binding. is_import ( ) {
929
- descr += " import" ;
930
- }
931
-
932
- let mut err =
933
- struct_span_err ! ( session, ident. span, E0603 , "{} `{}` is private" , descr, ident) ;
934
-
935
- err. span_label ( ident. span , & format ! ( "this {} is private" , descr) ) ;
936
- err. span_note (
937
- session. source_map ( ) . def_span ( binding. span ) ,
938
- & format ! ( "the {} `{}` is defined here" , descr, ident) ,
939
- ) ;
940
-
941
- err
942
- } ;
943
-
944
- let mut err = if let NameBindingKind :: Res (
920
+ /// If the binding refers to a tuple struct constructor with fields,
921
+ /// returns the span of its fields.
922
+ fn ctor_fields_span ( & self , binding : & NameBinding < ' _ > ) -> Option < Span > {
923
+ if let NameBindingKind :: Res (
945
924
Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) , ctor_def_id) ,
946
925
_,
947
926
) = binding. kind
948
927
{
949
928
let def_id = ( & * self ) . parent ( ctor_def_id) . expect ( "no parent for a constructor" ) ;
950
929
if let Some ( fields) = self . field_names . get ( & def_id) {
951
- let mut err = mk_struct_span_error ( true ) ;
952
930
let first_field = fields. first ( ) . expect ( "empty field list in the map" ) ;
953
- err. span_label (
954
- fields. iter ( ) . fold ( first_field. span , |acc, field| acc. to ( field. span ) ) ,
955
- "a constructor is private if any of the fields is private" ,
956
- ) ;
957
- err
958
- } else {
959
- mk_struct_span_error ( false )
931
+ return Some ( fields. iter ( ) . fold ( first_field. span , |acc, field| acc. to ( field. span ) ) ) ;
960
932
}
961
- } else {
962
- mk_struct_span_error ( false )
963
- } ;
933
+ }
934
+ None
935
+ }
936
+
937
+ crate fn report_privacy_error ( & self , privacy_error : & PrivacyError < ' _ > ) {
938
+ let PrivacyError { ident, binding, .. } = * privacy_error;
939
+
940
+ let ctor_fields_span = self . ctor_fields_span ( binding) ;
941
+ let mut descr = binding. res ( ) . descr ( ) . to_string ( ) ;
942
+ if ctor_fields_span. is_some ( ) {
943
+ descr += " constructor" ;
944
+ }
945
+ if binding. is_import ( ) {
946
+ descr += " import" ;
947
+ }
964
948
949
+ let mut err =
950
+ struct_span_err ! ( self . session, ident. span, E0603 , "{} `{}` is private" , descr, ident) ;
951
+ err. span_label ( ident. span , & format ! ( "this {} is private" , descr) ) ;
952
+ if let Some ( span) = ctor_fields_span {
953
+ err. span_label ( span, "a constructor is private if any of the fields is private" ) ;
954
+ }
955
+
956
+ err. span_note (
957
+ self . session . source_map ( ) . def_span ( binding. span ) ,
958
+ & format ! ( "the {} `{}` is defined here" , descr, ident) ,
959
+ ) ;
965
960
err. emit ( ) ;
966
961
}
967
962
}
0 commit comments