Skip to content

Commit

Permalink
Simplify binding.module().
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Nov 29, 2016
1 parent 7bccc9d commit 8fe525d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,11 @@ struct AmbiguityError<'a> {
}

impl<'a> NameBinding<'a> {
fn module(&self) -> Result<Module<'a>, bool /* true if an error has already been reported */> {
fn module(&self) -> Option<Module<'a>> {
match self.kind {
NameBindingKind::Module(module) => Ok(module),
NameBindingKind::Module(module) => Some(module),
NameBindingKind::Import { binding, .. } => binding.module(),
NameBindingKind::Def(Def::Err) => Err(true),
NameBindingKind::Def(_) => Err(false),
NameBindingKind::Ambiguity { .. } => Err(false),
_ => None,
}
}

Expand Down Expand Up @@ -1332,7 +1330,7 @@ impl<'a> Resolver<'a> {
fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
-> bool /* true if an error was reported */ {
// track extern crates for unused_extern_crate lint
if let Some(DefId { krate, .. }) = binding.module().ok().and_then(ModuleS::def_id) {
if let Some(DefId { krate, .. }) = binding.module().and_then(ModuleS::def_id) {
self.used_crates.insert(krate);
}

Expand Down Expand Up @@ -2372,7 +2370,7 @@ impl<'a> Resolver<'a> {

match binding {
Ok(binding) => {
if let Ok(next_module) = binding.module() {
if let Some(next_module) = binding.module() {
module = Some(next_module);
} else if binding.def() == Def::Err {
return PathResult::NonModule(err_path_resolution());
Expand Down Expand Up @@ -2980,7 +2978,7 @@ impl<'a> Resolver<'a> {
}

// collect submodules to explore
if let Ok(module) = name_binding.module() {
if let Some(module) = name_binding.module() {
// form the path
let mut path_segments = path_segments.clone();
path_segments.push(PathSegment {
Expand Down Expand Up @@ -3141,8 +3139,8 @@ impl<'a> Resolver<'a> {
(ValueNS, _) => "a value",
(MacroNS, _) => "a macro",
(TypeNS, _) if old_binding.is_extern_crate() => "an extern crate",
(TypeNS, Ok(module)) if module.is_normal() => "a module",
(TypeNS, Ok(module)) if module.is_trait() => "a trait",
(TypeNS, Some(module)) if module.is_normal() => "a module",
(TypeNS, Some(module)) if module.is_trait() => "a trait",
(TypeNS, _) => "a type",
};
format!("{} named `{}` has already been {} in this {}",
Expand Down

0 comments on commit 8fe525d

Please sign in to comment.