rust-lang / rust-lang/rust

ICE: `encountered a fresh type during canonicalization`

Open
#148,632 4 comments 0 reactions 1 assignee View on GitHub

@fmease is already working on this.

Since Nov 7, 2025.

A-dyn-trait C-bug F-min_generic_const_args I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(associated_const_equality)]

trait B<C> {}
trait D<C, E>: B<C> + B<E> {
    fn f(&self) {}
}

trait Project {
    const SELF: dyn D<Self, Self>;
}

fn take1(_: Project<SELF = { loop {} }>) {}

fn main() {}

A mutant of glacier2's fixed/123140.rs

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (c90bcb957 2025-11-06)
binary: rustc
commit-hash: c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38
commit-date: 2025-11-06
host: x86_64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.3
Error output

Command: rustc

warning: trait objects without an explicit `dyn` are deprecated
  --> 10.rs:12:13
   |
12 | fn take1(_: Project<SELF = { loop {} }>) {}
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = 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/edition-guide/rust-2021/warnings-promoted-to-error.html>
   = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
help: if this is a dyn-compatible trait, use `dyn`
   |
12 | fn take1(_: dyn Project<SELF = { loop {} }>) {}
   |             +++

error[E0038]: the trait `Project` is not dyn compatible
  --> 10.rs:12:13
   |
12 | fn take1(_: Project<SELF = { loop {} }>) {}
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Project` is not dyn compatible
   |
note: for a trait to be dyn compatible it needs to allow building a vtable
      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
  --> 10.rs:9:11
   |
 8 | trait Project {
   |       ------- this trait is not dyn compatible...
 9 |     const SELF: dyn D<Self, Self>;
   |           ^^^^ ...because it contains this associated `const`
   = help: consider moving `SELF` to another trait

error[E0277]: the size for values of type `(dyn Project + 'static)` cannot be known at compilation time
  --> 10.rs:12:13
   |
12 | fn take1(_: Project<SELF = { loop {} }>) {}
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `(dyn Project + 'static)`
   = help: unsized fn params are gated as an unstable feature
help: you can use `impl Trait` as the argument type
   |
12 | fn take1(_: impl Project<SELF = { loop {} }>) {}
   |             ++++
help: function arguments must have a statically known size, borrowed types always have a known size
   |
12 | fn take1(_: &dyn Project<SELF = { loop {} }>) {}
   |             ++++

error: internal compiler error: compiler/rustc_infer/src/infer/canonical/canonicalizer.rs:382:17: encountered a fresh type during canonicalization


thread 'rustc' (6386688) panicked at compiler/rustc_infer/src/infer/canonical/canonicalizer.rs:382:17:
Box<dyn Any>
Backtrace

thread 'rustc' (6386688) panicked at compiler/rustc_infer/src/infer/canonical/canonicalizer.rs:382:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   7: <&rustc_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::fold_with::<rustc_infer::infer::canonical::canonicalizer::Canonicalizer>
   8: rustc_middle::ty::util::fold_list::<rustc_infer::infer::canonical::canonicalizer::Canonicalizer, &rustc_middle::ty::list::RawList<(), rustc_type_ir::binder::Binder<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::ExistentialPredicate<rustc_middle::ty::context::TyCtxt>>>, rustc_type_ir::binder::Binder<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::ExistentialPredicate<rustc_middle::ty::context::TyCtxt>>, <&rustc_middle::ty::list::RawList<(), rustc_type_ir::binder::Binder<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::ExistentialPredicate<rustc_middle::ty::context::TyCtxt>>> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::fold_with<rustc_infer::infer::canonical::canonicalizer::Canonicalizer>::{closure#0}>
   9: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
  10: <rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ImpliedOutlivesBounds> as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform
  11: <rustc_borrowck::type_check::free_region_relations::UniversalRegionRelationsBuilder>::add_implied_bounds
  12: rustc_borrowck::type_check::type_check
  13: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  14: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
  15: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  16: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  17: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  18: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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/jb/Library/CloudStorage/Dropbox/Desk/2503_rustc_ice/20251106 ice 보고용/rustc-ice-2025-11-07T06_32_36-88044.txt` to your bug report

query stack during panic:
#0 [mir_borrowck] borrow-checking `take1::{constant#0}`
#1 [analysis] running analysis passes on crate `10`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

Notes

@rustbot label +F-associated_const_equality

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.