Skip to content

Commit 2f3db49

Browse files
committed
resolve: Prohibit use of imported tool modules
1 parent bf1e70c commit 2f3db49

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

src/librustc_resolve/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,13 @@ impl<'a> Resolver<'a> {
38743874
module = Some(ModuleOrUniformRoot::Module(next_module));
38753875
record_segment_def(self, def);
38763876
} else if def == Def::ToolMod && i + 1 != path.len() {
3877+
if binding.is_import() {
3878+
self.session.struct_span_err(
3879+
ident.span, "cannot use a tool module through an import"
3880+
).span_note(
3881+
binding.span, "the tool module imported here"
3882+
).emit();
3883+
}
38773884
let def = Def::NonMacroAttr(NonMacroAttrKind::Tool);
38783885
return PathResult::NonModule(PathResolution::new(def));
38793886
} else if def == Def::Err {

src/test/ui/rust-2018/uniform-paths/prelude-fail-2.rs

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
// Built-in attribute
66
use inline as imported_inline;
7+
mod builtin {
8+
pub use inline as imported_inline;
9+
}
10+
11+
// Tool module
12+
use rustfmt as imported_rustfmt;
13+
mod tool_mod {
14+
pub use rustfmt as imported_rustfmt;
15+
}
716

817
#[imported_inline] //~ ERROR cannot use a built-in attribute through an import
18+
#[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
19+
#[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
20+
#[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
921
fn main() {}

src/test/ui/rust-2018/uniform-paths/prelude-fail-2.stderr

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cannot use a built-in attribute through an import
2-
--> $DIR/prelude-fail-2.rs:8:3
2+
--> $DIR/prelude-fail-2.rs:17:3
33
|
44
LL | #[imported_inline] //~ ERROR cannot use a built-in attribute through an import
55
| ^^^^^^^^^^^^^^^
@@ -10,5 +10,35 @@ note: the built-in attribute imported here
1010
LL | use inline as imported_inline;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: aborting due to previous error
13+
error: cannot use a built-in attribute through an import
14+
--> $DIR/prelude-fail-2.rs:18:3
15+
|
16+
LL | #[builtin::imported_inline] //~ ERROR cannot use a built-in attribute through an import
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: cannot use a tool module through an import
20+
--> $DIR/prelude-fail-2.rs:19:3
21+
|
22+
LL | #[imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
23+
| ^^^^^^^^^^^^^^^^
24+
|
25+
note: the tool module imported here
26+
--> $DIR/prelude-fail-2.rs:12:5
27+
|
28+
LL | use rustfmt as imported_rustfmt;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: cannot use a tool module through an import
32+
--> $DIR/prelude-fail-2.rs:20:13
33+
|
34+
LL | #[tool_mod::imported_rustfmt::skip] //~ ERROR cannot use a tool module through an import
35+
| ^^^^^^^^^^^^^^^^
36+
|
37+
note: the tool module imported here
38+
--> $DIR/prelude-fail-2.rs:14:13
39+
|
40+
LL | pub use rustfmt as imported_rustfmt;
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: aborting due to 4 previous errors
1444

src/test/ui/rust-2018/uniform-paths/prelude.rs

-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
// Macro imported with `#[macro_use] extern crate`
77
use vec as imported_vec;
88

9-
// Tool module
10-
use rustfmt as imported_rustfmt;
11-
129
// Standard library prelude
1310
use Vec as ImportedVec;
1411

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

1815
type A = imported_u8;
1916

20-
#[imported_rustfmt::skip]
2117
fn main() {
2218
imported_vec![0];
2319
ImportedVec::<u8>::new();

0 commit comments

Comments
 (0)