ICE: `encountered a fresh type during canonicalization`
Opened this issue · 4 comments
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
-
ICE location:
compiler/rustc_infer/src/infer/canonical/canonicalizer.rs Line-382
rust/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Lines 381 to 383 in c90bcb9
-
Duplication Check
- I searched "canonicalizer.rs" ICE (Github issue page with query)
- #138891 shows identical ICE location, but the codes in there make no ICE for now.
@rustbot label +F-associated_const_equality
trait D<C> {}
trait Project {
const SELF: dyn D<Self>;
}
fn main() {
let _: &dyn Project<SELF = { 0 }>;
}cargo-bisect-rustc --start=2022-01-01 --end=2025-11-07 --regress ice --preserve --script rustc -- 148632.rs
********************************************************************************
Regression in nightly-2022-02-03
********************************************************************************
fetching https://static.rust-lang.org/dist/2022-02-02/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2022-02-02: 40 B / 40 B [================================================================================================================================================] 100.00 % 804.24 KB/s converted 2022-02-02 to 2681f253bcdb31a274411d2be456e7c6a1c67d62
fetching https://static.rust-lang.org/dist/2022-02-03/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2022-02-03: 40 B / 40 B [==================================================================================================================================================] 100.00 % 1.54 MB/s converted 2022-02-03 to 27f5d830eb11cd7bdc834d6f0d78120976f75443
looking for regression commit between 2022-02-02 and 2022-02-03
fetching (via remote github) commits from max(2681f253bcdb31a274411d2be456e7c6a1c67d62, 2022-01-31) to 27f5d830eb11cd7bdc834d6f0d78120976f75443
ending github query because we found starting sha: 2681f253bcdb31a274411d2be456e7c6a1c67d62
get_commits_between returning commits, len: 7
commit[0] 2022-02-01: Auto merge of #93442 - yaahc:Termination-abstraction, r=Mark-Simulacrum
commit[1] 2022-02-01: Auto merge of #93285 - JulianKnodt:const_eq_2, r=oli-obk
commit[2] 2022-02-02: Auto merge of #93466 - cjgillot:query-dead, r=nagisa
commit[3] 2022-02-02: Auto merge of #93573 - matthiaskrgr:rollup-nrjmygz, r=matthiaskrgr
commit[4] 2022-02-02: Auto merge of #93154 - michaelwoerister:fix-generic-closure-and-generator-debuginfo, r=wesleywiser
commit[5] 2022-02-02: Auto merge of #93312 - pierwill:map-all-local-trait-impls, r=cjgillot
commit[6] 2022-02-02: Auto merge of #93594 - matthiaskrgr:rollup-lcvhpdv, r=matthiaskrgr
ERROR: no CI builds available between 2681f253bcdb31a274411d2be456e7c6a1c67d62 and 27f5d830eb11cd7bdc834d6f0d78120976f75443 within last 167 days
We're leaking a trait_object_dummy_self which is the underlying problem (see e.g., #123140 for details).
It happens to be the case that trait_object_dummy_self is defined to be Infer(FreshTy(0)). As a result, various later compiler stages will bug out when encountering this fake type and that can take on quite different panic messages & query stacks but the root issue is still the same.