about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-01-15 03:09:48 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-01-15 03:12:49 +0000
commitc02d577c53dc29fcef0c589af8d95d037777a09b (patch)
treee7fbd65371e7d459cb4fdbcb4bdbb1e0abca361d
parent6fe23719feb20c25a8b2693d1f196e72d8da9af5 (diff)
downloadrust-c02d577c53dc29fcef0c589af8d95d037777a09b.tar.gz
rust-c02d577c53dc29fcef0c589af8d95d037777a09b.zip
Improve the warning cycle for `use $crate;`.
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs5
-rw-r--r--src/test/compile-fail/auxiliary/import_crate_var.rs7
-rw-r--r--src/test/compile-fail/import-crate-var.rs6
3 files changed, 14 insertions, 4 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index 5be21bc62c5..5e985687886 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -143,7 +143,7 @@ impl<'a> Resolver<'a> {
                 let is_prelude = attr::contains_name(&item.attrs, "prelude_import");
 
                 match view_path.node {
-                    ViewPathSimple(binding, ref full_path) => {
+                    ViewPathSimple(mut binding, ref full_path) => {
                         let mut source = full_path.segments.last().unwrap().identifier;
                         let source_name = source.name;
                         if source_name == "mod" || source_name == "self" {
@@ -157,6 +157,9 @@ impl<'a> Resolver<'a> {
                                 ModuleKind::Block(..) => unreachable!(),
                             };
                             source.name = crate_name;
+                            if binding.name == "$crate" {
+                                binding.name = crate_name;
+                            }
 
                             self.session.struct_span_warn(item.span, "`$crate` may not be imported")
                                 .note("`use $crate;` was erroneously allowed and \
diff --git a/src/test/compile-fail/auxiliary/import_crate_var.rs b/src/test/compile-fail/auxiliary/import_crate_var.rs
index 1dfc7a128aa..a8a55afa41a 100644
--- a/src/test/compile-fail/auxiliary/import_crate_var.rs
+++ b/src/test/compile-fail/auxiliary/import_crate_var.rs
@@ -8,5 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+pub fn f() {}
+
 #[macro_export]
-macro_rules! m { () => { use $crate; } }
+macro_rules! m { () => {
+    use $crate;
+    import_crate_var::f();
+} }
diff --git a/src/test/compile-fail/import-crate-var.rs b/src/test/compile-fail/import-crate-var.rs
index 9f573945483..e58ba2c8891 100644
--- a/src/test/compile-fail/import-crate-var.rs
+++ b/src/test/compile-fail/import-crate-var.rs
@@ -11,11 +11,13 @@
 // aux-build:import_crate_var.rs
 // error-pattern: `$crate` may not be imported
 // error-pattern: `use $crate;` was erroneously allowed and will become a hard error
+// error-pattern: compilation successful
 
 #![feature(rustc_attrs)]
 
 #[macro_use] extern crate import_crate_var;
-m!();
 
 #[rustc_error]
-fn main() {}
+fn main() {
+    m!();
+}