From 5a8845e40b6c973f9834dc6462bde7b8d3c03829 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 9 Mar 2016 01:55:21 +0000 Subject: [PATCH] Refactor away DefModifiers::PRELUDE --- src/librustc_resolve/lib.rs | 3 +-- src/librustc_resolve/resolve_imports.rs | 26 +++++++++++-------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 65d40edd958..763fa32795d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -932,8 +932,7 @@ bitflags! { // Variants are considered `PUBLIC`, but some of them live in private enums. // We need to track them to prohibit reexports like `pub use PrivEnum::Variant`. const PRIVATE_VARIANT = 1 << 2, - const PRELUDE = 1 << 3, - const GLOB_IMPORTED = 1 << 4, + const GLOB_IMPORTED = 1 << 3, } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 91bbb154bbe..a29954ade18 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -125,18 +125,17 @@ pub struct NameResolution<'a> { impl<'a> NameResolution<'a> { fn try_define(&mut self, binding: &'a NameBinding<'a>) -> Result<(), &'a NameBinding<'a>> { - match self.binding { - Some(old_binding) if !old_binding.defined_with(DefModifiers::PRELUDE) => { - if binding.defined_with(DefModifiers::GLOB_IMPORTED) { - self.duplicate_globs.push(binding); - } else if old_binding.defined_with(DefModifiers::GLOB_IMPORTED) { - self.duplicate_globs.push(old_binding); - self.binding = Some(binding); - } else { - return Err(old_binding); - } + if let Some(old_binding) = self.binding { + if binding.defined_with(DefModifiers::GLOB_IMPORTED) { + self.duplicate_globs.push(binding); + } else if old_binding.defined_with(DefModifiers::GLOB_IMPORTED) { + self.duplicate_globs.push(old_binding); + self.binding = Some(binding); + } else { + return Err(old_binding); } - _ => self.binding = Some(binding), + } else { + self.binding = Some(binding); } Ok(()) @@ -160,7 +159,6 @@ impl<'a> NameResolution<'a> { fn try_result(&self, allow_private_imports: bool) -> Option>> { match self.result(allow_private_imports) { - Success(binding) if binding.defined_with(DefModifiers::PRELUDE) => None, Failed(_) => None, result @ _ => Some(result), } @@ -192,8 +190,6 @@ impl<'a> NameResolution<'a> { }; for duplicate_glob in self.duplicate_globs.iter() { - if duplicate_glob.defined_with(DefModifiers::PRELUDE) { continue } - // FIXME #31337: We currently allow items to shadow glob-imported re-exports. if !binding.is_import() { if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind { @@ -360,7 +356,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { // resolution for it so that later resolve stages won't complain. if let SingleImport { target, .. } = e.import_directive.subclass { let dummy_binding = self.resolver.arenas.alloc_name_binding(NameBinding { - modifiers: DefModifiers::PRELUDE, + modifiers: DefModifiers::GLOB_IMPORTED, kind: NameBindingKind::Def(Def::Err), span: None, });