Skip to content

ICE: Failed to normalize Alias(Projection #137468

New issue

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

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

Already on GitHub? # to your account

Open
matthiaskrgr opened this issue Feb 23, 2025 · 2 comments
Open

ICE: Failed to normalize Alias(Projection #137468

matthiaskrgr opened this issue Feb 23, 2025 · 2 comments
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

//@compile-flags: -Zmir-opt-level=5 -Zvalidate-mir
trait Supertrait<T> {}

trait Identity {
    type Selff;
}

trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}

impl<P> Trait<P> for () {}

fn main() {
    let x: &dyn Trait<()> = &();
    let x: &dyn Supertrait<()> = x;
}

original:

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ check-pass

// Ensure we don't have ambiguity when upcasting to two supertraits
// that are identical modulo normalization.

trait Supertrait<T> {
    fn method(&self) {}
}
impl<T> Supertrait<T> for () {}

trait Identity {
    type Selff;
}
impl<Send> Identity for Selff {
    type Selff = Selff;
}
trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}

impl<P> Trait<P> for () {}

fn main() {
    let x: &dyn Trait<()> = &();
    let x: &dyn Supertrait<()> = x;
}

Version information

rustc 1.87.0-nightly (8dac72bb1 2025-02-22)
binary: rustc
commit-hash: 8dac72bb1d12b2649acd0c190e41524f83da5683
commit-date: 2025-02-22
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

fn normalize_generic_arg_after_erasing_regions(
&self,
arg: ty::GenericArg<'tcx>,
) -> ty::GenericArg<'tcx> {
let arg = self.typing_env.as_query_input(arg);
self.tcx.try_normalize_generic_arg_after_erasing_regions(arg).unwrap_or_else(|_| {
bug!(
"Failed to normalize {:?} in typing_env={:?}, \
maybe try to call `try_normalize_erasing_regions` instead",
arg.value,
self.typing_env,
)
})

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir

Program output

error[E0277]: the trait bound `P: Identity` is not satisfied
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:7:1
  |
7 | trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Identity` is not implemented for `P`
  |
help: consider restricting type parameter `P` with trait `Identity`
  |
7 | trait Trait<P: Identity>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
  |              ++++++++++

error[E0277]: the trait bound `P: Identity` is not satisfied
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:7:1
  |
7 | trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Identity` is not implemented for `P`
  |
help: consider restricting type parameter `P` with trait `Identity`
  |
7 | trait Trait<P: Identity>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
  |              ++++++++++

error[E0277]: the trait bound `P: Identity` is not satisfied
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:9:9
  |
9 | impl<P> Trait<P> for () {}
  |         ^^^^^^^^ the trait `Identity` is not implemented for `P`
  |
help: consider restricting type parameter `P` with trait `Identity`
  |
9 | impl<P: Identity> Trait<P> for () {}
  |       ++++++++++

error[E0277]: the trait bound `(): Supertrait<_>` is not satisfied
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:9:22
  |
9 | impl<P> Trait<P> for () {}
  |                      ^^ the trait `Supertrait<_>` is not implemented for `()`
  |
help: this trait has no implementations, consider adding one
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:1:1
  |
1 | trait Supertrait<T> {}
  | ^^^^^^^^^^^^^^^^^^^
note: required by a bound in `Trait`
 --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:7:34
  |
