diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 6dae116e4284a..3473144c4f0be 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1391,19 +1391,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { crate_path.push(ast::PathSegment::path_root(rustc_span::DUMMY_SP)); } crate_path.push(ast::PathSegment::from_ident(ident)); - let suggest_imports = self.lookup_import_candidates_from_module( + + suggestions.extend(self.lookup_import_candidates_from_module( lookup_ident, namespace, parent_scope, crate_root, crate_path, &filter_fn, - ); - for item in suggest_imports { - if suggestions.iter().all(|sugg| sugg.did != item.did) { - suggestions.push(item); - } - } + )); } } } diff --git a/tests/run-make/extern-alias/Makefile b/tests/run-make/extern-alias/Makefile deleted file mode 100644 index 89733acad134c..0000000000000 --- a/tests/run-make/extern-alias/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) --crate-type=rlib unwieldy_crate_name.rs -o $(TMPDIR)/libunwieldy_crate_name.rlib - $(RUSTC) --crate-type rlib main.rs --extern unwieldy_crate_name=$(TMPDIR)/libunwieldy_crate_name.rlib \ - 2>&1 | $(CGREP) "use nice_crate_name::Foo;" - - $(RUSTC) --crate-type=rlib --edition=2021 unwieldy_crate_name.rs -o $(TMPDIR)/libunwieldy_crate_name.rlib - $(RUSTC) --crate-type rlib main.rs --edition=2021 --extern unwieldy_crate_name=$(TMPDIR)/libunwieldy_crate_name.rlib \ - 2>&1 | $(CGREP) "use crate::nice_crate_name::Foo;" diff --git a/tests/run-make/extern-alias/main.rs b/tests/run-make/extern-alias/main.rs deleted file mode 100644 index 215dc76eb8180..0000000000000 --- a/tests/run-make/extern-alias/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -extern crate unwieldy_crate_name as nice_crate_name; - -fn use_foo_from_another_crate_without_importing_it_first() { - //use nice_crate_name::Foo; - let _: Foo = todo!(); -} diff --git a/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr b/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr index ffe4f800c7390..78e6376bca2e8 100644 --- a/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr +++ b/tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr @@ -24,8 +24,9 @@ LL | fn f() { my_core::mem::drop(0); } LL | a!(); | ---- in this macro invocation | - = help: consider importing this module: + = help: consider importing one of these items: core::mem + std::mem = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0433]: failed to resolve: use of undeclared crate or module `my_core` @@ -34,10 +35,12 @@ error[E0433]: failed to resolve: use of undeclared crate or module `my_core` LL | fn f() { my_core::mem::drop(0); } | ^^^^^^^ use of undeclared crate or module `my_core` | -help: consider importing this module +help: consider importing one of these items | LL + use core::mem; | +LL + use std::mem; + | help: if you import `mem`, refer to it directly | LL - fn f() { my_core::mem::drop(0); } diff --git a/tests/run-make/extern-alias/unwieldy_crate_name.rs b/tests/ui/imports/auxiliary/issue-121168-extern.rs similarity index 100% rename from tests/run-make/extern-alias/unwieldy_crate_name.rs rename to tests/ui/imports/auxiliary/issue-121168-extern.rs diff --git a/tests/ui/imports/issue-121168-2.rs b/tests/ui/imports/issue-121168-2.rs new file mode 100644 index 0000000000000..8b79b64ef2ebd --- /dev/null +++ b/tests/ui/imports/issue-121168-2.rs @@ -0,0 +1,12 @@ +//@ edition: 2018 +//@ compile-flags: --extern issue_121168_extern +//@ aux-build: issue-121168-extern.rs + +extern crate issue_121168_extern as nice_crate_name; + +fn use_foo_from_another_crate_without_importing_it_first() { + //use nice_crate_name::Foo; + let _: Foo = todo!(); //~ ERROR cannot find type `Foo` in this scope +} + +fn main() {} diff --git a/tests/ui/imports/issue-121168-2.stderr b/tests/ui/imports/issue-121168-2.stderr new file mode 100644 index 0000000000000..c53f9f45de1d2 --- /dev/null +++ b/tests/ui/imports/issue-121168-2.stderr @@ -0,0 +1,16 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/issue-121168-2.rs:9:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing one of these items + | +LL + use crate::nice_crate_name::Foo; + | +LL + use issue_121168_extern::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/issue-121168-3.rs b/tests/ui/imports/issue-121168-3.rs new file mode 100644 index 0000000000000..0ee461034b6ab --- /dev/null +++ b/tests/ui/imports/issue-121168-3.rs @@ -0,0 +1,12 @@ +//@ edition: 2015 +//@ compile-flags: --extern issue_121168_extern +//@ aux-build: issue-121168-extern.rs + +extern crate issue_121168_extern as nice_crate_name; + +fn use_foo_from_another_crate_without_importing_it_first() { + //use nice_crate_name::Foo; + let _: Foo = todo!(); //~ ERROR cannot find type `Foo` in this scope +} + +fn main() {} diff --git a/tests/ui/imports/issue-121168-3.stderr b/tests/ui/imports/issue-121168-3.stderr new file mode 100644 index 0000000000000..a8454a034782d --- /dev/null +++ b/tests/ui/imports/issue-121168-3.stderr @@ -0,0 +1,14 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/issue-121168-3.rs:9:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing this struct + | +LL + use nice_crate_name::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/issue-121168.rs b/tests/ui/imports/issue-121168.rs new file mode 100644 index 0000000000000..6c7c730d77239 --- /dev/null +++ b/tests/ui/imports/issue-121168.rs @@ -0,0 +1,12 @@ +//@ edition: 2021 +//@ compile-flags: --extern issue_121168_extern +//@ aux-build: issue-121168-extern.rs + +extern crate issue_121168_extern as nice_crate_name; + +fn use_foo_from_another_crate_without_importing_it_first() { + //use nice_crate_name::Foo; + let _: Foo = todo!(); //~ ERROR cannot find type `Foo` in this scope +} + +fn main() {} diff --git a/tests/ui/imports/issue-121168.stderr b/tests/ui/imports/issue-121168.stderr new file mode 100644 index 0000000000000..d628b02f411fe --- /dev/null +++ b/tests/ui/imports/issue-121168.stderr @@ -0,0 +1,16 @@ +error[E0412]: cannot find type `Foo` in this scope + --> $DIR/issue-121168.rs:9:12 + | +LL | let _: Foo = todo!(); + | ^^^ not found in this scope + | +help: consider importing one of these items + | +LL + use crate::nice_crate_name::Foo; + | +LL + use issue_121168_extern::Foo; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/imports/issue-56125.stderr b/tests/ui/imports/issue-56125.stderr index 27bbce1526f58..d2a0f436c42d0 100644 --- a/tests/ui/imports/issue-56125.stderr +++ b/tests/ui/imports/issue-56125.stderr @@ -8,10 +8,13 @@ help: consider importing one of these items instead | LL | use ::issue_56125::issue_56125; | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | use ::issue_56125::last_segment::issue_56125; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | use ::issue_56125::non_last_segment::non_last_segment::issue_56125; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LL | use crate::m3::last_segment::issue_56125; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -LL | use crate::m3::non_last_segment::non_last_segment::issue_56125; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + and 1 other candidate error[E0659]: `issue_56125` is ambiguous --> $DIR/issue-56125.rs:6:9 diff --git a/tests/ui/mir/issue-106062.stderr b/tests/ui/mir/issue-106062.stderr index f366c88a2b7cc..30635148dae64 100644 --- a/tests/ui/mir/issue-106062.stderr +++ b/tests/ui/mir/issue-106062.stderr @@ -2,10 +2,14 @@ error[E0573]: expected type, found variant `Ok` --> $DIR/issue-106062.rs:15:64 | LL | async fn connection_handler(handler: impl Sized) -> Result { - | ^^ - | | - | not a type - | help: try using the variant's enum: `core::result::Result` + | ^^ not a type + | +help: try using the variant's enum + | +LL | async fn connection_handler(handler: impl Sized) -> Result { + | ~~~~~~~~~~~~~~~~~~~~ +LL | async fn connection_handler(handler: impl Sized) -> Result { + | ~~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.rs b/tests/ui/suggestions/core-std-import-order-issue-83564.rs index 039227f767480..2cf1983858a65 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.rs +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.rs @@ -4,7 +4,7 @@ // For some reason, Rust 2018 or higher is required to reproduce the bug. fn main() { - //~^ HELP consider importing this type alias + //~^ HELP consider importing one of these items let _x = NonZeroU32::new(5).unwrap(); //~^ ERROR failed to resolve: use of undeclared type `NonZeroU32` } diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr index 437af83923951..c2634e3070ea9 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.stderr +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.stderr @@ -4,10 +4,12 @@ error[E0433]: failed to resolve: use of undeclared type `NonZeroU32` LL | let _x = NonZeroU32::new(5).unwrap(); | ^^^^^^^^^^ use of undeclared type `NonZeroU32` | -help: consider importing this type alias +help: consider importing one of these items | LL + use core::num::NonZeroU32; | +LL + use std::num::NonZeroU32; + | error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/crate-or-module-typo.stderr b/tests/ui/suggestions/crate-or-module-typo.stderr index dfd03e4aaea05..457d779064682 100644 --- a/tests/ui/suggestions/crate-or-module-typo.stderr +++ b/tests/ui/suggestions/crate-or-module-typo.stderr @@ -30,10 +30,12 @@ help: there is a crate or module with a similar name | LL | bar: std::cell::Cell | ~~~ -help: consider importing this module +help: consider importing one of these items | LL + use core::cell; | +LL + use std::cell; + | help: if you import `cell`, refer to it directly | LL - bar: st::cell::Cell diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.rs b/tests/ui/suggestions/suggest-tryinto-edition-change.rs index 51ca53390bb50..c4a24ffee93cd 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.rs +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.rs @@ -11,16 +11,19 @@ fn test() { let _i: i16 = TryFrom::try_from(0_i32).unwrap(); //~^ ERROR failed to resolve: use of undeclared type //~| NOTE use of undeclared type + //~| NOTE 'std::convert::TryFrom' is included in the prelude starting in Edition 2021 //~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021 let _i: i16 = TryInto::try_into(0_i32).unwrap(); //~^ ERROR failed to resolve: use of undeclared type //~| NOTE use of undeclared type + //~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021 //~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021 let _v: Vec<_> = FromIterator::from_iter(&[1]); //~^ ERROR failed to resolve: use of undeclared type //~| NOTE use of undeclared type + //~| NOTE 'std::iter::FromIterator' is included in the prelude starting in Edition 2021 //~| NOTE 'core::iter::FromIterator' is included in the prelude starting in Edition 2021 } diff --git a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr index 3fc6c3ae7393c..057e37dbe109f 100644 --- a/tests/ui/suggestions/suggest-tryinto-edition-change.stderr +++ b/tests/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -5,38 +5,47 @@ LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap(); | ^^^^^^^ use of undeclared type `TryFrom` | = note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021 -help: consider importing this trait + = note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021 +help: consider importing one of these items | LL + use core::convert::TryFrom; | +LL + use std::convert::TryFrom; + | error[E0433]: failed to resolve: use of undeclared type `TryInto` - --> $DIR/suggest-tryinto-edition-change.rs:16:19 + --> $DIR/suggest-tryinto-edition-change.rs:17:19 | LL | let _i: i16 = TryInto::try_into(0_i32).unwrap(); | ^^^^^^^ use of undeclared type `TryInto` | = note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021 -help: consider importing this trait + = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 +help: consider importing one of these items | LL + use core::convert::TryInto; | +LL + use std::convert::TryInto; + | error[E0433]: failed to resolve: use of undeclared type `FromIterator` - --> $DIR/suggest-tryinto-edition-change.rs:21:22 + --> $DIR/suggest-tryinto-edition-change.rs:23:22 | LL | let _v: Vec<_> = FromIterator::from_iter(&[1]); | ^^^^^^^^^^^^ use of undeclared type `FromIterator` | = note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021 + = note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021 help: a trait with a similar name exists | LL | let _v: Vec<_> = IntoIterator::from_iter(&[1]); | ~~~~~~~~~~~~ -help: consider importing this trait +help: consider importing one of these items | LL + use core::iter::FromIterator; | +LL + use std::iter::FromIterator; + | error[E0599]: no method named `try_into` found for type `i32` in the current scope --> $DIR/suggest-tryinto-edition-change.rs:6:25