@@ -156,6 +156,21 @@ impl<'a> NameResolution<'a> {
156
156
}
157
157
}
158
158
159
+ // Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
160
+ // are permitted for backward-compatibility under a deprecation lint.
161
+ fn pub_use_of_private_extern_crate_hack ( import : & Import < ' _ > , binding : & NameBinding < ' _ > ) -> bool {
162
+ match ( & import. kind , & binding. kind ) {
163
+ (
164
+ ImportKind :: Single { .. } ,
165
+ NameBindingKind :: Import {
166
+ import : Import { kind : ImportKind :: ExternCrate { .. } , .. } ,
167
+ ..
168
+ } ,
169
+ ) => import. vis . get ( ) == ty:: Visibility :: Public ,
170
+ _ => false ,
171
+ }
172
+ }
173
+
159
174
impl < ' a > Resolver < ' a > {
160
175
crate fn resolve_ident_in_module_unadjusted (
161
176
& mut self ,
@@ -263,10 +278,7 @@ impl<'a> Resolver<'a> {
263
278
return Err ( ( Determined , Weak :: No ) ) ;
264
279
}
265
280
}
266
- // `extern crate` are always usable for backwards compatibility, see issue #37020,
267
- // remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
268
- let usable = this. is_accessible_from ( binding. vis , parent_scope. module )
269
- || binding. is_extern_crate ( ) ;
281
+ let usable = this. is_accessible_from ( binding. vis , parent_scope. module ) ;
270
282
if usable { Ok ( binding) } else { Err ( ( Determined , Weak :: No ) ) }
271
283
} ;
272
284
@@ -309,10 +321,7 @@ impl<'a> Resolver<'a> {
309
321
}
310
322
}
311
323
312
- if !( self . is_accessible_from ( binding. vis , parent_scope. module ) ||
313
- // Remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`
314
- ( self . last_import_segment && binding. is_extern_crate ( ) ) )
315
- {
324
+ if !self . is_accessible_from ( binding. vis , parent_scope. module ) {
316
325
self . privacy_errors . push ( PrivacyError {
317
326
ident,
318
327
binding,
@@ -455,9 +464,8 @@ impl<'a> Resolver<'a> {
455
464
binding : & ' a NameBinding < ' a > ,
456
465
import : & ' a Import < ' a > ,
457
466
) -> & ' a NameBinding < ' a > {
458
- let vis = if binding. vis . is_at_least ( import. vis . get ( ) , self ) ||
459
- // cf. `PUB_USE_OF_PRIVATE_EXTERN_CRATE`
460
- !import. is_glob ( ) && binding. is_extern_crate ( )
467
+ let vis = if binding. vis . is_at_least ( import. vis . get ( ) , self )
468
+ || pub_use_of_private_extern_crate_hack ( import, binding)
461
469
{
462
470
import. vis . get ( )
463
471
} else {
@@ -1188,7 +1196,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
1188
1196
// All namespaces must be re-exported with extra visibility for an error to occur.
1189
1197
if !any_successful_reexport {
1190
1198
let ( ns, binding) = reexport_error. unwrap ( ) ;
1191
- if ns == TypeNS && binding. is_extern_crate ( ) {
1199
+ if pub_use_of_private_extern_crate_hack ( import , binding) {
1192
1200
let msg = format ! (
1193
1201
"extern crate `{}` is private, and cannot be \
1194
1202
re-exported (error E0365), consider declaring with \
0 commit comments