about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2018-12-13 01:43:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-01-12 16:18:20 +0300
commit2f3db49c3d99d0338b4a47b62079da71c26db458 (patch)
tree5541c2fa88db3bbbdc5f07cdeeb8636a3b02e64f
parentbf1e70cd1f39c0879b36bead3b07a0fdfcfc4c32 (diff)
downloadrust-2f3db49c3d99d0338b4a47b62079da71c26db458.tar.gz
rust-2f3db49c3d99d0338b4a47b62079da71c26db458.zip
resolve: Prohibit use of imported tool modules
-rw-r--r--src/librustc_resolve/lib.rs7
-rw-r--r--src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs12
-rw-r--r--src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr34
-rw-r--r--src/test/ui/rust-2018/uniform-paths/prelude.rs4
4 files changed, 51 insertions, 6 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index cf949b62a63..e656e5329b5 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -3874,6 +3874,13 @@ impl<'a> Resolver<'a> {
                         module = Some(ModuleOrUniformRoot::Module(next_module));
                         record_segment_def(self, def);
                     } else if def == Def::ToolMod && i + 1 != path.len() {
+                        if binding.is_import() {
+                            self.session.struct_span_err(
+                                ident.span, "cannot use a tool module through an import"
+                            ).span_note(
+                                binding.span, "the tool module imported here"
+                            ).emit();
+                        }
                         let def = Def::NonMacroAttr(NonMacroAttrKind::Tool);
                         return PathResult::NonModule(PathResolution::new(def));
                     } else if def == Def::Err {
diff --git a/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs b/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
index 6488b89f369..e153e868b31 100644
--- a/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
+++ b/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
@@ -4,6 +4,18 @@
 
 // Built-in attribute
 use inline as imported_inline;
+mod builtin {
+    pub use inline as imported_inline;
+}
+
+// Tool module
+use rustfmt as imported_rustfmt;
+mod tool_mod {
+    pub use rustfmt as imported_rustfmt;
+}
 
 #[imported_inline] //~ ERROR cannot use a built-in attribute through an import
+#[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
+#[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
+#[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
 fn main() {}
diff --git a/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr b/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
index 10dd303aa28..4c49cd89bdc 100644
--- a/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
+++ b/src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr
@@ -1,5 +1,5 @@
 error: cannot use a built-in attribute through an import
-  --> $DIR/prelude-fail-2.rs:8:3
+  --> $DIR/prelude-fail-2.rs:17:3
    |
 LL | #[imported_inline] //~ ERROR cannot use a built-in attribute through an import
    |   ^^^^^^^^^^^^^^^
@@ -10,5 +10,35 @@ note: the built-in attribute imported here
 LL | use inline as imported_inline;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to previous error
+error: cannot use a built-in attribute through an import
+  --> $DIR/prelude-fail-2.rs:18:3
+   |
+LL | #[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
+   |   ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: cannot use a tool module through an import
+  --> $DIR/prelude-fail-2.rs:19:3
+   |
+LL | #[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
+   |   ^^^^^^^^^^^^^^^^
+   |
+note: the tool module imported here
+  --> $DIR/prelude-fail-2.rs:12:5
+   |
+LL | use rustfmt as imported_rustfmt;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: cannot use a tool module through an import
+  --> $DIR/prelude-fail-2.rs:20:13
+   |
+LL | #[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
+   |             ^^^^^^^^^^^^^^^^
+   |
+note: the tool module imported here
+  --> $DIR/prelude-fail-2.rs:14:13
+   |
+LL |     pub use rustfmt as imported_rustfmt;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
 
diff --git a/src/test/ui/rust-2018/uniform-paths/prelude.rs b/src/test/ui/rust-2018/uniform-paths/prelude.rs
index 46ce725fdba..1a6027f30d7 100644
--- a/src/test/ui/rust-2018/uniform-paths/prelude.rs
+++ b/src/test/ui/rust-2018/uniform-paths/prelude.rs
@@ -6,9 +6,6 @@
 // Macro imported with `#[macro_use] extern crate`
 use vec as imported_vec;
 
-// Tool module
-use rustfmt as imported_rustfmt;
-
 // Standard library prelude
 use Vec as ImportedVec;
 
@@ -17,7 +14,6 @@ use u8 as imported_u8;
 
 type A = imported_u8;
 
-#[imported_rustfmt::skip]
 fn main() {
     imported_vec![0];
     ImportedVec::<u8>::new();