Skip to content

[ICE]: has escaping bound vars, so it cannot be wrapped in a dummy binder #158317

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
trait FooMut {
    fn bar<I>(&self, _: I)
    where
        for<'b> &'b I: Iterator<Item = &'b ()>;

    fn bar<I>(&self, _: I)
    where
        I: Iterator,
    {
        let collection = vec![_I].iter().map(|x| ());
        self.bar(collection);
    }
}

original:

trait FooMut {
    fn bar<I>(&self, _: I)
    where
        for<'b> &'b I: Iterator<Item = &'b ()>;

    fn bar<I>(&self, _: I)
    where
        I: Iterator,
    {
        let collection = vec![_I].iter().map(|x| ());
        self.bar(collection);
    }
}

fn main() {}

Version information

rustc 1.98.0-nightly (4429659e4 2026-06-22)
binary: rustc
commit-hash: 4429659e4745016bd3f26a4a421843edc7fbc422
commit-date: 2026-06-22
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.7

Possibly related line of code:

fn register_goals(&mut self, obligations: impl IntoIterator<Item = Goal<I, I::Predicate>>) {
self.goals.extend(obligations);
}
fn register_alias_relate_predicate(&mut self, a: I::Ty, b: I::Ty) {
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
ty::Covariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Subtype,
),
// a :> b is b <: a

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=globally

Program output

error[E0428]: the name `bar` is defined multiple times
  --> /tmp/icemaker_global_tempdir.izummaQbYnwZ/rustc_testrunner_tmpdir_reporting.ofzxHrCribxf/mvce.rs:6:5
   |
 2 | /     fn bar<I>(&self, _: I)
 3 | |     where
 4 | |         for<'b> &'b I: Iterator<Item = &'b ()>;
   | |_______________________________________________- previous definition of the value `bar` here
 5 |
 6 | /     fn bar<I>(&self, _: I)
 7 | |     where
 8 | |         I: Iterator,
...  |
11 | |         self.bar(collection);
12 | |     }
   | |_____^ `bar` redefined here
   |
   = note: `bar` must be defined only once in the value namespace of this trait

error[E0425]: cannot find value `_I` in this scope
  --> /tmp/icemaker_global_tempdir.izummaQbYnwZ/rustc_testrunner_tmpdir_reporting.ofzxHrCribxf/mvce.rs:10:31
   |
10 |         let collection = vec![_I].iter().map(|x| ());
   |                               ^^ not found in this scope

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

error[E0277]: `&'b _` is not an iterator
  --> /tmp/icemaker_global_tempdir.izummaQbYnwZ/rustc_testrunner_tmpdir_reporting.ofzxHrCribxf/mvce.rs:11:18
   |
11 |         self.bar(collection);
   |              --- ^^^^^^^^^^ `&'b _` is not an iterator
   |              |
   |              required by a bound introduced by this call
   |
   = help: the trait `for<'b> Iterator` is not implemented for `&'b _`
note: required by a bound in `FooMut::bar`
  --> /tmp/icemaker_global_tempdir.izummaQbYnwZ/rustc_testrunner_tmpdir_reporting.ofzxHrCribxf/mvce.rs:4:24
   |
 2 |     fn bar<I>(&self, _: I)
   |        --- required by a bound in this associated function
 3 |     where
 4 |         for<'b> &'b I: Iterator<Item = &'b ()>;
   |                        ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `FooMut::bar`


