Skip to content

Commit 49c425d

Browse files
committed
Disable use $crate::{self}
1 parent ce6daf3 commit 49c425d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
706706
}
707707

708708
e.emit();
709+
} else if let &[self_span] = &self_spans[..]
710+
&& prefix.len() == 1
711+
&& prefix[0].ident.name == kw::DollarCrate
712+
{
713+
// Disallow `use $crate::{self};`
714+
self.r.dcx().emit_err(errors::CrateImported { span: self_span });
709715
}
710716

711717
for &(ref tree, id) in items {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
macro_rules! foo {
2+
() => {
3+
use $crate::{self}; //~ ERROR `$crate` may not be imported
4+
};
5+
}
6+
7+
foo!();
8+
9+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: `$crate` may not be imported
2+
--> $DIR/use-dollar-crate-self.rs:3:22
3+
|
4+
LL | use $crate::{self};
5+
| ^^^^
6+
...
7+
LL | foo!();
8+
| ------ in this macro invocation
9+
|
10+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)