Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
}

e.emit();
} else if let &[self_span] = &self_spans[..]
&& prefix.len() == 1
&& prefix[0].ident.name == kw::DollarCrate
{
// Disallow `use $crate::{self};`
self.r.dcx().emit_err(errors::CrateImported { span: self_span });
}

for &(ref tree, id) in items {
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/dollar-crate/use-dollar-crate-self.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
macro_rules! foo {
() => {
use $crate::{self}; //~ ERROR `$crate` may not be imported
};
}

foo!();

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/dollar-crate/use-dollar-crate-self.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: `$crate` may not be imported
--> $DIR/use-dollar-crate-self.rs:3:22
|
LL | use $crate::{self};
| ^^^^
...
LL | foo!();
| ------ in this macro invocation
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

Loading