rust-lang / rust-lang/rust

ICE: `add_outlives_bounds: unexpected regions`

Open
#153,241 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-adt_const_params F-unsized_const_params I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(adt_const_params)]
#![feature(unsized_const_params)]
trait Config {
    const DATA: &[&[u8]];
}
struct Provider;
impl Config for Provider {
    const DATA: &[&[u8]] = &[&[]];
}
struct Box<const DATA: &'static [&'static [u8]]> {}
impl Drop for Box<{ Provider::DATA }> {
    fn drop(& mut self) {}
}
fn main() {
    let _ = Box::<{ Provider::DATA }>;
}

Related to #152891

Meta

rustc --version --verbose:

rustc 1.95.0-nightly (6a979b3e3 2026-02-26)
binary: rustc
commit-hash: 6a979b3e32522049d0acb4a47f7ae44b7c8abfd5
commit-date: 2026-02-26
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Backtrace

error[E0423]: expected value, found struct `Box`
  --> bug.rs:15:13
   |
10 | struct Box<const DATA: &'static [&'static [u8]]> {}
   | --------------------------------------------------- `Box` defined here
...
15 |     let _ = Box::<{ Provider::DATA }>;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `Box {}`

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

error[E0366]: `Drop` impls cannot be specialized
  --> bug.rs:11:1
   |
11 | impl Drop for Box<{ Provider::DATA }> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `{ Provider::DATA }` is not a generic parameter
note: use the same sequence of generic lifetime, type and const parameters as the struct definition
  --> bug.rs:10:1
   |
10 | struct Box<const DATA: &'static [&'static [u8]]> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: /rustc-dev/6a979b3e32522049d0acb4a47f7ae44b7c8abfd5/compiler/rustc_infer/src/infer/outlives/env.rs:85:26: add_outlives_bounds: unexpected regions: (ReLateParam(DefId(0:13 ~ bug[42c3]::{impl#1}::drop), LateNamed(DefId(2:61573 ~ core[fe7c]::ops::drop::Drop::drop::'_))), '{erased})


thread 'rustc' (929314) panicked at /rustc-dev/6a979b3e32522049d0acb4a47f7ae44b7c8abfd5/compiler/rustc_infer/src/infer/outlives/env.rs:85:26:
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::outlives::env::OutlivesEnvironment as rustc_trait_selection::regions::OutlivesEnvironmentBuildExt>::new_with_implied_bounds_compat::<indexmap::set::IndexSet<rustc_middle::ty::Ty, rustc_hash::FxBuildHasher>>
   7: rustc_hir_analysis::check::compare_impl_item::compare_impl_item
      [... omitted 1 frame ...]
   8: rustc_hir_analysis::check::check::check_item_type
   9: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  10: rustc_hir_analysis::check::wfcheck::check_type_wf
      [... omitted 1 frame ...]
  11: rustc_hir_analysis::check_crate
  12: rustc_interface::passes::analysis
  13: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
  14: 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 `test/rustc-ice-2026-03-01T04_47_53-929216.txt` to your bug report

note: rustc 1.95.0-nightly (6a979b3e3 2026-02-26) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [compare_impl_item] checking assoc item `<impl at test.rs:11:1: 11:38>::drop` is compatible with trait definition
#1 [check_well_formed] checking that `<impl at test.rs:11:1: 11:38>` is well-formed
#2 [check_type_wf] checking that types are well-formed
#3 [analysis] running analysis passes on crate `test`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

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 by reproducing the provided snippet with the reported nightly compiler, then inspect compiler/rustc_infer/src/infer/outlives/env.rs at add_outlives_bounds and the compare_impl_item query shown in the stack. Trace how the Drop implementation reaches the unexpected-regions assertion. Done means the reproducer no longer triggers an internal compiler error and produces an appropriate diagnostic.

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
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.