Skip to content

[ICE]: mgca: DefId does not appear in children of DefId #159172

Description

@matthiaskrgr

Since #158617 probably

code:

#![feature(min_generic_const_args)]
trait Iter<
    const C: core::direct_const_arg!(|| {
        use std::io::*;
        let mut buffer = std::fs::File::create("foo.txt")?;
        write!(buffer, "oh no")?;
    }),
>
{
}
fn main() {}

Version information

rustc 1.99.0-nightly (be8e82435 2026-07-11)
binary: rustc
commit-hash: be8e82435eb04fbe75ed5286b52735366e160bed
commit-date: 2026-07-11
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Possibly related line of code:

// and skips all non-owner parents, so fetch the HIR associated to it.
parent_info = tcx.lower_to_hir(hir_id.owner);
}
let parent_info = parent_info.unwrap();
*parent_info.children.get(&def_id).unwrap_or_else(|| {
panic!(
"{:?} does not appear in children of {:?}",
def_id,
parent_info.nodes.node().def_id()
)
})
};

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> a.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

error: expected type, found `direct_const_arg!()` constant
 --> a.rs:3:14
  |
3 |       const C: core::direct_const_arg!(|| {
  |  ______________^
4 | |         use std::io::*;
5 | |         let mut buffer = std::fs::File::create("foo.txt")?;
6 | |         write!(buffer, "oh no")?;
7 | |     }),
  | |______^


thread 'rustc' (3926550) panicked at /rustc-dev/be8e82435eb04fbe75ed5286b52735366e160bed/compiler/rustc_ast_lowering/src/lib.rs:686:13:
DefId(0:6 ~ a[a5a4]::Iter::{closure#0}) does not appear in children of DefId(0:3 ~ a[a5a4]::Iter)
stack backtrace:
   0:     0x7f0ae69ef336 - <<std[9dee65175fc15e8a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[f7c17f95b9e87ecb]::fmt::Display>::fmt
   1:     0x7f0ae700f0c8 - core[f7c17f95b9e87ecb]::fmt::write
   2:     0x7f0ae6a047ac - <std[9dee65175fc15e8a]::sys::stdio::unix::Stderr as core[f7c17f95b9e87ecb]::io::write::Write>::write_fmt
   3:     0x7f0ae69c36ba - std[9dee65175fc15e8a]::panicking::default_hook::{closure#0}
   4:     0x7f0ae69e1a53 - std[9dee65175fc15e8a]::panicking::default_hook
   5:     0x7f0ae59bbe2b - std[9dee65175fc15e8a]::panicking::update_hook::<alloc[6f37f170616d1c17]::boxed::Box<rustc_driver_impl[bdac25697827ee93]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f0ae69e1ef2 - std[9dee65175fc15e8a]::panicking::panic_with_hook
   7:     0x7f0ae69c3772 - std[9dee65175fc15e8a]::panicking::panic_handler::{closure#0}
   8:     0x7f0ae69b7c59 - std[9dee65175fc15e8a]::sys::backtrace::__rust_end_short_backtrace::<std[9dee65175fc15e8a]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f0ae69c50cd - __rustc[68377fe7e23c34a7]::rust_begin_unwind
  10:     0x7f0ae37684ec - core[f7c17f95b9e87ecb]::panicking::panic_fmt
  11:     0x7f0ae75118e9 - rustc_ast_lowering[b3c65ba3b18da7e]::lower_to_hir
  12:     0x7f0ae750b35d - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::lower_to_hir::invoke_provider_fn::__rust_begin_short_backtrace
  13:     0x7f0ae7509fca - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_data_structures[7274291927d51f67]::vec_cache::VecCache<rustc_span[fa652b6c2772fbf8]::def_id::LocalDefId, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 16usize]>, rustc_middle[dc20d7af34d4b5d8]::dep_graph::graph::DepNodeIndex>, false>
  14:     0x7f0ae7509d05 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::lower_to_hir::execute_query_non_incr::__rust_end_short_backtrace
  15:     0x7f0ae7509831 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::hir_owner::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f0ae7508bd2 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_data_structures[7274291927d51f67]::vec_cache::VecCache<rustc_span[fa652b6c2772fbf8]::def_id::LocalDefId, rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 32usize]>, rustc_middle[dc20d7af34d4b5d8]::dep_graph::graph::DepNodeIndex>, false>
  17:     0x7f0ae7508908 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::hir_owner::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f0ae7417b46 - <rustc_middle[dc20d7af34d4b5d8]::ty::context::TyCtxt>::lint_level_spec_at_node
  19:     0x7f0ae7650db7 - rustc_hir_analysis[ec844b60f7f98a43]::check_unused::check_unused_traits
  20:     0x7f0ae8170907 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::SingleCache<rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 0usize]>>, false>
  21:     0x7f0ae8170669 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::check_unused_traits::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f0ae7653475 - rustc_hir_analysis[ec844b60f7f98a43]::check_crate
  23:     0x7f0ae764e1cb - rustc_interface[3c71d144d463ca91]::passes::analysis
  24:     0x7f0ae8170907 - rustc_query_impl[65ec22dc7d75fb0e]::execution::try_execute_query::<rustc_middle[dc20d7af34d4b5d8]::query::caches::SingleCache<rustc_middle[dc20d7af34d4b5d8]::query::erase::ErasedData<[u8; 0usize]>>, false>
  25:     0x7f0ae81705e9 - rustc_query_impl[65ec22dc7d75fb0e]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7f0ae8107a9b - rustc_interface[3c71d144d463ca91]::interface::run_compiler::<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7f0ae815b57a - std[9dee65175fc15e8a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3c71d144d463ca91]::util::run_in_thread_with_globals<rustc_interface[3c71d144d463ca91]::util::run_in_thread_pool_with_globals<rustc_interface[3c71d144d463ca91]::interface::run_compiler<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f0ae815b32d - <std[9dee65175fc15e8a]::thread::lifecycle::spawn_unchecked<rustc_interface[3c71d144d463ca91]::util::run_in_thread_with_globals<rustc_interface[3c71d144d463ca91]::util::run_in_thread_pool_with_globals<rustc_interface[3c71d144d463ca91]::interface::run_compiler<(), rustc_driver_impl[bdac25697827ee93]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f7c17f95b9e87ecb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f0ae815f750 - <std[9dee65175fc15e8a]::sys::thread::unix::Thread>::new::thread_start
  30:     0x7f0ae1a97739 - <unknown>
  31:     0x7f0ae1b1bedc - <unknown>
  32:                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: please attach the file at `/tmp/l/rustc-ice-2026-07-12T07_57_55-3926548.txt` to your bug report

note: rustc 1.99.0-nightly (be8e82435 2026-07-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [lower_to_hir] lowering HIR for `Iter::{closure#0}`
#1 [hir_owner] getting owner for `Iter::{closure#0}`
#2 [check_unused_traits] checking unused trait imports in crate
#3 [analysis] running analysis passes on crate `a`
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

@rustbot label +F-min_generic_const_args

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-min_generic_const_args`#![feature(min_generic_const_args)]`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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Fields

    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