From 9eb7a3c76fe826b646a0a5a747292a5643f9e197 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 24 Aug 2018 18:51:32 +0300 Subject: [PATCH] rustc_resolve: don't allow `::crate_name` to bypass `extern_prelude`. --- src/librustc_resolve/resolve_imports.rs | 12 ++++++++-- .../save-analysis-rfc2126/Makefile | 6 +++-- src/test/ui/issues/issue-52489.rs | 1 + src/test/ui/issues/issue-52489.stderr | 2 +- .../non-existent-1.rs | 2 +- .../non-existent-1.stderr | 8 +++---- .../non-existent-2.rs | 3 ++- .../non-existent-2.stderr | 8 +++---- .../non-existent-3.rs | 2 +- .../non-existent-3.stderr | 8 +++---- .../single-segment.rs | 1 + .../single-segment.stderr | 6 ++--- .../non-existent-1.rs | 2 +- .../non-existent-1.stderr | 8 +++---- .../non-existent-2.rs | 3 ++- .../non-existent-2.stderr | 8 +++---- .../non-existent-3.rs | 2 +- .../non-existent-3.stderr | 10 ++++---- .../single-segment.rs | 1 + .../single-segment.stderr | 6 ++--- .../ui/run-pass/issues/issue-52140/main.rs | 1 + .../ui/run-pass/issues/issue-52141/main.rs | 1 + .../ui/run-pass/issues/issue-52705/main.rs | 1 + .../rfc-2126-extern-absolute-paths/basic.rs | 1 + .../rfc-2126-extern-absolute-paths/extern.rs | 1 + .../extern-crate-idiomatic-in-2018.fixed | 1 + .../extern-crate-idiomatic-in-2018.rs | 1 + .../extern-crate-idiomatic-in-2018.stderr | 6 ++--- .../ui/rust-2018/extern-crate-idiomatic.fixed | 1 + .../ui/rust-2018/extern-crate-idiomatic.rs | 1 + src/test/ui/rust-2018/issue-54006.rs | 23 +++++++++++++++++++ src/test/ui/rust-2018/issue-54006.stderr | 17 ++++++++++++++ .../ui/rust-2018/remove-extern-crate.fixed | 1 + src/test/ui/rust-2018/remove-extern-crate.rs | 1 + .../ui/rust-2018/remove-extern-crate.stderr | 8 +++---- 35 files changed, 115 insertions(+), 49 deletions(-) create mode 100644 src/test/ui/rust-2018/issue-54006.rs create mode 100644 src/test/ui/rust-2018/issue-54006.stderr diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index e7d3a8ef661..c86d430face 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -196,7 +196,11 @@ pub fn resolve_ident_in_module_unadjusted(&mut self, } // Fall back to resolving to an external crate. - if !(ns == TypeNS && self.extern_prelude.contains(&ident.name)) { + if !( + ns == TypeNS && + !ident.is_path_segment_keyword() && + self.extern_prelude.contains(&ident.name) + ) { // ... unless the crate name is not in the `extern_prelude`. return binding; } @@ -211,7 +215,11 @@ pub fn resolve_ident_in_module_unadjusted(&mut self, ) { self.resolve_crate_root(ident) - } else if ns == TypeNS && !ident.is_path_segment_keyword() { + } else if + ns == TypeNS && + !ident.is_path_segment_keyword() && + self.extern_prelude.contains(&ident.name) + { let crate_id = self.crate_loader.process_path_extern(ident.name, ident.span); self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX }) diff --git a/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile b/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile index 6a67b5862a8..2b931d89f1f 100644 --- a/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile +++ b/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile @@ -1,9 +1,11 @@ -include ../tools.mk all: extern_absolute_paths.rs extern_in_paths.rs krate2 - $(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018 + $(RUSTC) extern_absolute_paths.rs -Zsave-analysis --edition=2018 \ + -Z unstable-options --extern krate2 cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py - $(RUSTC) extern_in_paths.rs -Zsave-analysis --edition=2018 + $(RUSTC) extern_in_paths.rs -Zsave-analysis --edition=2018 \ + -Z unstable-options --extern krate2 cat $(TMPDIR)/save-analysis/extern_in_paths.json | "$(PYTHON)" validate_json.py krate2: krate2.rs diff --git a/src/test/ui/issues/issue-52489.rs b/src/test/ui/issues/issue-52489.rs index c43cc12ca02..f26392e82ac 100644 --- a/src/test/ui/issues/issue-52489.rs +++ b/src/test/ui/issues/issue-52489.rs @@ -10,6 +10,7 @@ // edition:2018 // aux-build:issue-52489.rs +// compile-flags:--extern issue_52489 use issue_52489; //~^ ERROR use of unstable library feature 'issue_52489_unstable' diff --git a/src/test/ui/issues/issue-52489.stderr b/src/test/ui/issues/issue-52489.stderr index 5b38a0789ad..b8c41d82643 100644 --- a/src/test/ui/issues/issue-52489.stderr +++ b/src/test/ui/issues/issue-52489.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature 'issue_52489_unstable' - --> $DIR/issue-52489.rs:14:5 + --> $DIR/issue-52489.rs:15:5 | LL | use issue_52489; | ^^^^^^^^^^^ diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.rs index 826bf675bd6..a259266420a 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.rs @@ -10,6 +10,6 @@ // edition:2018 -use xcrate::S; //~ ERROR can't find crate for `xcrate` +use xcrate::S; //~ ERROR unresolved import `xcrate` fn main() {} diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.stderr index 27a69ec1b1f..1a8ceec5dac 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-1.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `xcrate` +error[E0432]: unresolved import `xcrate` --> $DIR/non-existent-1.rs:13:5 | -LL | use xcrate::S; //~ ERROR can't find crate for `xcrate` - | ^^^^^^ can't find crate +LL | use xcrate::S; //~ ERROR unresolved import `xcrate` + | ^^^^^^ Could not find `xcrate` in `{{root}}` error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs index 053bf92f4d1..41adb974f21 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs @@ -11,5 +11,6 @@ // edition:2018 fn main() { - let s = ::xcrate::S; //~ ERROR can't find crate for `xcrate` + let s = ::xcrate::S; + //~^ ERROR failed to resolve. Could not find `xcrate` in `{{root}}` } diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr index eb96d5f05d7..b46576b0143 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `xcrate` +error[E0433]: failed to resolve. Could not find `xcrate` in `{{root}}` --> $DIR/non-existent-2.rs:14:15 | -LL | let s = ::xcrate::S; //~ ERROR can't find crate for `xcrate` - | ^^^^^^ can't find crate +LL | let s = ::xcrate::S; + | ^^^^^^ Could not find `xcrate` in `{{root}}` error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.rs index 1b9e5a75e83..0cbeb8cf50f 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.rs @@ -10,6 +10,6 @@ // edition:2018 -use ycrate; //~ ERROR can't find crate for `ycrate` +use ycrate; //~ ERROR unresolved import `ycrate` fn main() {} diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.stderr index 434bde79a83..31486e14bd2 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-3.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `ycrate` +error[E0432]: unresolved import `ycrate` --> $DIR/non-existent-3.rs:13:5 | -LL | use ycrate; //~ ERROR can't find crate for `ycrate` - | ^^^^^^ can't find crate +LL | use ycrate; //~ ERROR unresolved import `ycrate` + | ^^^^^^ no `ycrate` external crate error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs index 69fc4b4f7f8..b5b1485f662 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs +++ b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.rs @@ -9,6 +9,7 @@ // except according to those terms. // aux-build:xcrate.rs +// compile-flags:--extern xcrate // edition:2018 use crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;` diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr index cfb1a0ac39a..b49291b9c0c 100644 --- a/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr +++ b/src/test/ui/rfc-2126-extern-absolute-paths/single-segment.stderr @@ -1,17 +1,17 @@ error: crate root imports need to be explicitly named: `use crate as name;` - --> $DIR/single-segment.rs:14:5 + --> $DIR/single-segment.rs:15:5 | LL | use crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;` | ^^^^^ error: cannot glob-import all possible crates - --> $DIR/single-segment.rs:15:5 + --> $DIR/single-segment.rs:16:5 | LL | use *; //~ ERROR cannot glob-import all possible crates | ^ error[E0423]: expected value, found module `xcrate` - --> $DIR/single-segment.rs:18:13 + --> $DIR/single-segment.rs:19:13 | LL | let s = ::xcrate; //~ ERROR expected value, found module `xcrate` | ^^^^^^^^ not a value diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs b/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs index 7eba02ed444..c17e74c547c 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.rs @@ -10,6 +10,6 @@ #![feature(extern_in_paths)] -use extern::xcrate::S; //~ ERROR can't find crate for `xcrate` +use extern::xcrate::S; //~ ERROR unresolved import `extern::xcrate` fn main() {} diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr b/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr index c25698c395e..55b8b625507 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-1.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `xcrate` +error[E0432]: unresolved import `extern::xcrate` --> $DIR/non-existent-1.rs:13:13 | -LL | use extern::xcrate::S; //~ ERROR can't find crate for `xcrate` - | ^^^^^^ can't find crate +LL | use extern::xcrate::S; //~ ERROR unresolved import `extern::xcrate` + | ^^^^^^ Could not find `xcrate` in `extern` error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs b/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs index 4d09a05253e..128ecf41a30 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.rs @@ -11,5 +11,6 @@ #![feature(extern_in_paths)] fn main() { - let s = extern::xcrate::S; //~ ERROR can't find crate for `xcrate` + let s = extern::xcrate::S; + //~^ ERROR failed to resolve. Could not find `xcrate` in `extern` } diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr b/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr index b7ca8890c19..7fbe50a9202 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-2.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `xcrate` +error[E0433]: failed to resolve. Could not find `xcrate` in `extern` --> $DIR/non-existent-2.rs:14:21 | -LL | let s = extern::xcrate::S; //~ ERROR can't find crate for `xcrate` - | ^^^^^^ can't find crate +LL | let s = extern::xcrate::S; + | ^^^^^^ Could not find `xcrate` in `extern` error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs b/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs index 402d294b2e3..350cca70487 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.rs @@ -10,6 +10,6 @@ #![feature(extern_in_paths)] -use extern::ycrate; //~ ERROR can't find crate for `ycrate` +use extern::ycrate; //~ ERROR unresolved import `extern::ycrate` fn main() {} diff --git a/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr b/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr index fbea89ae93a..0a49d172169 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr +++ b/src/test/ui/rfc-2126-extern-in-paths/non-existent-3.stderr @@ -1,9 +1,9 @@ -error[E0463]: can't find crate for `ycrate` - --> $DIR/non-existent-3.rs:13:13 +error[E0432]: unresolved import `extern::ycrate` + --> $DIR/non-existent-3.rs:13:5 | -LL | use extern::ycrate; //~ ERROR can't find crate for `ycrate` - | ^^^^^^ can't find crate +LL | use extern::ycrate; //~ ERROR unresolved import `extern::ycrate` + | ^^^^^^^^^^^^^^ no `ycrate` external crate error: aborting due to previous error -For more information about this error, try `rustc --explain E0463`. +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rfc-2126-extern-in-paths/single-segment.rs b/src/test/ui/rfc-2126-extern-in-paths/single-segment.rs index 017844a0252..ea448863703 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/single-segment.rs +++ b/src/test/ui/rfc-2126-extern-in-paths/single-segment.rs @@ -9,6 +9,7 @@ // except according to those terms. // aux-build:xcrate.rs +// compile-flags:--extern xcrate #![feature(extern_in_paths)] diff --git a/src/test/ui/rfc-2126-extern-in-paths/single-segment.stderr b/src/test/ui/rfc-2126-extern-in-paths/single-segment.stderr index 8b1dd89fe3c..033bedb3b93 100644 --- a/src/test/ui/rfc-2126-extern-in-paths/single-segment.stderr +++ b/src/test/ui/rfc-2126-extern-in-paths/single-segment.stderr @@ -1,17 +1,17 @@ error: cannot glob-import all possible crates - --> $DIR/single-segment.rs:17:5 + --> $DIR/single-segment.rs:18:5 | LL | use extern::*; //~ ERROR cannot glob-import all possible crates | ^^^^^^^^^ error[E0432]: unresolved import `extern` - --> $DIR/single-segment.rs:15:5 + --> $DIR/single-segment.rs:16:5 | LL | use extern; //~ ERROR unresolved import `extern` | ^^^^^^ no `extern` in the root error[E0423]: expected value, found module `extern::xcrate` - --> $DIR/single-segment.rs:20:13 + --> $DIR/single-segment.rs:21:13 | LL | let s = extern::xcrate; //~ ERROR expected value, found module `extern::xcrate` | ^^^^^^^^^^^^^^ not a value diff --git a/src/test/ui/run-pass/issues/issue-52140/main.rs b/src/test/ui/run-pass/issues/issue-52140/main.rs index c17a4796555..3d727e2ad1b 100644 --- a/src/test/ui/run-pass/issues/issue-52140/main.rs +++ b/src/test/ui/run-pass/issues/issue-52140/main.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:some_crate.rs +// compile-flags:--extern some_crate // edition:2018 mod foo { diff --git a/src/test/ui/run-pass/issues/issue-52141/main.rs b/src/test/ui/run-pass/issues/issue-52141/main.rs index d1003bb2908..20705dc38e1 100644 --- a/src/test/ui/run-pass/issues/issue-52141/main.rs +++ b/src/test/ui/run-pass/issues/issue-52141/main.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:some_crate.rs +// compile-flags:--extern some_crate // edition:2018 use some_crate as some_name; diff --git a/src/test/ui/run-pass/issues/issue-52705/main.rs b/src/test/ui/run-pass/issues/issue-52705/main.rs index 3d828ba60d3..00cb5ac103a 100644 --- a/src/test/ui/run-pass/issues/issue-52705/main.rs +++ b/src/test/ui/run-pass/issues/issue-52705/main.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:png2.rs +// compile-flags:--extern png2 // edition:2018 mod png { diff --git a/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs b/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs index c5a356d979d..b13602297a4 100644 --- a/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs +++ b/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/basic.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:xcrate.rs +// compile-flags:--extern xcrate // edition:2018 use xcrate::Z; diff --git a/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs b/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs index 3d31c2d3a4d..0d84ccc3d32 100644 --- a/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs +++ b/src/test/ui/run-pass/rfcs/rfc-2126-extern-absolute-paths/extern.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:xcrate.rs +// compile-flags:--extern xcrate #![feature(extern_in_paths)] diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed index fc81ab08f62..36a837509c5 100644 --- a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed @@ -10,6 +10,7 @@ // aux-build:edition-lint-paths.rs // run-rustfix +// compile-flags:--extern edition_lint_paths // edition:2018 // The "normal case". Ideally we would remove the `extern crate` here, diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs index 72751f2080c..9daa4145630 100644 --- a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs @@ -10,6 +10,7 @@ // aux-build:edition-lint-paths.rs // run-rustfix +// compile-flags:--extern edition_lint_paths // edition:2018 // The "normal case". Ideally we would remove the `extern crate` here, diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr index 0ecfd4e4a2c..b3afa2bd1d5 100644 --- a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr @@ -1,18 +1,18 @@ error: unused extern crate - --> $DIR/extern-crate-idiomatic-in-2018.rs:21:1 + --> $DIR/extern-crate-idiomatic-in-2018.rs:22:1 | LL | extern crate edition_lint_paths; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here - --> $DIR/extern-crate-idiomatic-in-2018.rs:18:9 + --> $DIR/extern-crate-idiomatic-in-2018.rs:19:9 | LL | #![deny(rust_2018_idioms)] | ^^^^^^^^^^^^^^^^ = note: #[deny(unused_extern_crates)] implied by #[deny(rust_2018_idioms)] error: `extern crate` is not idiomatic in the new edition - --> $DIR/extern-crate-idiomatic-in-2018.rs:24:1 + --> $DIR/extern-crate-idiomatic-in-2018.rs:25:1 | LL | extern crate edition_lint_paths as bar; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic.fixed b/src/test/ui/rust-2018/extern-crate-idiomatic.fixed index a874a622202..0be1f2cc72b 100644 --- a/src/test/ui/rust-2018/extern-crate-idiomatic.fixed +++ b/src/test/ui/rust-2018/extern-crate-idiomatic.fixed @@ -10,6 +10,7 @@ // run-pass // aux-build:edition-lint-paths.rs +// compile-flags:--extern edition_lint_paths // run-rustfix // The "normal case". Ideally we would remove the `extern crate` here, diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic.rs b/src/test/ui/rust-2018/extern-crate-idiomatic.rs index a874a622202..0be1f2cc72b 100644 --- a/src/test/ui/rust-2018/extern-crate-idiomatic.rs +++ b/src/test/ui/rust-2018/extern-crate-idiomatic.rs @@ -10,6 +10,7 @@ // run-pass // aux-build:edition-lint-paths.rs +// compile-flags:--extern edition_lint_paths // run-rustfix // The "normal case". Ideally we would remove the `extern crate` here, diff --git a/src/test/ui/rust-2018/issue-54006.rs b/src/test/ui/rust-2018/issue-54006.rs new file mode 100644 index 00000000000..ee58d240fcb --- /dev/null +++ b/src/test/ui/rust-2018/issue-54006.rs @@ -0,0 +1,23 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// edition:2018 + +#![no_std] +#![crate_type = "lib"] + +use alloc::vec; +//~^ ERROR unresolved import `alloc` + +pub fn foo() { + let mut xs = vec![]; + //~^ ERROR cannot determine resolution for the macro `vec` + xs.push(0); +} diff --git a/src/test/ui/rust-2018/issue-54006.stderr b/src/test/ui/rust-2018/issue-54006.stderr new file mode 100644 index 00000000000..1183dc9794a --- /dev/null +++ b/src/test/ui/rust-2018/issue-54006.stderr @@ -0,0 +1,17 @@ +error[E0432]: unresolved import `alloc` + --> $DIR/issue-54006.rs:16:5 + | +LL | use alloc::vec; + | ^^^^^ Could not find `alloc` in `{{root}}` + +error: cannot determine resolution for the macro `vec` + --> $DIR/issue-54006.rs:20:18 + | +LL | let mut xs = vec![]; + | ^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/rust-2018/remove-extern-crate.fixed b/src/test/ui/rust-2018/remove-extern-crate.fixed index 995be4290b8..895da74afd7 100644 --- a/src/test/ui/rust-2018/remove-extern-crate.fixed +++ b/src/test/ui/rust-2018/remove-extern-crate.fixed @@ -12,6 +12,7 @@ // edition:2018 // compile-pass // aux-build:remove-extern-crate.rs +// compile-flags:--extern remove_extern_crate --extern core #![warn(rust_2018_idioms)] diff --git a/src/test/ui/rust-2018/remove-extern-crate.rs b/src/test/ui/rust-2018/remove-extern-crate.rs index 3ab97a74287..c03431a6b88 100644 --- a/src/test/ui/rust-2018/remove-extern-crate.rs +++ b/src/test/ui/rust-2018/remove-extern-crate.rs @@ -12,6 +12,7 @@ // edition:2018 // compile-pass // aux-build:remove-extern-crate.rs +// compile-flags:--extern remove_extern_crate --extern core #![warn(rust_2018_idioms)] diff --git a/src/test/ui/rust-2018/remove-extern-crate.stderr b/src/test/ui/rust-2018/remove-extern-crate.stderr index 752a7b180de..064a853625f 100644 --- a/src/test/ui/rust-2018/remove-extern-crate.stderr +++ b/src/test/ui/rust-2018/remove-extern-crate.stderr @@ -1,24 +1,24 @@ warning: unused extern crate - --> $DIR/remove-extern-crate.rs:18:1 + --> $DIR/remove-extern-crate.rs:19:1 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here - --> $DIR/remove-extern-crate.rs:16:9 + --> $DIR/remove-extern-crate.rs:17:9 | LL | #![warn(rust_2018_idioms)] | ^^^^^^^^^^^^^^^^ = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)] warning: `extern crate` is not idiomatic in the new edition - --> $DIR/remove-extern-crate.rs:19:1 + --> $DIR/remove-extern-crate.rs:20:1 | LL | extern crate core as another_name; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` warning: `extern crate` is not idiomatic in the new edition - --> $DIR/remove-extern-crate.rs:32:5 + --> $DIR/remove-extern-crate.rs:33:5 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ help: convert it to a `use` -- 2.44.0