From 2f3db49c3d99d0338b4a47b62079da71c26db458 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 13 Dec 2018 01:43:44 +0300 Subject: [PATCH] resolve: Prohibit use of imported tool modules --- src/librustc_resolve/lib.rs | 7 ++++ .../rust-2018/uniform-paths/prelude-fail-2.rs | 12 +++++++ .../uniform-paths/prelude-fail-2.stderr | 34 +++++++++++++++++-- .../ui/rust-2018/uniform-paths/prelude.rs | 4 --- 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 @@ fn resolve_path( 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 @@ type A = imported_u8; -#[imported_rustfmt::skip] fn main() { imported_vec![0]; ImportedVec::::new(); -- 2.44.0