about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-07-31 20:40:03 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-07-31 20:40:03 +0000
commit93fd214d61749ecae05a9ff240d51fcf77ca086c (patch)
tree96e93729e7da3f3bbde5a3298235500694c117d8
parent46bd5d3fa01a86925f7e7776a5567c536e6f2408 (diff)
downloadrust-93fd214d61749ecae05a9ff240d51fcf77ca086c.tar.gz
rust-93fd214d61749ecae05a9ff240d51fcf77ca086c.zip
Clean up `resolve_trait_reference`.
-rw-r--r--src/librustc_resolve/lib.rs63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 23281d25c8d..33e5282188c 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -1807,41 +1807,40 @@ impl<'a> Resolver<'a> {
                                path_depth: usize)
                                -> Result<PathResolution, ()> {
         self.resolve_path(id, trait_path, path_depth, TypeNS).and_then(|path_res| {
-            if let Def::Trait(_) = path_res.base_def {
-                debug!("(resolving trait) found trait def: {:?}", path_res);
-                Ok(path_res)
-            } else if path_res.base_def == Def::Err {
-                Err(true)
-            } else {
-                let mut err =
-                    resolve_struct_error(self,
-                                  trait_path.span,
-                                  ResolutionError::IsNotATrait(&path_names_to_string(trait_path,
-                                                                                      path_depth)));
-
-                // If it's a typedef, give a note
-                if let Def::TyAlias(..) = path_res.base_def {
-                    let trait_name = trait_path.segments.last().unwrap().identifier.name;
-                    err.span_label(trait_path.span,
-                                   &format!("`{}` is not a trait", trait_name));
-
-                    let definition_site = {
-                        let segments = &trait_path.segments;
-                        if trait_path.global {
-                            self.resolve_crate_relative_path(trait_path.span, segments, TypeNS)
-                        } else {
-                            self.resolve_module_relative_path(trait_path.span, segments, TypeNS)
-                        }.map(|binding| binding.span).unwrap_or(syntax_pos::DUMMY_SP)
-                    };
+            match path_res.base_def {
+                Def::Trait(_) => {
+                    debug!("(resolving trait) found trait def: {:?}", path_res);
+                    return Ok(path_res);
+                }
+                Def::Err => return Err(true),
+                _ => {}
+            }
 
-                    if definition_site != syntax_pos::DUMMY_SP {
-                        err.span_label(definition_site,
-                                       &format!("type aliases cannot be used for traits"));
-                    }
+            let mut err = resolve_struct_error(self, trait_path.span, {
+                ResolutionError::IsNotATrait(&path_names_to_string(trait_path, path_depth))
+            });
+
+            // If it's a typedef, give a note
+            if let Def::TyAlias(..) = path_res.base_def {
+                let trait_name = trait_path.segments.last().unwrap().identifier.name;
+                err.span_label(trait_path.span, &format!("`{}` is not a trait", trait_name));
+
+                let definition_site = {
+                    let segments = &trait_path.segments;
+                    if trait_path.global {
+                        self.resolve_crate_relative_path(trait_path.span, segments, TypeNS)
+                    } else {
+                        self.resolve_module_relative_path(trait_path.span, segments, TypeNS)
+                    }.map(|binding| binding.span).unwrap_or(syntax_pos::DUMMY_SP)
+                };
+
+                if definition_site != syntax_pos::DUMMY_SP {
+                    err.span_label(definition_site,
+                                   &format!("type aliases cannot be used for traits"));
                 }
-                err.emit();
-                Err(true)
             }
+            err.emit();
+            Err(true)
         }).map_err(|error_reported| {
             if error_reported { return }