7 | trait Trait<P>: Supertrait<()> + Supertrait<<P as Identity>::Selff> {}
  |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait`

warning: unused variable: `x`
  --> /tmp/icemaker_global_tempdir.NCcR1kXSOfbE/rustc_testrunner_tmpdir_reporting.z1VbsmiiUhVM/mvce.rs:13:9
   |
13 |     let x: &dyn Supertrait<()> = x;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:13: Failed to normalize Alias(Projection, AliasTy { args: [()], def_id: DefId(0:6 ~ mvce[6a89]::Identity::Selff), .. }) in typing_env=TypingEnv { typing_mode: PostAnalysis, param_env: ParamEnv { caller_bounds: [] } }, maybe try to call `try_normalize_erasing_regions` instead


thread 'rustc' panicked at compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:169:13:
Box<dyn Any>
stack backtrace:
   0:     0x72981eb8b604 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h38ba1fb232694db8
   1:     0x72981f21602c - core::fmt::write::hd9fa0bf1d3d8f7ee
   2:     0x7298205f2951 - std::io::Write::write_fmt::h494b4f6e85366c52
   3:     0x72981eb8b462 - std::sys::backtrace::BacktraceLock::print::hef8b76e17140041f
   4:     0x72981eb8dc6e - std::panicking::default_hook::{{closure}}::h77663862c6fb4f85
   5:     0x72981eb8d844 - std::panicking::default_hook::h1663f8412d2a703d
   6:     0x72981dce7d07 - std[7deecfbd79e4275a]::panicking::update_hook::<alloc[23b4fbae564311fb]::boxed::Box<rustc_driver_impl[cf432ae27b341183]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x72981eb8e4e3 - std::panicking::rust_panic_with_hook::h4cb73b1bd858bb29
   8:     0x72981dd23e01 - std[7deecfbd79e4275a]::panicking::begin_panic::<rustc_errors[700fece676fda129]::ExplicitBug>::{closure#0}
   9:     0x72981dd18216 - std[7deecfbd79e4275a]::sys::backtrace::__rust_end_short_backtrace::<std[7deecfbd79e4275a]::panicking::begin_panic<rustc_errors[700fece676fda129]::ExplicitBug>::{closure#0}, !>
  10:     0x72981dd18203 - std[7deecfbd79e4275a]::panicking::begin_panic::<rustc_errors[700fece676fda129]::ExplicitBug>
  11:     0x72981dd2d801 - <rustc_errors[700fece676fda129]::diagnostic::BugAbort as rustc_errors[700fece676fda129]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x72981e2ff276 - rustc_middle[e1b2a093fd8c5f9e]::util::bug::opt_span_bug_fmt::<rustc_span[f957837e5cbe62b2]::span_encoding::Span>::{closure#0}
  13:     0x72981e2e874a - rustc_middle[e1b2a093fd8c5f9e]::ty::context::tls::with_opt::<rustc_middle[e1b2a093fd8c5f9e]::util::bug::opt_span_bug_fmt<rustc_span[f957837e5cbe62b2]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x72981e2e85db - rustc_middle[e1b2a093fd8c5f9e]::ty::context::tls::with_context_opt::<rustc_middle[e1b2a093fd8c5f9e]::ty::context::tls::with_opt<rustc_middle[e1b2a093fd8c5f9e]::util::bug::opt_span_bug_fmt<rustc_span[f957837e5cbe62b2]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x72981c77d6e0 - rustc_middle[e1b2a093fd8c5f9e]::util::bug::bug_fmt
  16:     0x72981f6a041e - <rustc_middle[e1b2a093fd8c5f9e]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_type_ir[7337433cf2c61bcb]::fold::TypeFolder<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>>::fold_ty
  17:     0x72981e927312 - <&rustc_middle[e1b2a093fd8c5f9e]::ty::list::RawList<(), rustc_middle[e1b2a093fd8c5f9e]::ty::generic_args::GenericArg> as rustc_type_ir[7337433cf2c61bcb]::fold::TypeFoldable<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>>::try_fold_with::<rustc_middle[e1b2a093fd8c5f9e]::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder>
  18:     0x729820db6744 - <rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>::normalize_erasing_late_bound_regions::<rustc_type_ir[7337433cf2c61bcb]::predicate::TraitPredicate<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>>.cold
  19:     0x72982016a911 - <core[585ec36c4bc8fc42]::iter::adapters::flatten::FlattenCompat<_, _> as core[585ec36c4bc8fc42]::iter::traits::iterator::Iterator>::try_fold::flatten::<core[585ec36c4bc8fc42]::iter::adapters::map::Map<core[585ec36c4bc8fc42]::iter::adapters::filter_map::FilterMap<rustc_type_ir[7337433cf2c61bcb]::binder::IterIdentityCopied<&[(rustc_middle[e1b2a093fd8c5f9e]::ty::predicate::Clause, rustc_span[f957837e5cbe62b2]::span_encoding::Span)]>, rustc_trait_selection[b9356aeac392e085]::traits::vtable::prepare_vtable_segments_inner<(), rustc_trait_selection[b9356aeac392e085]::traits::vtable::vtable_entries::{closure#0}>::{closure#0}>, rustc_trait_selection[b9356aeac392e085]::traits::vtable::prepare_vtable_segments_inner<(), rustc_trait_selection[b9356aeac392e085]::traits::vtable::vtable_entries::{closure#0}>::{closure#1}>, (), core[585ec36c4bc8fc42]::ops::control_flow::ControlFlow<rustc_type_ir[7337433cf2c61bcb]::predicate::TraitRef<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>>, core[585ec36c4bc8fc42]::iter::traits::iterator::Iterator::find::check<rustc_type_ir[7337433cf2c61bcb]::predicate::TraitRef<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>, rustc_trait_selection[b9356aeac392e085]::traits::vtable::prepare_vtable_segments_inner<(), rustc_trait_selection[b9356aeac392e085]::traits::vtable::vtable_entries::{closure#0}>::{closure#3}>::{closure#0}>::{closure#0}
  20:     0x729820169f9d - rustc_trait_selection[b9356aeac392e085]::traits::vtable::vtable_entries
  21:     0x729820169a60 - rustc_query_impl[e1b1efbe27e837e4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e1b1efbe27e837e4]::query_impl::vtable_entries::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 16usize]>>
  22:     0x729820169a21 - <rustc_query_impl[e1b1efbe27e837e4]::query_impl::vtable_entries::dynamic_query::{closure#2} as core[585ec36c4bc8fc42]::ops::function::FnOnce<(rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt, rustc_type_ir[7337433cf2c61bcb]::predicate::TraitRef<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>)>>::call_once
  23:     0x729820164fab - rustc_query_system[df8f3c09d69e93fa]::query::plumbing::try_execute_query::<rustc_query_impl[e1b1efbe27e837e4]::DynamicConfig<rustc_query_system[df8f3c09d69e93fa]::query::caches::DefaultCache<rustc_type_ir[7337433cf2c61bcb]::predicate::TraitRef<rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>, rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[e1b1efbe27e837e4]::plumbing::QueryCtxt, false>
  24:     0x729820164cae - rustc_query_impl[e1b1efbe27e837e4]::query_impl::vtable_entries::get_query_non_incr::__rust_end_short_backtrace
  25:     0x72981e426d0e - <rustc_const_eval[16fbdf47858b3855]::interpret::eval_context::InterpCx<rustc_const_eval[16fbdf47858b3855]::const_eval::dummy_machine::DummyMachine>>::vtable_entries
  26:     0x729820c95916 - <rustc_const_eval[16fbdf47858b3855]::interpret::eval_context::InterpCx<rustc_const_eval[16fbdf47858b3855]::const_eval::dummy_machine::DummyMachine>>::unsize_into_ptr.cold
  27:     0x72981fdfa1df - <rustc_mir_transform[18da0cf66f51b93]::gvn::VnState>::insert
  28:     0x72981fdf605c - <rustc_mir_transform[18da0cf66f51b93]::gvn::VnState>::simplify_rvalue::{closure#0}
  29:     0x72981ccd6f86 - <rustc_mir_transform[18da0cf66f51b93]::gvn::GVN as rustc_mir_transform[18da0cf66f51b93]::pass_manager::MirPass>::run_pass
  30:     0x72981f2047b3 - rustc_mir_transform[18da0cf66f51b93]::pass_manager::run_passes_inner
  31:     0x72981fb80d7b - rustc_mir_transform[18da0cf66f51b93]::optimized_mir
  32:     0x72981fb805ad - rustc_query_impl[e1b1efbe27e837e4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e1b1efbe27e837e4]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 8usize]>>
  33:     0x72981f31ae32 - rustc_query_system[df8f3c09d69e93fa]::query::plumbing::try_execute_query::<rustc_query_impl[e1b1efbe27e837e4]::DynamicConfig<rustc_query_system[df8f3c09d69e93fa]::query::caches::DefIdCache<rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e1b1efbe27e837e4]::plumbing::QueryCtxt, false>
  34:     0x72981f31a1a0 - rustc_query_impl[e1b1efbe27e837e4]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  35:     0x72981f757143 - <rustc_middle[e1b2a093fd8c5f9e]::ty::context::TyCtxt>::instance_mir
  36:     0x72981f5f2067 - rustc_interface[80363c102bb18c76]::passes::run_required_analyses
  37:     0x72982013703a - rustc_interface[80363c102bb18c76]::passes::analysis
  38:     0x729820137019 - rustc_query_impl[e1b1efbe27e837e4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e1b1efbe27e837e4]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 0usize]>>
  39:     0x7298202d0ecb - rustc_query_system[df8f3c09d69e93fa]::query::plumbing::try_execute_query::<rustc_query_impl[e1b1efbe27e837e4]::DynamicConfig<rustc_query_system[df8f3c09d69e93fa]::query::caches::SingleCache<rustc_middle[e1b2a093fd8c5f9e]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[e1b1efbe27e837e4]::plumbing::QueryCtxt, false>
  40:     0x7298202d0bb9 - rustc_query_impl[e1b1efbe27e837e4]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  41:     0x72982033dbbc - rustc_interface[80363c102bb18c76]::passes::create_and_enter_global_ctxt::<core[585ec36c4bc8fc42]::option::Option<rustc_interface[80363c102bb18c76]::queries::Linker>, rustc_driver_impl[cf432ae27b341183]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  42:     0x729820304420 - rustc_interface[80363c102bb18c76]::interface::run_compiler::<(), rustc_driver_impl[cf432ae27b341183]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7298201850d0 - std[7deecfbd79e4275a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[80363c102bb18c76]::util::run_in_thread_with_globals<rustc_interface[80363c102bb18c76]::util::run_in_thread_pool_with_globals<rustc_interface[80363c102bb18c76]::interface::run_compiler<(), rustc_driver_impl[cf432ae27b341183]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  44:     0x7298201854f4 - <<std[7deecfbd79e4275a]::thread::Builder>::spawn_unchecked_<rustc_interface[80363c102bb18c76]::util::run_in_thread_with_globals<rustc_interface[80363c102bb18c76]::util::run_in_thread_pool_with_globals<rustc_interface[80363c102bb18c76]::interface::run_compiler<(), rustc_driver_impl[cf432ae27b341183]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[585ec36c4bc8fc42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x729820185eaf - std::sys::pal::unix::thread::Thread::new::thread_start::h37bc1ac1274efed7
  46:     0x72981a4a370a - <unknown>
  47:     0x72981a527aac - <unknown>
  48:                0x0 - <unknown>

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: rustc 1.87.0-nightly (8dac72bb1 2025-02-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z dump-mir-dir=dir

query stack during panic:
#0 [vtable_entries] finding all vtable entries for trait `Trait`
#1 [optimized_mir] optimizing MIR for `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

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

@matthiaskrgr matthiaskrgr 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 Feb 23, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 23, 2025
@matthiaskrgr
Copy link
Member Author

bisects to #135318

@Noratrieb
Copy link
Member

@compiler-errors

@Noratrieb Noratrieb added A-mir-opt Area: MIR optimizations and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 23, 2025
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Mar 9, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants