Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "use $crate" a hard error #67775

Merged
merged 8 commits into from
Jan 4, 2020
Merged
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: 1 addition & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {

self.r
.session
.struct_span_warn(item.span, "`$crate` may not be imported")
.note(
"`use $crate;` was erroneously allowed and \
will become a hard error in a future release",
)
.struct_span_err(item.span, "`$crate` may not be imported")
.emit();
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/dollar-crate/dollar-crate-is-keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ macro_rules! m {
struct $crate {} //~ ERROR expected identifier, found reserved identifier `$crate`
}

use $crate; // OK
//~^ WARN `$crate` may not be imported
use $crate; //~ ERROR `$crate` may not be imported
use $crate as $crate; //~ ERROR expected identifier, found reserved identifier `$crate`
//~^ WARN `$crate` may not be imported
//~^ ERROR `$crate` may not be imported
}
}

Expand Down
16 changes: 6 additions & 10 deletions src/test/ui/dollar-crate/dollar-crate-is-keyword.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@ LL | m!();
| ----- in this macro invocation

error: expected identifier, found reserved identifier `$crate`
--> $DIR/dollar-crate-is-keyword.rs:11:23
--> $DIR/dollar-crate-is-keyword.rs:10:23
|
LL | use $crate as $crate;
| ^^^^^^ expected identifier, found reserved identifier
...
LL | m!();
| ----- in this macro invocation

warning: `$crate` may not be imported
error: `$crate` may not be imported
--> $DIR/dollar-crate-is-keyword.rs:9:9
|
LL | use $crate; // OK
LL | use $crate;
| ^^^^^^^^^^^
...
LL | m!();
| ----- in this macro invocation
|
= note: `use $crate;` was erroneously allowed and will become a hard error in a future release

warning: `$crate` may not be imported
--> $DIR/dollar-crate-is-keyword.rs:11:9
error: `$crate` may not be imported
--> $DIR/dollar-crate-is-keyword.rs:10:9
|
LL | use $crate as $crate;
| ^^^^^^^^^^^^^^^^^^^^^
...
LL | m!();
| ----- in this macro invocation
|
= note: `use $crate;` was erroneously allowed and will become a hard error in a future release

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors
mental32 marked this conversation as resolved.
Show resolved Hide resolved

4 changes: 1 addition & 3 deletions src/test/ui/imports/import-crate-var.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// check-pass
// aux-build:import_crate_var.rs

#[macro_use] extern crate import_crate_var;

fn main() {
m!();
//~^ WARN `$crate` may not be imported
//~| NOTE `use $crate;` was erroneously allowed and will become a hard error
//~^ ERROR `$crate` may not be imported
}
9 changes: 5 additions & 4 deletions src/test/ui/imports/import-crate-var.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
warning: `$crate` may not be imported
--> $DIR/import-crate-var.rs:7:5
error: `$crate` may not be imported
--> $DIR/import-crate-var.rs:6:5
|
LL | m!();
| ^^^^^
|
= note: `use $crate;` was erroneously allowed and will become a hard error in a future release
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error
mental32 marked this conversation as resolved.
Show resolved Hide resolved