Repository: rust
Issue: ICE: `No HirID for DefId(...)` with feature `generic_assert`
Labels: I-ICE,T-compiler,C-bug,requires-nightly,S-bug-has-test,F-non_lifetime_binders,F-generic_assert

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Note

- Command: `rustc -Zcrate-attr="feature(generic_assert)"`
- ICE-loc:
https://github.com/rust-lang/rust/blob/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/compiler/rustc_middle/src/hir/mod.rs#L168
- I can't find any other ICE issue with this message.

### Code

(reduced)

```Rust
fn foo()
where
    for<const N: usize = {
        || {
            assert!(u1 == u2);
        };
    }> ():,
{
}
```

<details><summary><strong>Original Code</strong></summary>
<p>

```Rust
// test for ICE "no entry found for key" in generics_of.rs #113017

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub fn foo()
where
    for<const N: usize = { || {
    let u = U { b: 0 };
    let u1 = u;
    let u2 = u.clone();
    assert!(u1 == u2);

    let w = W { a: 0 };
    let w1 = w.clone();
    assert!(w == w1);
}; 1 }> ():,
    //~^ ERROR only lifetime parameters can be used in this context
    //~^^  ERROR defaults for generic parameters are not allowed in `for<...>` binders
{}

pub fn main() {}
```

</p>
</details>


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.79.0-nightly (9d5cdf75a 2024-04-07)
binary: rustc
commit-hash: 9d5cdf75aa42faaf0b58ba21a510117e8d0051a3
commit-date: 2024-04-07
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.3
```

### Command
`rustc -Zcrate-attr="feature(generic_assert)"`

### Error output

```
error[E0425]: cannot find value `u1` in this scope
 --> r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs:5:21
  |
5 |             assert!(u1 == u2);
  |                     ^^ not found in this scope

error[E0425]: cannot find value `u2` in this scope
 --> r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs:5:27
  |
5 |             assert!(u1 == u2);
  |                           ^^ not found in this scope

error[E0658]: only lifetime parameters can be used in this context
 --> r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs:3:15
  |
3 |     for<const N: usize = {
  |               ^
  |
  = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
  = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
  = note: this compiler was built on 2024-04-07; consider upgrading it if it is out of date

error: defaults for generic parameters are not allowed in `for<...>` binders
 --> r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs:3:9
  |
3 |       for<const N: usize = {
  |  _________^
4 | |         || {
5 | |             assert!(u1 == u2);
6 | |         };
7 | |     }> ():,
  | |_____^

error[E0601]: `main` function not found in crate `r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B`
 --> r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs:9:2
  |
9 | }
  |  ^ consider adding a `main` function to `r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B.rs`
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```

error: internal compiler error: /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/compiler/rustc_middle/src/hir/mod.rs:168:32: No HirId for DefId(0:6 ~ r_A95E66CAB86034DA3FA9192088ADD18A7364FEB318508290E83C5B9C99E7388B[c8dc]::foo::{constant#0}::{closure#0})

thread 'rustc' panicked at /rustc/9d5cdf75aa42faaf0b58ba21a510117e8d0051a3/compiler/rustc_middle/src/hir/mod.rs:168:32:
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_middle::hir::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
      [... omitted 1 frame ...]
   7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
   8: <rustc_middle::hir::provide::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_hir::hir_id::OwnerId)>>::call_once
      [... omitted 1 frame ...]
   9: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  10: <rustc_middle::ty::context::TyCtxt>::parent_hir_id
  11: <rustc_middle::lint::ShallowLintLevelMap>::probe_for_lint_level
  12: <rustc_middle::lint::ShallowLintLevelMap>::lint_level_id_at_node
  13: <rustc_lint::levels::LintLevelsBuilder<rustc_lint::levels::LintLevelQueryMap>>::insert_spec
  14: <rustc_lint::levels::LintLevelsBuilder<rustc_lint::levels::LintLevelQueryMap>>::add
  15: rustc_lint::levels::shallow_lint_levels_on
      [... omitted 1 frame ...]
  16: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  17: rustc_hir_analysis::check_unused::check_unused_traits
      [... omitted 1 frame ...]
  18: rustc_hir_analysis::check_crate
  19: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  20: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  21: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: it seems that this compiler `1.79.0-nightly (9d5cdf75a 2024-04-07)` is outdated, a newer nightly should have been released in the mean time
  |
  = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
  = note: if the problem still persists, 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 attach the file at `/Volumes/T7/workspace/placeholder_rustexec/0408/rustc-ice-2024-04-08T12_46_17-87853.txt` to your bug report

note: compiler flags: -Z crate-attr=feature(generic_assert)

query stack during panic:
#0 [local_def_id_to_hir_id] getting HIR ID of `foo::{constant#0}::{closure#0}`
#1 [hir_owner_parent] getting HIR parent of `foo::{constant#0}::{closure#0}::{use#1}`
#2 [shallow_lint_levels_on] looking up lint levels for `foo::{constant#0}::{closure#0}::{use#1}`
#3 [check_unused_traits] checking unused trait imports in crate
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0425`.
```

</p>
</details>