]> git.lizzy.rs Git - rust.git/commitdiff
prepend crate:: when crate_in_path feature is enabled
authorDouglas Campos <qmx@qmx.me>
Mon, 16 Jul 2018 12:55:37 +0000 (12:55 +0000)
committerDouglas Campos <qmx@qmx.me>
Thu, 16 Aug 2018 19:19:54 +0000 (19:19 +0000)
src/librustc_resolve/lib.rs

index 958c496d9845bba7618afed9b99f3110acb691f5..292a5825d5d6ec65f70f32b01bae27dc371eb0d1 100644 (file)
@@ -4236,6 +4236,7 @@ fn lookup_import_candidates_from_module<FilterFn>(&mut self,
                                           lookup_name: Name,
                                           namespace: Namespace,
                                           start_module: &'a ModuleData<'a>,
+                                          graph_root: bool,
                                           filter_fn: FilterFn)
                                           -> Vec<ImportSuggestion>
         where FilterFn: Fn(Def) -> bool
@@ -4262,17 +4263,14 @@ fn lookup_import_candidates_from_module<FilterFn>(&mut self,
                 if ident.name == lookup_name && ns == namespace {
                     if filter_fn(name_binding.def()) {
                         // create the path
-                        let mut segms = if self.session.rust_2018() && !in_module_is_extern {
+                        let mut segms = path_segments.clone();
+                        if self.session.rust_2018() && !in_module_is_extern {
                             // crate-local absolute paths start with `crate::` in edition 2018
                             // FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
-                            let mut full_segms = vec![
-                                ast::PathSegment::from_ident(keywords::Crate.ident())
-                            ];
-                            full_segms.extend(path_segments.clone());
-                            full_segms
-                        } else {
-                            path_segments.clone()
-                        };
+                            if graph_root {
+                                segms.insert(0, ast::PathSegment::from_ident(keywords::Crate.ident()));
+                            }
+                        }
 
                         segms.push(ast::PathSegment::from_ident(ident));
                         let path = Path {
@@ -4326,7 +4324,7 @@ fn lookup_import_candidates<FilterFn>(&mut self,
                                           -> Vec<ImportSuggestion>
         where FilterFn: Fn(Def) -> bool
     {
-        self.lookup_import_candidates_from_module(lookup_name, namespace, self.graph_root, filter_fn)
+        self.lookup_import_candidates_from_module(lookup_name, namespace, self.graph_root, true, filter_fn)
     }
 
     fn find_module(&mut self,