]> git.lizzy.rs Git - rust.git/commitdiff
Resolve prefix in imports with empty braces
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 15 Sep 2015 21:50:50 +0000 (00:50 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 17 Sep 2015 11:13:14 +0000 (14:13 +0300)
src/librustc_front/visit.rs
src/librustc_resolve/lib.rs
src/libsyntax/visit.rs
src/test/compile-fail/issue-28388-1.rs [new file with mode: 0644]
src/test/compile-fail/issue-28388-2.rs [new file with mode: 0644]
src/test/compile-fail/issue-28388-3.rs [new file with mode: 0644]

index 12a20a8d21f49de6d46e935aa05eb21ae8487e3c..8f5208d3ef1192cfe362d84bafcde2da4b4c5516 100644 (file)
@@ -218,8 +218,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
                             visitor.visit_path_list_item(prefix, item)
                         }
                     } else {
-                        // FIXME(#28388) visit_path should be used instead of walk_path
-                        walk_path(visitor, prefix);
+                        visitor.visit_path(prefix, item.id);
                     }
                 }
             }
index 8e34118957ebd8bfa5e6c8f5ceaf4c6318165f33..6159ba5b79e0e6cd45abcf3e22d0f733dba22a5b 100644 (file)
@@ -2210,10 +2210,10 @@ fn resolve_item(&mut self, item: &Item) {
 
             ItemUse(ref view_path) => {
                 // check for imports shadowing primitive types
-                let check_rename = |id, ident: Ident| {
-                    match self.def_map.borrow().get(&id).map(|d| d.full_def()) {
+                let check_rename = |this: &Self, id, ident: Ident| {
+                    match this.def_map.borrow().get(&id).map(|d| d.full_def()) {
                         Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => {
-                            self.check_if_primitive_type_name(ident.name, item.span);
+                            this.check_if_primitive_type_name(ident.name, item.span);
                         }
                         _ => {}
                     }
@@ -2221,12 +2221,28 @@ fn resolve_item(&mut self, item: &Item) {
 
                 match view_path.node {
                     hir::ViewPathSimple(ident, _) => {
-                        check_rename(item.id, ident);
+                        check_rename(self, item.id, ident);
                     }
-                    hir::ViewPathList(_, ref items) => {
+                    hir::ViewPathList(ref prefix, ref items) => {
                         for item in items {
                             if let Some(ident) = item.node.rename() {
-                                check_rename(item.node.id(), ident);
+                                check_rename(self, item.node.id(), ident);
+                            }
+                        }
+
+                        // Resolve prefix of an import with empty braces (issue #28388)
+                        if items.is_empty() && !prefix.segments.is_empty() {
+                            match self.resolve_crate_relative_path(prefix.span,
+                                                                   &prefix.segments,
+                                                                   TypeNS) {
+                                Some((def, lp)) => self.record_def(item.id,
+                                                   PathResolution::new(def, lp, 0)),
+                                None => {
+                                    resolve_error(self,
+                                                  prefix.span,
+                                                  ResolutionError::FailedToResolve(
+                                                      &path_names_to_string(prefix, 0)));
+                                }
                             }
                         }
                     }
index cda750c5cda7e118efb7e466196ddd9bef5126c2..f4f4c9dfc24fb172ebc6b3a3dde4a5214b65d5a5 100644 (file)
@@ -224,8 +224,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
                             visitor.visit_path_list_item(prefix, item)
                         }
                     } else {
-                        // FIXME(#28388) visit_path should be used instead of walk_path
-                        walk_path(visitor, prefix);
+                        visitor.visit_path(prefix, item.id);
                     }
                 }
             }
diff --git a/src/test/compile-fail/issue-28388-1.rs b/src/test/compile-fail/issue-28388-1.rs
new file mode 100644 (file)
index 0000000..ef97b40
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
+
+use foo::{}; //~ ERROR failed to resolve. foo
+
+fn main() {}
diff --git a/src/test/compile-fail/issue-28388-2.rs b/src/test/compile-fail/issue-28388-2.rs
new file mode 100644 (file)
index 0000000..837dc67
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
+
+mod m {
+    mod n {}
+}
+
+use m::n::{}; //~ ERROR module `n` is private
+
+fn main() {}
diff --git a/src/test/compile-fail/issue-28388-3.rs b/src/test/compile-fail/issue-28388-3.rs
new file mode 100644 (file)
index 0000000..59756be
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc.
+
+use std::rt::{}; //~ ERROR use of unstable library feature 'rt'
+use std::{}; // OK
+
+fn main() {}