rust-lang / rust-lang/rust

ICE: `assertion failed: !ty.has_non_region_infer()`

Open
#135,122 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug fixed-by-next-solver I-ICE S-bug-has-test S-has-bisection T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

use std::ops::Add;

struct Container<S: Data>(S);

trait Data {
    type Elem;
}

impl<A, S> Add<Container<S>> for f32
where
    f32: Add<A, Output = A>,
    S:,
{
}

impl<'a, A, S> Add<&'a Container<S>> for f32
where
    f32: Add<A>,
    S: Data<Elem = A>,
{
    type Output = Container<Vec<<f32 as Add<A>>::Output>>;
    fn add(self, _rhs: &Container<Data>) -> Self::Output {}
}

original:

use std::ops::Add;

struct Container<S: Data>(S);

trait Data {
    type Elem;
}

impl<A> Data for Vec<A> {
    type Elem = A;
}

impl<A, S> Add<Container<S>> for f32
where
    f32: Add<A, Output=A>,
    S: Data<Elem=A>,
{
    impl<A> Data for Vec<A> {
    type Elem = A;
}
    fn add(self, _rhs: Container<S>) -> Container<S> {
        unimplemented!()
    }
}

impl<'a, A, S> Add<&'a Container<S>> for f32
where
      f32: Add<A>,
      S: Data<Elem=A>,
{
    type Output = Container<Vec<<f32 as Add<A>>::Output>>;
    fn add(self, _rhs: &Container<Data>) -> Self::Output {
        unimplemented!()
    }
}

Version information

rustc 1.86.0-nightly (dcfa38fe2 2025-01-05)
binary: rustc
commit-hash: dcfa38fe234de9304169afc6638e81d0dd222c06
commit-date: 2025-01-05
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

Possibly related line of code:
https://github.com/rust-lang/rust/blob/dcfa38fe234de9304169afc6638e81d0dd222c06/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs#L48-L60

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:23:2
   |
23 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs`

warning: trait objects without an explicit `dyn` are deprecated
  --> /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:22:35
   |
22 |     fn add(self, _rhs: &Container<Data>) -> Self::Output {}
   |                                   ^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
   = note: `#[warn(bare_trait_objects)]` on by default
help: if this is a dyn-compatible trait, use `dyn`
   |
22 |     fn add(self, _rhs: &Container<dyn Data>) -> Self::Output {}
   |                                   +++

error[E0191]: the value of the associated type `Elem` in `Data` must be specified
  --> /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:22:35
   |
6  |     type Elem;
   |     --------- `Elem` defined here
...
22 |     fn add(self, _rhs: &Container<Data>) -> Self::Output {}
   |                                   ^^^^ help: specify the associated type: `Data<Elem = Type>`

error[E0207]: the type parameter `A` is not constrained by the impl trait, self type, or predicates
 --> /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:9:6
  |
9 | impl<A, S> Add<Container<S>> for f32
  |      ^ unconstrained type parameter


thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/outlives_bounds.rs:54:5:
assertion failed: !ty.has_non_region_infer()
stack backtrace:
   0:     0x7b44522d47ca - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hadf8e2df861efce2
   1:     0x7b4452a135e6 - core::fmt::write::h7a55e8c402e63d48
   2:     0x7b44539127d1 - std::io::Write::write_fmt::h3751c3424aa517d0
   3:     0x7b44522d4622 - std::sys::backtrace::BacktraceLock::print::hda228978e42208f7
   4:     0x7b44522d6bc7 - std::panicking::default_hook::{{closure}}::hd850557dd952fc8c
   5:     0x7b44522d69b0 - std::panicking::default_hook::hb302f704a65842a5
   6:     0x7b4451452928 - std[3100b7b695602b1a]::panicking::update_hook::<alloc[5f744d0bf49b6096]::boxed::Box<rustc_driver_impl[736abb8093ca35b1]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7b44522d7413 - std::panicking::rust_panic_with_hook::ha601460835d6d839
   8:     0x7b44522d70d6 - std::panicking::begin_panic_handler::{{closure}}::h81a3663d6cb5d12c
   9:     0x7b44522d4c99 - std::sys::backtrace::__rust_end_short_backtrace::h4ff0aa96a7064803
  10:     0x7b44522d6dcd - rust_begin_unwind
  11:     0x7b444ef9e9e0 - core::panicking::panic_fmt::h6dfbe1ba47369a2f
  12:     0x7b444fafa15c - core::panicking::panic::h24ba62daf6026c27
  13:     0x7b4453786400 - rustc_trait_selection[a36a1e16c88a6dc2]::traits::outlives_bounds::implied_outlives_bounds
  14:     0x7b445312cb37 - <rustc_infer[9bafcf6fc3bf205d]::infer::outlives::env::OutlivesEnvironment>::with_bounds::<core[5eafa33fb0699880]::iter::adapters::flatten::FlatMap<indexmap[5764fe6e3edd7c17]::set::iter::Iter<rustc_middle[ccb2eb78bedf1942]::ty::Ty>, alloc[5f744d0bf49b6096]::vec::Vec<rustc_middle[ccb2eb78bedf1942]::traits::query::OutlivesBound>, <rustc_infer[9bafcf6fc3bf205d]::infer::InferCtxt as rustc_trait_selection[a36a1e16c88a6dc2]::traits::outlives_bounds::InferCtxtExt>::implied_bounds_tys::{closure#0}>>
  15:     0x7b4453148e2b - rustc_hir_analysis[48e47dfc185f7fea]::check::compare_impl_item::compare_impl_item
  16:     0x7b44531476d5 - rustc_query_impl[ac2bab59562664c7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ac2bab59562664c7]::query_impl::compare_impl_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>>
  17:     0x7b4453131c23 - rustc_query_system[9e3640c263c85fee]::query::plumbing::try_execute_query::<rustc_query_impl[ac2bab59562664c7]::DynamicConfig<rustc_data_structures[52740ce709e2e05d]::vec_cache::VecCache<rustc_span[8e152531e0bcd89e]::def_id::LocalDefId, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[9e3640c263c85fee]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ac2bab59562664c7]::plumbing::QueryCtxt, false>
  18:     0x7b4453131601 - rustc_query_impl[ac2bab59562664c7]::query_impl::compare_impl_item::get_query_non_incr::__rust_end_short_backtrace
  19:     0x7b4453c06b3a - rustc_hir_analysis[48e47dfc185f7fea]::check::check::check_impl_items_against_trait
  20:     0x7b4453124d0f - rustc_hir_analysis[48e47dfc185f7fea]::check::check::check_item_type
  21:     0x7b4453133580 - rustc_hir_analysis[48e47dfc185f7fea]::check::wfcheck::check_well_formed
  22:     0x7b4453132463 - rustc_query_impl[ac2bab59562664c7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ac2bab59562664c7]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>>
  23:     0x7b4453131f05 - rustc_query_system[9e3640c263c85fee]::query::plumbing::try_execute_query::<rustc_query_impl[ac2bab59562664c7]::DynamicConfig<rustc_data_structures[52740ce709e2e05d]::vec_cache::VecCache<rustc_span[8e152531e0bcd89e]::def_id::LocalDefId, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[9e3640c263c85fee]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ac2bab59562664c7]::plumbing::QueryCtxt, false>
  24:     0x7b4453131981 - rustc_query_impl[ac2bab59562664c7]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7b445312edac - rustc_hir_analysis[48e47dfc185f7fea]::check::wfcheck::check_mod_type_wf
  26:     0x7b445312ebcb - rustc_query_impl[ac2bab59562664c7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ac2bab59562664c7]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7b445397a1c8 - rustc_query_system[9e3640c263c85fee]::query::plumbing::try_execute_query::<rustc_query_impl[ac2bab59562664c7]::DynamicConfig<rustc_query_system[9e3640c263c85fee]::query::caches::DefaultCache<rustc_span[8e152531e0bcd89e]::def_id::LocalModDefId, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ac2bab59562664c7]::plumbing::QueryCtxt, false>
  28:     0x7b4453979f70 - rustc_query_impl[ac2bab59562664c7]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7b4452dc2378 - rustc_hir_analysis[48e47dfc185f7fea]::check_crate
  30:     0x7b4452e950a8 - rustc_interface[21548936fe144d05]::passes::run_required_analyses
  31:     0x7b445391665e - rustc_interface[21548936fe144d05]::passes::analysis
  32:     0x7b445391662f - rustc_query_impl[ac2bab59562664c7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ac2bab59562664c7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 0usize]>>
  33:     0x7b445397f7d5 - rustc_query_system[9e3640c263c85fee]::query::plumbing::try_execute_query::<rustc_query_impl[ac2bab59562664c7]::DynamicConfig<rustc_query_system[9e3640c263c85fee]::query::caches::SingleCache<rustc_middle[ccb2eb78bedf1942]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ac2bab59562664c7]::plumbing::QueryCtxt, false>
  34:     0x7b445397f50e - rustc_query_impl[ac2bab59562664c7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7b445393ecde - rustc_interface[21548936fe144d05]::passes::create_and_enter_global_ctxt::<core[5eafa33fb0699880]::option::Option<rustc_interface[21548936fe144d05]::queries::Linker>, rustc_driver_impl[736abb8093ca35b1]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  36:     0x7b4453958524 - rustc_interface[21548936fe144d05]::interface::run_compiler::<(), rustc_driver_impl[736abb8093ca35b1]::run_compiler::{closure#0}>::{closure#1}
  37:     0x7b4453806187 - std[3100b7b695602b1a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[21548936fe144d05]::util::run_in_thread_with_globals<rustc_interface[21548936fe144d05]::util::run_in_thread_pool_with_globals<rustc_interface[21548936fe144d05]::interface::run_compiler<(), rustc_driver_impl[736abb8093ca35b1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  38:     0x7b4453806624 - <<std[3100b7b695602b1a]::thread::Builder>::spawn_unchecked_<rustc_interface[21548936fe144d05]::util::run_in_thread_with_globals<rustc_interface[21548936fe144d05]::util::run_in_thread_pool_with_globals<rustc_interface[21548936fe144d05]::interface::run_compiler<(), rustc_driver_impl[736abb8093ca35b1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5eafa33fb0699880]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7b4453807c01 - std::sys::pal::unix::thread::Thread::new::thread_start::he5122ef3561b8e92
  40:     0x7b444dca339d - <unknown>
  41:     0x7b444dd2849c - <unknown>
  42:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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.86.0-nightly (dcfa38fe2 2025-01-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [compare_impl_item] checking assoc item `<impl at /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:16:1: 19:23>::add` is compatible with trait definition
#1 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.eJbTZCOAMNoj/rustc_testrunner_tmpdir_reporting.9QYtHLbbaWJb/mvce.rs:16:1: 19:23>` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0191, E0207, E0601.
For more information about an error, try `rustc --explain E0191`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced Rust example and reproduce the ICE using the reported rustc command. Inspect compiler/rustc_trait_selection/src/traits/outlives_bounds.rs around lines 48-60 and the query stack involving compare_impl_item. Done means this input no longer causes the compiler to panic, while its reported compilation errors remain appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.