diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index a3076edef0f..b5e5114d895 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -155,6 +155,9 @@ impl<'a> NameResolution<'a> { fn result(&self, allow_private_imports: bool) -> ResolveResult<&'a NameBinding<'a>> { match self.binding { Some(binding) if !binding.defined_with(DefModifiers::GLOB_IMPORTED) => Success(binding), + // If we don't allow private imports and no public imports can define the name, fail. + _ if !allow_private_imports && self.pub_outstanding_references == 0 && + !self.binding.map(NameBinding::is_public).unwrap_or(false) => Failed(None), _ if self.outstanding_references > 0 => Indeterminate, Some(binding) => Success(binding), None => Failed(None),