]> git.lizzy.rs Git - rust.git/commitdiff
extract helper fn
authorDouglas Campos <qmx@qmx.me>
Thu, 5 Jul 2018 13:36:17 +0000 (13:36 +0000)
committerDouglas Campos <qmx@qmx.me>
Thu, 16 Aug 2018 19:19:36 +0000 (19:19 +0000)
src/librustc_resolve/lib.rs

index 992ea12ffa2b14c44dde94f4fdfc303ac356d791..958c496d9845bba7618afed9b99f3110acb691f5 100644 (file)
@@ -4232,16 +4232,10 @@ fn get_traits_in_module_containing_item(&mut self,
         }
     }
 
-    /// When name resolution fails, this method can be used to look up candidate
-    /// entities with the expected name. It allows filtering them using the
-    /// supplied predicate (which should be used to only accept the types of
-    /// definitions expected e.g. traits). The lookup spans across all crates.
-    ///
-    /// NOTE: The method does not look into imports, but this is not a problem,
-    /// since we report the definitions (thus, the de-aliased imports).
-    fn lookup_import_candidates<FilterFn>(&mut self,
+    fn lookup_import_candidates_from_module<FilterFn>(&mut self,
                                           lookup_name: Name,
                                           namespace: Namespace,
+                                          start_module: &'a ModuleData<'a>,
                                           filter_fn: FilterFn)
                                           -> Vec<ImportSuggestion>
         where FilterFn: Fn(Def) -> bool
@@ -4249,7 +4243,7 @@ fn lookup_import_candidates<FilterFn>(&mut self,
         let mut candidates = Vec::new();
         let mut worklist = Vec::new();
         let mut seen_modules = FxHashSet();
-        worklist.push((self.graph_root, Vec::new(), false));
+        worklist.push((start_module, Vec::new(), false));
 
         while let Some((in_module,
                         path_segments,
@@ -4318,6 +4312,23 @@ fn lookup_import_candidates<FilterFn>(&mut self,
         candidates
     }
 
+    /// When name resolution fails, this method can be used to look up candidate
+    /// entities with the expected name. It allows filtering them using the
+    /// supplied predicate (which should be used to only accept the types of
+    /// definitions expected e.g. traits). The lookup spans across all crates.
+    ///
+    /// NOTE: The method does not look into imports, but this is not a problem,
+    /// since we report the definitions (thus, the de-aliased imports).
+    fn lookup_import_candidates<FilterFn>(&mut self,
+                                          lookup_name: Name,
+                                          namespace: Namespace,
+                                          filter_fn: FilterFn)
+                                          -> Vec<ImportSuggestion>
+        where FilterFn: Fn(Def) -> bool
+    {
+        self.lookup_import_candidates_from_module(lookup_name, namespace, self.graph_root, filter_fn)
+    }
+
     fn find_module(&mut self,
                    module_def: Def)
                    -> Option<(Module<'a>, ImportSuggestion)>