resolve: Prohibit use of imported tool modules

This commit is contained in:
Vadim Petrochenkov 2018-12-13 01:43:44 +03:00
parent bf1e70cd1f
commit 2f3db49c3d
4 changed files with 51 additions and 6 deletions

View File

@ -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 {

View File

@ -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() {}

View File

@ -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

View File

@ -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();