@@ -156,6 +156,21 @@ impl<'a> NameResolution<'a> {
156156 }
157157}
158158
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+
159174impl < ' a > Resolver < ' a > {
160175 crate fn resolve_ident_in_module_unadjusted (
161176 & mut self ,
@@ -263,10 +278,7 @@ impl<'a> Resolver<'a> {
263278 return Err ( ( Determined , Weak :: No ) ) ;
264279 }
265280 }
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 ) ;
270282 if usable { Ok ( binding) } else { Err ( ( Determined , Weak :: No ) ) }
271283 } ;
272284
@@ -309,10 +321,7 @@ impl<'a> Resolver<'a> {
309321 }
310322 }
311323
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 ) {
316325 self . privacy_errors . push ( PrivacyError {
317326 ident,
318327 binding,
@@ -455,9 +464,8 @@ impl<'a> Resolver<'a> {
455464 binding : & ' a NameBinding < ' a > ,
456465 import : & ' a Import < ' a > ,
457466 ) -> & ' 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)
461469 {
462470 import. vis . get ( )
463471 } else {
@@ -1188,7 +1196,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11881196 // All namespaces must be re-exported with extra visibility for an error to occur.
11891197 if !any_successful_reexport {
11901198 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) {
11921200 let msg = format ! (
11931201 "extern crate `{}` is private, and cannot be \
11941202 re-exported (error E0365), consider declaring with \
0 commit comments