@@ -1132,8 +1132,9 @@ pub struct Resolver<'a> {
1132
1132
1133
1133
potentially_unused_imports : Vec < & ' a ImportDirective < ' a > > ,
1134
1134
1135
- // Auxiliary map used only for reporting `legacy_constructor_visibility` lint.
1136
- legacy_ctor_visibilities : DefIdMap < ( Def , ty:: Visibility ) > ,
1135
+ // This table maps struct IDs into struct constructor IDs,
1136
+ // it's not used during normal resolution, only for better error reporting.
1137
+ struct_constructors : DefIdMap < ( Def , ty:: Visibility ) > ,
1137
1138
}
1138
1139
1139
1140
pub struct ResolverArenas < ' a > {
@@ -1313,7 +1314,7 @@ impl<'a> Resolver<'a> {
1313
1314
proc_macro_enabled : features. proc_macro ,
1314
1315
warned_proc_macros : FxHashSet ( ) ,
1315
1316
potentially_unused_imports : Vec :: new ( ) ,
1316
- legacy_ctor_visibilities : DefIdMap ( ) ,
1317
+ struct_constructors : DefIdMap ( ) ,
1317
1318
}
1318
1319
}
1319
1320
@@ -2209,6 +2210,15 @@ impl<'a> Resolver<'a> {
2209
2210
_ => { }
2210
2211
} ,
2211
2212
_ if ns == ValueNS && is_struct_like ( def) => {
2213
+ if let Def :: Struct ( def_id) = def {
2214
+ if let Some ( ( ctor_def, ctor_vis) )
2215
+ = this. struct_constructors . get ( & def_id) . cloned ( ) {
2216
+ if is_expected ( ctor_def) && !this. is_accessible ( ctor_vis) {
2217
+ err. span_label ( span, & format ! ( "constructor is not visible \
2218
+ here due to private fields") ) ;
2219
+ }
2220
+ }
2221
+ }
2212
2222
err. span_label ( span, & format ! ( "did you mean `{} {{ /* fields */ }}`?" ,
2213
2223
path_str) ) ;
2214
2224
return err;
@@ -2244,7 +2254,7 @@ impl<'a> Resolver<'a> {
2244
2254
let mut res = None ;
2245
2255
if let Def :: Struct ( def_id) = resolution. base_def {
2246
2256
if let Some ( ( ctor_def, ctor_vis) )
2247
- = self . legacy_ctor_visibilities . get ( & def_id) . cloned ( ) {
2257
+ = self . struct_constructors . get ( & def_id) . cloned ( ) {
2248
2258
if is_expected ( ctor_def) && self . is_accessible ( ctor_vis) {
2249
2259
let lint = lint:: builtin:: LEGACY_CONSTRUCTOR_VISIBILITY ;
2250
2260
self . session . add_lint ( lint, id, span,
0 commit comments