Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
resolve: Prohibit use of imported tool modules
  • Loading branch information
petrochenkov committed Jan 12, 2019
1 parent bf1e70c commit 2f3db49
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs
Expand Up @@ -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() {}
34 changes: 32 additions & 2 deletions 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
| ^^^^^^^^^^^^^^^
Expand All @@ -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

4 changes: 0 additions & 4 deletions src/test/ui/rust-2018/uniform-paths/prelude.rs
Expand Up @@ -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;

Expand All @@ -17,7 +14,6 @@ use u8 as imported_u8;

type A = imported_u8;

#[imported_rustfmt::skip]
fn main() {
imported_vec![0];
ImportedVec::<u8>::new();
Expand Down

0 comments on commit 2f3db49

Please sign in to comment.