Skip to content

[ICE]: expected a projection #155204

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
#![feature(inherent_associated_types)]
pub struct Windows<T> {}

impl<T> Windows<fn(&())> {
    type AssocType = impl Send;
    fn ret(&self) -> Self::AssocType {
        ()
    }
}

original:

pub trait Iter {
    type Item<'a> where Self: 'a;

    fn next<'a>(&'a mut self) -> Option<Windows<T>>;

    fn for_each<F>(&'a mut self, mut f: F)
        where Self: Sized, F: for<'a> FnMut(Self::Windows<'a>)
    {
      todo!()
    }
}

pub struct Windows<T> {}

impl<T> Windows<fn(&())> {
    type AssocType = impl Send;
    fn ret(&self) -> Self::AssocType {
        ()
    }
}

impl<T> Iter for Windows<T> {

    fn T<'a>(&'for_each mut self) -> Option<Self::Item<'a>> {
        todo!();
    }
}

Version information

rustc 1.97.0-nightly (532f8f144 2026-04-12)
binary: rustc
commit-hash: 532f8f1443be8f605bcc9da7968e3476d3f27d26
commit-date: 2026-04-12
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Possibly related line of code:

/// Extracts the underlying trait reference and own args from this projection.
///
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
/// then this function would return a `T: StreamingIterator` trait reference and
/// `['a]` as the own args.
pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) {
let AliasTyKind::Projection { def_id } = self.kind else { panic!("expected a projection") };
interner.trait_ref_and_own_args_for_alias(def_id, self.args)
}
/// Extracts the underlying trait reference from this projection.
///

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(inherent_associated_types) -Znext-solver=globally

Program output

error[E0658]: `impl Trait` in associated types is unstable
 --> /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:4:22
  |
4 |     type AssocType = impl Send;
  |                      ^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable
  = note: this compiler was built on 2026-04-12; consider upgrading it if it is out of date

warning: the feature `inherent_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:12
  |
1 | #![feature(inherent_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
  = note: `#[warn(incomplete_features)]` on by default

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

error[E0392]: type parameter `T` is never used
 --> /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:1:20
  |
1 | pub struct Windows<T> {}
  |                    ^ unused type parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:3:6
  |