thread 'rustc' (3118313) panicked at /rustc-dev/4429659e4745016bd3f26a4a421843edc7fbc422/compiler/rustc_type_ir/src/relate/solver_relating.rs:387:35:
`AliasRelate(Term::Ty(&'^0.Named(DefId(0:6 ~ mvce[b5bc]::FooMut::bar::'b)) ()), Equate, Term::Ty(Alias(Alias { kind: Projection { def_id: DefId(2:10209 ~ core[1e5d]::iter::traits::iterator::Iterator::Item) }, args: [{type error}], .. })))` has escaping bound vars, so it cannot be wrapped in a dummy binder.
stack backtrace:
   0:     0x7fc2b3822629 - <<std[3d46086344a7ae7a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[1e5dff68517d21c3]::fmt::Display>::fmt
   1:     0x7fc2b3e0ed1e - core[1e5dff68517d21c3]::fmt::write
   2:     0x7fc2b3838cc6 - <std[3d46086344a7ae7a]::sys::stdio::unix::Stderr as std[3d46086344a7ae7a]::io::Write>::write_fmt
   3:     0x7fc2b37f78ee - std[3d46086344a7ae7a]::panicking::default_hook::{closure#0}
   4:     0x7fc2b3815313 - std[3d46086344a7ae7a]::panicking::default_hook
   5:     0x7fc2b2870661 - std[3d46086344a7ae7a]::panicking::update_hook::<alloc[b6e8defdd65683e4]::boxed::Box<rustc_driver_impl[e98da4d991f149da]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc2b38155f2 - std[3d46086344a7ae7a]::panicking::panic_with_hook
   7:     0x7fc2b37f79b2 - std[3d46086344a7ae7a]::panicking::panic_handler::{closure#0}
   8:     0x7fc2b37ee679 - std[3d46086344a7ae7a]::sys::backtrace::__rust_end_short_backtrace::<std[3d46086344a7ae7a]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fc2b37f941d - __rustc[9ba924033e29ab74]::rust_begin_unwind
  10:     0x7fc2b06f713c - core[1e5dff68517d21c3]::panicking::panic_fmt
  11:     0x7fc2b3ed25aa - <rustc_type_ir[ddd872802aba9539]::relate::solver_relating::SolverRelating<rustc_infer[8178364f2f6d9ffd]::infer::InferCtxt, rustc_middle[cff461d045763160]::ty::context::TyCtxt> as rustc_type_ir[ddd872802aba9539]::relate::TypeRelation<rustc_middle[cff461d045763160]::ty::context::TyCtxt>>::tys
  12:     0x7fc2b4bfaeaf - <rustc_infer[8178364f2f6d9ffd]::infer::InferCtxt as rustc_type_ir[ddd872802aba9539]::relate::solver_relating::RelateExt>::relate::<rustc_middle[cff461d045763160]::ty::Ty>
  13:     0x7fc2b45636ba - <rustc_trait_selection[2a52d8c4a2c04eed]::traits::engine::ObligationCtxt>::eq::<rustc_middle[cff461d045763160]::ty::Ty>
  14:     0x7fc2b3548ec9 - <rustc_trait_selection[2a52d8c4a2c04eed]::error_reporting::TypeErrCtxt>::point_at_chain::<rustc_span[c0fd46f789e8d999]::ErrorGuaranteed>
  15:     0x7fc2b3569718 - <rustc_trait_selection[2a52d8c4a2c04eed]::error_reporting::TypeErrCtxt>::note_function_argument_obligation::<rustc_span[c0fd46f789e8d999]::ErrorGuaranteed>
  16:     0x7fc2b355e93f - <rustc_trait_selection[2a52d8c4a2c04eed]::error_reporting::TypeErrCtxt>::note_obligation_cause_code::<rustc_span[c0fd46f789e8d999]::ErrorGuaranteed, rustc_middle[cff461d045763160]::ty::predicate::Predicate>
  17:     0x7fc2b3650b06 - <rustc_trait_selection[2a52d8c4a2c04eed]::error_reporting::TypeErrCtxt>::note_obligation_cause
  18:     0x7fc2b21bc4cf - <rustc_trait_selection[2a52d8c4a2c04eed]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  19:     0x7fc2b4723065 - <rustc_hir_typeck[469cc3357cf82113]::fn_ctxt::FnCtxt>::check_expr_method_call
  20:     0x7fc2b4127f40 - <rustc_hir_typeck[469cc3357cf82113]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21:     0x7fc2b40f990c - <rustc_hir_typeck[469cc3357cf82113]::fn_ctxt::FnCtxt>::check_expr_block
  22:     0x7fc2b4127f6d - <rustc_hir_typeck[469cc3357cf82113]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7fc2b40ee42c - rustc_hir_typeck[469cc3357cf82113]::check::check_fn
  24:     0x7fc2b42cfc56 - rustc_hir_typeck[469cc3357cf82113]::typeck_with_inspect::{closure#0}
  25:     0x7fc2b42ccc70 - rustc_query_impl[f15f39df5e5f8d31]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  26:     0x7fc2b42cc0a9 - rustc_query_impl[f15f39df5e5f8d31]::execution::try_execute_query::<rustc_data_structures[69d529ec17ad3052]::vec_cache::VecCache<rustc_span[c0fd46f789e8d999]::def_id::LocalDefId, rustc_middle[cff461d045763160]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[cff461d045763160]::dep_graph::graph::DepNodeIndex>, false>
  27:     0x7fc2b42cba43 - rustc_query_impl[f15f39df5e5f8d31]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  28:     0x7fc2b42c646d - <rustc_middle[cff461d045763160]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[cb7c76efa507416e]::check_crate::{closure#1}>::{closure#0}
  29:     0x7fc2b42c5e61 - rustc_hir_analysis[cb7c76efa507416e]::check_crate
  30:     0x7fc2b42c81b4 - rustc_interface[3222c6a6230bc2a3]::passes::analysis
  31:     0x7fc2b4f06b07 - rustc_query_impl[f15f39df5e5f8d31]::execution::try_execute_query::<rustc_middle[cff461d045763160]::query::caches::SingleCache<rustc_middle[cff461d045763160]::query::erase::ErasedData<[u8; 0usize]>>, false>
  32:     0x7fc2b4f06769 - rustc_query_impl[f15f39df5e5f8d31]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  33:     0x7fc2b4f5d13d - rustc_interface[3222c6a6230bc2a3]::interface::run_compiler::<(), rustc_driver_impl[e98da4d991f149da]::run_compiler::{closure#0}>::{closure#1}
  34:     0x7fc2b4f18b7a - std[3d46086344a7ae7a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3222c6a6230bc2a3]::util::run_in_thread_with_globals<rustc_interface[3222c6a6230bc2a3]::util::run_in_thread_pool_with_globals<rustc_interface[3222c6a6230bc2a3]::interface::run_compiler<(), rustc_driver_impl[e98da4d991f149da]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x7fc2b4f1892d - <std[3d46086344a7ae7a]::thread::lifecycle::spawn_unchecked<rustc_interface[3222c6a6230bc2a3]::util::run_in_thread_with_globals<rustc_interface[3222c6a6230bc2a3]::util::run_in_thread_pool_with_globals<rustc_interface[3222c6a6230bc2a3]::interface::run_compiler<(), rustc_driver_impl[e98da4d991f149da]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1e5dff68517d21c3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7fc2b4f1cc92 - <std[3d46086344a7ae7a]::sys::thread::unix::Thread>::new::thread_start
  37:     0x7fc2aea981b9 - <unknown>
  38:     0x7fc2aeb1d21c - <unknown>
  39:                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.98.0-nightly (4429659e4 2026-06-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck_root] type-checking `FooMut::bar`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors

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

@rustbot label +WG-trait-system-refactor

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jun 23, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)
    on Jun 23, 2026
  3. matthiaskrgr commented on Jun 23, 2026

    @matthiaskrgr
    MemberAuthor

    since #156619

  4. moved this from needs triage to No status in -Znext-solver=globallyon Jun 24, 2026
  5. moved this to needs triage in -Znext-solver=globallyon Jun 24, 2026
  6. added a commit that references this issue on Jul 6, 2026
  7. added a commit that references this issue on Jul 7, 2026
  8. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 7, 2026
  9. added a commit that references this issue on Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions