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

ICE: inconsistent resolution for an import #128813

Closed
Naserume opened this issue Aug 8, 2024 · 0 comments · Fixed by #128932
Closed

ICE: inconsistent resolution for an import #128813

Naserume opened this issue Aug 8, 2024 · 0 comments · Fixed by #128932
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Naserume
Copy link

Naserume commented Aug 8, 2024

Code

extern crate core;

fn useful_syntax() {
    use ::{{core}, {std}};
}

macro_rules! define_other_core {
    () => {
        extern crate std as core;
    };
}

define_other_core!();

fn main() {}

command: rustc ./file.rs --edition=2021

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (60d146580 2024-08-06)
binary: rustc
commit-hash: 60d146580c10036ce89e019422c6bc2fd9729b65
commit-date: 2024-08-06
host: x86_64-apple-darwin
release: 1.82.0-nightly
LLVM version: 19.1.0

Error output

error[E0259]: the name `core` is defined multiple times
  --> ./12995.rs:9:9
   |
1  | extern crate core;
   | ------------------ previous import of the extern crate `core` here
...
9  |         extern crate std as core;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ `core` reimported here
...
13 | define_other_core!();
   | -------------------- in this macro invocation
   |
   = note: `core` must be defined only once in the type namespace of this module
   = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can use `as` to change the binding name of the import
   |
9  |         extern crate std as other_core;
   |

Backtrace

error: internal compiler error: compiler/rustc_resolve/src/imports.rs:1095:33: inconsistent resolution for an import
 --> ./12995.rs:4:13
  |
4 |     use ::{{core}, {std}};
  |             ^^^^