3 | impl<T> Windows<fn(&())> {
  |      ^ unconstrained type parameter

error[E0282]: type annotations needed
 --> /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:5:22
  |
5 |     fn ret(&self) -> Self::AssocType {
  |                      ^^^^^^^^^^^^^^^ cannot infer type

error: unconstrained opaque type
 --> /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:4:22
  |
4 |     type AssocType = impl Send;
  |                      ^^^^^^^^^
  |
  = note: `AssocType` must be used in combination with a concrete type within the same impl


thread 'rustc' (4172499) panicked at /rustc-dev/532f8f1443be8f605bcc9da7968e3476d3f27d26/compiler/rustc_type_ir/src/ty_kind.rs:522:67:
expected a projection
stack backtrace:
   0:     0x7fc5e342b31b - <<std[30bf32b9e108fde8]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[afc6995f3fa91ad]::fmt::Display>::fmt
   1:     0x7fc5e3a20a48 - core[afc6995f3fa91ad]::fmt::write
   2:     0x7fc5e34425e6 - <std[30bf32b9e108fde8]::sys::stdio::unix::Stderr as std[30bf32b9e108fde8]::io::Write>::write_fmt
   3:     0x7fc5e3401618 - std[30bf32b9e108fde8]::panicking::default_hook::{closure#0}
   4:     0x7fc5e341e983 - std[30bf32b9e108fde8]::panicking::default_hook
   5:     0x7fc5e23fb5bc - std[30bf32b9e108fde8]::panicking::update_hook::<alloc[ad9adc906e64577e]::boxed::Box<rustc_driver_impl[56c0fec0d7fc84ae]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc5e341ec62 - std[30bf32b9e108fde8]::panicking::panic_with_hook
   7:     0x7fc5e340170a - std[30bf32b9e108fde8]::panicking::panic_handler::{closure#0}
   8:     0x7fc5e33f5c39 - std[30bf32b9e108fde8]::sys::backtrace::__rust_end_short_backtrace::<std[30bf32b9e108fde8]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fc5e340313d - __rustc[a6530efb79a2fd0]::rust_begin_unwind
  10:     0x7fc5dff5d63c - core[afc6995f3fa91ad]::panicking::panic_fmt
  11:     0x7fc5e311738e - <rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::suggest_constraint::<&<rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::expected_projection::{closure#0}>
  12:     0x7fc5e31e866e - <rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::note_and_explain_type_err
  13:     0x7fc5e1c1930a - <rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::note_type_err
  14:     0x7fc5e31d5c7f - <rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::report_and_explain_type_error
  15:     0x7fc5e0950f4d - <rustc_trait_selection[6b2e4746fb1d1412]::error_reporting::TypeErrCtxt>::report_mismatched_types
  16:     0x7fc5e1b12433 - <rustc_hir_typeck[4630abcebbdfa870]::coercion::CoerceMany>::report_return_mismatched_types
  17:     0x7fc5e3d5fe9d - <rustc_hir_typeck[4630abcebbdfa870]::fn_ctxt::FnCtxt>::check_expr_block
  18:     0x7fc5e3dbc5c1 - <rustc_hir_typeck[4630abcebbdfa870]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  19:     0x7fc5e3d552c0 - rustc_hir_typeck[4630abcebbdfa870]::check::check_fn
  20:     0x7fc5e4c01733 - rustc_hir_typeck[4630abcebbdfa870]::typeck_with_inspect::{closure#0}
  21:     0x7fc5e4c00130 - rustc_query_impl[c84ee57d90a0448f]::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  22:     0x7fc5e3dee466 - rustc_query_impl[c84ee57d90a0448f]::execution::try_execute_query::<rustc_data_structures[981e95ba1a8afd5c]::vec_cache::VecCache<rustc_span[786217fdcf1835d0]::def_id::LocalDefId, rustc_middle[5ed6dbbca286abee]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[5ed6dbbca286abee]::dep_graph::graph::DepNodeIndex>, false>
  23:     0x7fc5e3dedc83 - rustc_query_impl[c84ee57d90a0448f]::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  24:     0x7fc5e3df17d4 - <rustc_middle[5ed6dbbca286abee]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[a31e2ccfc121be5e]::check_crate::{closure#1}>::{closure#0}
  25:     0x7fc5e3df11ad - rustc_hir_analysis[a31e2ccfc121be5e]::check_crate
  26:     0x7fc5e490d742 - rustc_interface[82dfd3b1fd905165]::passes::analysis
  27:     0x7fc5e4bbe0c9 - rustc_query_impl[c84ee57d90a0448f]::execution::try_execute_query::<rustc_middle[5ed6dbbca286abee]::query::caches::SingleCache<rustc_middle[5ed6dbbca286abee]::query::erase::ErasedData<[u8; 0usize]>>, false>
  28:     0x7fc5e4bbdd29 - rustc_query_impl[c84ee57d90a0448f]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7fc5e4b94890 - rustc_interface[82dfd3b1fd905165]::interface::run_compiler::<(), rustc_driver_impl[56c0fec0d7fc84ae]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7fc5e4b7e8be - std[30bf32b9e108fde8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[82dfd3b1fd905165]::util::run_in_thread_with_globals<rustc_interface[82dfd3b1fd905165]::util::run_in_thread_pool_with_globals<rustc_interface[82dfd3b1fd905165]::interface::run_compiler<(), rustc_driver_impl[56c0fec0d7fc84ae]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  31:     0x7fc5e4b7f160 - <std[30bf32b9e108fde8]::thread::lifecycle::spawn_unchecked<rustc_interface[82dfd3b1fd905165]::util::run_in_thread_with_globals<rustc_interface[82dfd3b1fd905165]::util::run_in_thread_pool_with_globals<rustc_interface[82dfd3b1fd905165]::interface::run_compiler<(), rustc_driver_impl[56c0fec0d7fc84ae]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[afc6995f3fa91ad]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7fc5e4b7ffec - <std[30bf32b9e108fde8]::sys::thread::unix::Thread>::new::thread_start
  33:     0x7fc5de6a597a - <unknown>
  34:     0x7fc5de7292bc - <unknown>
  35:                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.97.0-nightly (532f8f144 2026-04-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(inherent_associated_types) -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck_root] type-checking `<impl at /tmp/icemaker_global_tempdir.nWLI7VjApHkt/rustc_testrunner_tmpdir_reporting.cMBT7uk0gMpW/mvce.rs:3:1: 3:25>::ret`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 6 previous errors; 1 warning emitted

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

@rustbot label +F-inherent_associated_types +WG-trait-system-refactor

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]`F-inherent_associated_types`#![feature(inherent_associated_types)]`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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions