rust-lang / rust-lang/rust

[ICE]: mgca: `cannot relate region: LUB`

Open
#159,688 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code
#![feature(min_generic_const_args)]
#![feature(min_adt_const_params)]

use std::marker::ConstParamTy;

pub struct Foo {
    slice: &'static [u8],
}

#[derive(PartialEq, Eq)]
pub struct Foo_<const F: Foo>;

impl
    Foo_<
        {
            Foo {
                slice: &[1, 2, 3],
            }
        },
    >
{
}


fn main() {}

Meta

rustc --version --verbose:

rustc 1.99.0-nightly (87e5904f5 2026-07-20)
binary: rustc
commit-hash: 87e5904f5eb6398af6b22eac2802c78934260c48
commit-date: 2026-07-20
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8
Error output
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> red.rs:1:12
  |
1 | #![feature(min_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unused import: `std::marker::ConstParamTy`
 --> red.rs:4:5
  |
4 | use std::marker::ConstParamTy;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
  --> red.rs:11:26
   |
11 | pub struct Foo_<const F: Foo>;
   |                          ^^^
   |
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct
   |
 6 + #[derive(ConstParamTy, PartialEq, Eq)]
 7 | pub struct Foo {
   |
Backtrace

error: internal compiler error: /rustc-dev/87e5904f5eb6398af6b22eac2802c78934260c48/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:507:17: cannot relate region: LUB('static, '{erased})


thread 'rustc' (932514) panicked at /rustc-dev/87e5904f5eb6398af6b22eac2802c78934260c48/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:507:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f13bdaf82c6 - <<std[6efd5c09ffcfac08]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[ea245c8d2ee73497]::fmt::Display>::fmt
   1:     0x7f13be20a2d0 - core[ea245c8d2ee73497]::fmt::write
   2:     0x7f13bdb0d52c - <std[6efd5c09ffcfac08]::sys::stdio::unix::Stderr as core[ea245c8d2ee73497]::io::write::Write>::write_fmt
   3:     0x7f13bdac9f8a - std[6efd5c09ffcfac08]::panicking::default_hook::{closure#0}
   4:     0x7f13bdaeaa23 - std[6efd5c09ffcfac08]::panicking::default_hook
   5:     0x7f13bca8d67b - std[6efd5c09ffcfac08]::panicking::update_hook::<alloc[a1e390ae03eee5f8]::boxed::Box<rustc_driver_impl[59d4b006446e1bc6]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f13bdaeaec2 - std[6efd5c09ffcfac08]::panicking::panic_with_hook
   7:     0x7f13bcabb171 - std[6efd5c09ffcfac08]::panicking::begin_panic::<rustc_errors[c0ac912468147ca8]::ExplicitBug>::{closure#0}
   8:     0x7f13bcab3eb6 - std[6efd5c09ffcfac08]::sys::backtrace::__rust_end_short_backtrace::<std[6efd5c09ffcfac08]::panicking::begin_panic<rustc_errors[c0ac912468147ca8]::ExplicitBug>::{closure#0}, !>
   9:     0x7f13bcab1ef7 - std[6efd5c09ffcfac08]::panicking::begin_panic::<rustc_errors[c0ac912468147ca8]::ExplicitBug>
  10:     0x7f13bcac6ea1 - <rustc_errors[c0ac912468147ca8]::diagnostic::BugAbort as rustc_errors[c0ac912468147ca8]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f13bd0596d9 - rustc_middle[29b03d310a3cce60]::util::bug::opt_span_bug_fmt::<rustc_span[e37ebf9381237dab]::span_encoding::Span>::{closure#0}
  12:     0x7f13bd059842 - rustc_middle[29b03d310a3cce60]::ty::context::tls::with_opt::<rustc_middle[29b03d310a3cce60]::util::bug::opt_span_bug_fmt<rustc_span[e37ebf9381237dab]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f13bd044b6b - rustc_middle[29b03d310a3cce60]::ty::context::tls::with_context_opt::<rustc_middle[29b03d310a3cce60]::ty::context::tls::with_opt<rustc_middle[29b03d310a3cce60]::util::bug::opt_span_bug_fmt<rustc_span[e37ebf9381237dab]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f13ba5f26e4 - rustc_middle[29b03d310a3cce60]::util::bug::bug_fmt
  15:     0x7f13becf2e33 - <rustc_infer[2eb1aa5a4cde060a]::infer::lexical_region_resolve::LexicalResolver>::lub_concrete_regions
  16:     0x7f13becf2844 - <rustc_infer[2eb1aa5a4cde060a]::infer::lexical_region_resolve::LexicalResolver>::sub_concrete_regions
  17:     0x7f13bb3644cc - rustc_infer[2eb1aa5a4cde060a]::infer::lexical_region_resolve::resolve
  18:     0x7f13bf36f6ed - <rustc_infer[2eb1aa5a4cde060a]::infer::InferCtxt as rustc_trait_selection[88d947e23979c5c4]::regions::InferCtxtRegionExt>::resolve_regions_with_outlives_env
  19:     0x7f13beb5aab0 - rustc_hir_analysis[ca44aecb6e5f879b]::check::wfcheck::check_impl
  20:     0x7f13bf0ec606 - rustc_hir_analysis[ca44aecb6e5f879b]::check::check::check_item_type
  21:     0x7f13bf0df9aa - rustc_hir_analysis[ca44aecb6e5f879b]::check::wfcheck::check_well_formed
  22:     0x7f13bf0df98b - rustc_query_impl[1529885af8ad1ce5]::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f13bf0def71 - rustc_query_impl[1529885af8ad1ce5]::execution::try_execute_query::<rustc_data_structures[4108383575fd76c4]::vec_cache::VecCache<rustc_span[e37ebf9381237dab]::def_id::LocalDefId, rustc_middle[29b03d310a3cce60]::query::erase::ErasedData<[u8; 1usize]>, rustc_middle[29b03d310a3cce60]::dep_graph::graph::DepNodeIndex>, false>
  24:     0x7f13bf0ded07 - rustc_query_impl[1529885af8ad1ce5]::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f13bf0db6c6 - rustc_hir_analysis[ca44aecb6e5f879b]::check::wfcheck::check_type_wf
  26:     0x7f13bf0db5cf - rustc_query_impl[1529885af8ad1ce5]::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7f13bf352f52 - rustc_query_impl[1529885af8ad1ce5]::execution::try_execute_query::<rustc_middle[29b03d310a3cce60]::query::caches::SingleCache<rustc_middle[29b03d310a3cce60]::query::erase::ErasedData<[u8; 1usize]>>, false>
  28:     0x7f13bf352d37 - rustc_query_impl[1529885af8ad1ce5]::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f13be6ce5da - rustc_hir_analysis[ca44aecb6e5f879b]::check_crate
  30:     0x7f13be6c874b - rustc_interface[8d1f9f90545f286d]::passes::analysis
  31:     0x7f13bf353d47 - rustc_query_impl[1529885af8ad1ce5]::execution::try_execute_query::<rustc_middle[29b03d310a3cce60]::query::caches::SingleCache<rustc_middle[29b03d310a3cce60]::query::erase::ErasedData<[u8; 0usize]>>, false>
  32:     0x7f13bf353a29 - rustc_query_impl[1529885af8ad1ce5]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  33:     0x7f13bf3a2e0d - rustc_interface[8d1f9f90545f286d]::interface::run_compiler::<(), rustc_driver_impl[59d4b006446e1bc6]::run_compiler::{closure#0}>::{closure#2}
  34:     0x7f13bf37c024 - std[6efd5c09ffcfac08]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8d1f9f90545f286d]::util::run_in_thread_with_globals<rustc_interface[8d1f9f90545f286d]::util::run_in_thread_pool_with_globals<rustc_interface[8d1f9f90545f286d]::interface::run_compiler<(), rustc_driver_impl[59d4b006446e1bc6]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x7f13bf37bdfb - <std[6efd5c09ffcfac08]::thread::lifecycle::spawn_unchecked<rustc_interface[8d1f9f90545f286d]::util::run_in_thread_with_globals<rustc_interface[8d1f9f90545f286d]::util::run_in_thread_pool_with_globals<rustc_interface[8d1f9f90545f286d]::interface::run_compiler<(), rustc_driver_impl[59d4b006446e1bc6]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ea245c8d2ee73497]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7f13bf38643a - <std[6efd5c09ffcfac08]::sys::thread::unix::Thread>::new::thread_start
  37:     0x7f13b8a97739 - <unknown>
  38:     0x7f13b8b1bedc - <unknown>
  39:                0x0 - <unknown>

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 `/tmp/K/rustc-ice-2026-07-21T20_38_34-932504.txt` to your bug report

note: rustc 1.99.0-nightly (87e5904f5 2026-07-20) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `<impl at red.rs:13:1: 20:6>` is well-formed
#1 [check_type_wf] checking that types are well-formed
#2 [analysis] running analysis passes on crate `red`
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

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

Reproduce the ICE with the red.rs example, then start at compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:507 and follow the check_well_formed query stack shown in the report. Done means this input no longer causes rustc to panic with cannot relate region: LUB('static, '{erased}).

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.