Skip to content

Commit

Permalink
Fix issues in suggesting importing extern crate paths
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 25, 2024
1 parent 43d3470 commit 5f41994
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
12 changes: 11 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,10 +1290,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let mut path_segments = path_segments.clone();
path_segments.push(ast::PathSegment::from_ident(ident));

let alias_import = if let NameBindingKind::Import { import, .. } =
name_binding.kind
&& let ImportKind::ExternCrate { source: Some(_), .. } = import.kind
&& import.parent_scope.expansion == parent_scope.expansion
{
true
} else {
false
};

let is_extern_crate_that_also_appears_in_prelude =
name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();

if !is_extern_crate_that_also_appears_in_prelude {
if !is_extern_crate_that_also_appears_in_prelude || alias_import {
// add the module to the lookup
if seen_modules.insert(module.def_id()) {
if via_import { &mut worklist_via_import } else { &mut worklist }
Expand Down
2 changes: 1 addition & 1 deletion library/stdarch
Submodule stdarch updated 33 files
+23 −6 .github/workflows/main.yml
+0 −51 crates/core_arch/src/aarch64/crc.rs
+0 −4 crates/core_arch/src/aarch64/mod.rs
+224 −224 crates/core_arch/src/aarch64/neon/generated.rs
+13 −13 crates/core_arch/src/aarch64/neon/mod.rs
+74 −0 crates/core_arch/src/arm_shared/crc.rs
+54 −54 crates/core_arch/src/arm_shared/neon/generated.rs
+52 −52 crates/core_arch/src/arm_shared/neon/mod.rs
+18 −8 crates/core_arch/src/macros.rs
+1,076 −13 crates/core_arch/src/powerpc/altivec.rs
+97 −524 crates/core_arch/src/simd.rs
+5 −64 crates/core_arch/src/simd_llvm.rs
+34 −28 crates/core_arch/src/wasm32/simd128.rs
+4 −4 crates/core_arch/src/x86/avx.rs
+5 −5 crates/core_arch/src/x86/avx2.rs
+322 −322 crates/core_arch/src/x86/avx512f.rs
+3 −3 crates/core_arch/src/x86/sse.rs
+20 −20 crates/core_arch/src/x86/sse2.rs
+5 −5 crates/core_arch/src/x86/sse41.rs
+1 −1 crates/core_arch/src/x86_64/avx.rs
+1 −1 crates/core_arch/src/x86_64/avx2.rs
+4 −4 crates/core_arch/src/x86_64/avx512f.rs
+2 −2 crates/core_arch/src/x86_64/sse2.rs
+2 −2 crates/core_arch/src/x86_64/sse41.rs
+0 −2 crates/intrinsic-test/missing_arm.txt
+8 −7 crates/std_detect/src/detect/arch/aarch64.rs
+3 −0 crates/std_detect/src/detect/mod.rs
+1 −1 crates/std_detect/src/detect/os/aarch64.rs
+2 −1 crates/std_detect/src/detect/os/linux/aarch64.rs
+98 −0 crates/std_detect/src/detect/os/macos/aarch64.rs
+1 −8 crates/std_detect/src/lib.rs
+32 −0 crates/std_detect/tests/cpu-detection.rs
+84 −91 crates/stdarch-gen/neon.spec
1 change: 1 addition & 0 deletions tests/ui/imports/auxiliary/issue-121168-extern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Foo<T>(pub core::ptr::NonNull<T>);
14 changes: 14 additions & 0 deletions tests/ui/imports/issue-121168.edition2015.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168.rs:11:12
|
LL | let _: Foo<i32> = 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`.
16 changes: 16 additions & 0 deletions tests/ui/imports/issue-121168.edition2018.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168.rs:11:12
|
LL | let _: Foo<i32> = 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`.
16 changes: 16 additions & 0 deletions tests/ui/imports/issue-121168.edition2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/issue-121168.rs:11:12
|
LL | let _: Foo<i32> = 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`.
14 changes: 14 additions & 0 deletions tests/ui/imports/issue-121168.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ revisions: edition2015 edition2018 edition2021
//@ [edition2015] edition:2015
//@ [edition2018] edition:2018
//@ [edition2021] 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() {
let _: Foo<i32> = todo!(); //~ ERROR cannot find type `Foo` in this scope
}

fn main() {}

0 comments on commit 5f41994

Please sign in to comment.