Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow prelude imports to shadow eachother (needed for the [pretty] te…
…sts)

Derive the Default impl for NameResolution
  • Loading branch information
jseyfried committed Feb 9, 2016
1 parent 3c62d90 commit 3df40c0
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -99,7 +99,7 @@ impl ImportDirective {
}
}

#[derive(Clone, Copy)]
#[derive(Clone, Default)]
/// Records information about the resolution of a name in a module.
pub struct NameResolution<'a> {
/// The number of unresolved single imports that could define the name.
Expand All @@ -108,12 +108,6 @@ pub struct NameResolution<'a> {
pub binding: Option<&'a NameBinding<'a>>,
}

impl<'a> Default for NameResolution<'a> {
fn default() -> Self {
NameResolution { outstanding_references: 0, binding: None }
}
}

impl<'a> NameResolution<'a> {
pub fn result(&self, outstanding_globs: usize) -> ResolveResult<&'a NameBinding<'a>> {
// If no unresolved imports (single or glob) can define the name, self.binding is final.
Expand All @@ -137,8 +131,8 @@ impl<'a> NameResolution<'a> {
pub fn try_define(&mut self, binding: &'a NameBinding<'a>) -> Result<(), &'a NameBinding<'a>> {
let is_prelude = |binding: &NameBinding| binding.defined_with(DefModifiers::PRELUDE);
let old_binding = match self.binding {
Some(old_binding) if is_prelude(binding) && !is_prelude(old_binding) => return Ok(()),
Some(old_binding) if is_prelude(old_binding) == is_prelude(binding) => old_binding,
Some(_) if is_prelude(binding) => return Ok(()),
Some(old_binding) if !is_prelude(old_binding) => old_binding,
_ => { self.binding = Some(binding); return Ok(()); }
};

Expand Down

0 comments on commit 3df40c0

Please sign in to comment.