thread 'rustc' panicked at compiler/rustc_resolve/src/imports.rs:1095:33:
Box<dyn Any>
stack backtrace:
   0:        0x102a0a7f9 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hde541634c76c8424
   1:        0x102a5658b - core::fmt::write::h0a6995bfd5310686
   2:        0x1029ffa32 - std::io::Write::write_fmt::ha44463c63b65871a
   3:        0x102a0d0a8 - std::panicking::default_hook::{{closure}}::h8629ee341b692758
   4:        0x102a0ccee - std::panicking::default_hook::h8703f8d1cc197d13
   5:        0x10c06f0fd - std[513de39480af1bab]::panicking::update_hook::<alloc[88fbee91b568d05e]::boxed::Box<rustc_driver_impl[1a7a7dac5035a0ee]::install_ice_hook::{closure#0}>>::{closure#0}
   6:        0x102a0ded0 - std::panicking::rust_panic_with_hook::h68d7251319b974a6
   7:        0x10c0e28f7 - std[513de39480af1bab]::panicking::begin_panic::<rustc_errors[77d550dff4600411]::ExplicitBug>::{closure#0}
   8:        0x10c0ce7f9 - std[513de39480af1bab]::sys::backtrace::__rust_end_short_backtrace::<std[513de39480af1bab]::panicking::begin_panic<rustc_errors[77d550dff4600411]::ExplicitBug>::{closure#0}, !>
   9:        0x110ca0589 - std[513de39480af1bab]::panicking::begin_panic::<rustc_errors[77d550dff4600411]::ExplicitBug>
  10:        0x10c0f5466 - <rustc_errors[77d550dff4600411]::diagnostic::BugAbort as rustc_errors[77d550dff4600411]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:        0x10d7ced41 - <rustc_errors[77d550dff4600411]::DiagCtxtHandle>::span_bug::<rustc_span[af5dc13a57d4458]::span_encoding::Span, alloc[88fbee91b568d05e]::string::String>
  12:        0x10d823f78 - rustc_middle[ef4ebef1f35b9a45]::util::bug::opt_span_bug_fmt::<rustc_span[af5dc13a57d4458]::span_encoding::Span>::{closure#0}
  13:        0x10d823fb7 - rustc_middle[ef4ebef1f35b9a45]::ty::context::tls::with_opt::<rustc_middle[ef4ebef1f35b9a45]::util::bug::opt_span_bug_fmt<rustc_span[af5dc13a57d4458]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:        0x10d806895 - rustc_middle[ef4ebef1f35b9a45]::ty::context::tls::with_context_opt::<rustc_middle[ef4ebef1f35b9a45]::ty::context::tls::with_opt<rustc_middle[ef4ebef1f35b9a45]::util::bug::opt_span_bug_fmt<rustc_span[af5dc13a57d4458]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:        0x110e2de12 - rustc_middle[ef4ebef1f35b9a45]::util::bug::span_bug_fmt::<rustc_span[af5dc13a57d4458]::span_encoding::Span>
  16:        0x10d8912a5 - <rustc_resolve[45692f5fb0b81a0]::Resolver>::finalize_import::{closure#2}
  17:        0x10d88c7e2 - <rustc_resolve[45692f5fb0b81a0]::Resolver>::finalize_import
  18:        0x10d90b9bd - <rustc_resolve[45692f5fb0b81a0]::Resolver>::resolve_crate::{closure#0}
  19:        0x10d90a9de - <rustc_resolve[45692f5fb0b81a0]::Resolver>::resolve_crate
  20:        0x10c9a9e24 - rustc_interface[55f0bb586236ba3f]::passes::resolver_for_lowering_raw
  21:        0x10d718c66 - rustc_query_impl[db7d5818ebb544c0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db7d5818ebb544c0]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 16usize]>>
  22:        0x10d6dbb3e - <rustc_query_impl[db7d5818ebb544c0]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[31c80208252ed77d]::ops::function::FnOnce<(rustc_middle[ef4ebef1f35b9a45]::ty::context::TyCtxt, ())>>::call_once
  23:        0x10d4f4ae8 - rustc_query_system[9c8bd583e072577f]::query::plumbing::try_execute_query::<rustc_query_impl[db7d5818ebb544c0]::DynamicConfig<rustc_query_system[9c8bd583e072577f]::query::caches::SingleCache<rustc_middle[ef4ebef1f35b9a45]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[db7d5818ebb544c0]::plumbing::QueryCtxt, false>
  24:        0x10d7207bc - rustc_query_impl[db7d5818ebb544c0]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  25:        0x10c019ebe - <rustc_interface[55f0bb586236ba3f]::queries::QueryResult<&rustc_middle[ef4ebef1f35b9a45]::ty::context::GlobalCtxt>>::enter::<&rustc_data_structures[1d7d5eef2915edc]::steal::Steal<(rustc_middle[ef4ebef1f35b9a45]::ty::ResolverAstLowering, alloc[88fbee91b568d05e]::sync::Arc<rustc_ast[6e61105b9f75d832]::ast::Crate>)>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  26:        0x10c07559d - rustc_interface[55f0bb586236ba3f]::interface::run_compiler::<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}
  27:        0x10c0619c1 - std[513de39480af1bab]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_with_globals<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_pool_with_globals<rustc_interface[55f0bb586236ba3f]::interface::run_compiler<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>
  28:        0x10c078a06 - <<std[513de39480af1bab]::thread::Builder>::spawn_unchecked_<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_with_globals<rustc_interface[55f0bb586236ba3f]::util::run_in_thread_pool_with_globals<rustc_interface[55f0bb586236ba3f]::interface::run_compiler<core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>, rustc_driver_impl[1a7a7dac5035a0ee]::run_compiler::{closure#0}>::{closure#1}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c80208252ed77d]::result::Result<(), rustc_span[af5dc13a57d4458]::ErrorGuaranteed>>::{closure#1} as core[31c80208252ed77d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:        0x102a16afb - std::sys::pal::unix::thread::Thread::new::thread_start::h38612934f7248e43
  30:     0x7ff801f5318b - __pthread_start

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/rustc-ice-2024-08-08T08_02_16-90700.txt` to your bug report

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0259`.

Note

ICE location:

let res = binding.res();
let has_ambiguity_error =
this.ambiguity_errors.iter().any(|error| !error.warning);
if res == Res::Err || has_ambiguity_error {
this.dcx()
.span_delayed_bug(import.span, "some error happened for an import");
return;
}
if let Ok(initial_res) = initial_res {
if res != initial_res {
span_bug!(import.span, "inconsistent resolution for an import");
}
} else if this.privacy_errors.is_empty() {
this.dcx()
.create_err(CannotDetermineImportResolution { span: import.span })
.emit();
}

@Naserume Naserume added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 8, 2024
@jieyouxu jieyouxu added the A-resolve Area: Name resolution label Aug 8, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 13, 2024
@bors bors closed this as completed in 2e58d62 Aug 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 21, 2024
Rollup merge of rust-lang#128932 - bvanjoi:issue-128813, r=petrochenkov

skip updating when external binding is existed

Fixes rust-lang#128813

For following code:

```rs
extern crate core;

fn f() {
    use ::core;
}

macro_rules! m {
    () => {
        extern crate std as core;
    };
}

m!();

fn main() {}
```

- In the first loop, we define `extern crate core` and `use ::core` will be referred to `core` (yes, it does not consider if there are some macros that are not expanded. Ideally, this should be delayed if there are some unexpanded macros in the root, but I didn't change it like that because it seems like a huge change).
- Then `m` is expanded, which makes `extern_prelude('core')` return `std` rather than `core`, causing the inconsistency.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants