Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: impl_trait_in_bindings: No HirId for DefId #134307

Closed
matthiaskrgr opened this issue Dec 14, 2024 · 1 comment · Fixed by #134313
Closed

ICE: impl_trait_in_bindings: No HirId for DefId #134307

matthiaskrgr opened this issue Dec 14, 2024 · 1 comment · Fixed by #134313
Assignees
Labels
A-metadata Area: Crate metadata C-bug Category: This is a bug. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

//@compile-flags: --crate-type=lib
#![feature(impl_trait_in_bindings)]
fn new() {
    let i: i32 = 0;
    let j: &impl PartialEq = &i;
}

original:

use std::ops::Add;

fn new() {
    let i: i32 = 0;
    let j: &impl PartialEq = &i;
    //~^ `impl Trait` is not allowed in the type of variable bindings
}

Version information

rustc 1.85.0-nightly (f5079d00e 2024-12-14)
binary: rustc
commit-hash: f5079d00e63718235f95353df38ebb0891bab5b4
commit-date: 2024-12-14
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(impl_trait_in_bindings) --crate-type=lib

Program output

warning: unused variable: `j`
 --> /tmp/icemaker_global_tempdir.IDmpCOQFuoUf/rustc_testrunner_tmpdir_reporting.ewZJCTGzPUBc/mvce.rs:3:9
  |
3 |     let j: &impl PartialEq = &i;
  |         ^ help: if this is intentional, prefix it with an underscore: `_j`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function `new` is never used
 --> /tmp/icemaker_global_tempdir.IDmpCOQFuoUf/rustc_testrunner_tmpdir_reporting.ewZJCTGzPUBc/mvce.rs:1:4
  |
1 | fn new() {
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

error: internal compiler error: /rustc/f5079d00e63718235f95353df38ebb0891bab5b4/compiler/rustc_middle/src/hir/mod.rs:182:32: No HirId for DefId(0:4 ~ mvce[e79c]::new::{opaque#0})

thread 'rustc' panicked at /rustc/f5079d00e63718235f95353df38ebb0891bab5b4/compiler/rustc_middle/src/hir/mod.rs:182:32:
Box<dyn Any>
stack backtrace:
   0:     0x76318f58e4ea - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::ha0c263ead94684c1
   1:     0x76318fe13d26 - core::fmt::write::h3e3bbe3ca914e5b8
   2:     0x763190e126d1 - std::io::Write::write_fmt::h8644899506913dbe
   3:     0x76318f58e342 - std::sys::backtrace::BacktraceLock::print::h860b21be370591ee
   4:     0x76318f59083a - std::panicking::default_hook::{{closure}}::h3ee6bbfbfbc66430
   5:     0x76318f590683 - std::panicking::default_hook::h79822c95ebfc3bcf
   6:     0x76318e6e5138 - std[1a5d30e1e0c007d8]::panicking::update_hook::<alloc[14385021349c12d]::boxed::Box<rustc_driver_impl[82473e392678a029]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x76318f590ff8 - std::panicking::rust_panic_with_hook::h4c5c19cf2bfcc665
   8:     0x76318e71aec1 - std[1a5d30e1e0c007d8]::panicking::begin_panic::<rustc_errors[45f849f7416f2b46]::ExplicitBug>::{closure#0}
   9:     0x76318e710066 - std[1a5d30e1e0c007d8]::sys::backtrace::__rust_end_short_backtrace::<std[1a5d30e1e0c007d8]::panicking::begin_panic<rustc_errors[45f849f7416f2b46]::ExplicitBug>::{closure#0}, !>
  10:     0x76318e70fe1f - std[1a5d30e1e0c007d8]::panicking::begin_panic::<rustc_errors[45f849f7416f2b46]::ExplicitBug>
  11:     0x76318e724e61 - <rustc_errors[45f849f7416f2b46]::diagnostic::BugAbort as rustc_errors[45f849f7416f2b46]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x76318ed1acd3 - rustc_middle[c13b89039089cda2]::util::bug::opt_span_bug_fmt::<rustc_span[23dbc7880e66e138]::span_encoding::Span>::{closure#0}
  13:     0x76318ed0069a - rustc_middle[c13b89039089cda2]::ty::context::tls::with_opt::<rustc_middle[c13b89039089cda2]::util::bug::opt_span_bug_fmt<rustc_span[23dbc7880e66e138]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x76318ed0052b - rustc_middle[c13b89039089cda2]::ty::context::tls::with_context_opt::<rustc_middle[c13b89039089cda2]::ty::context::tls::with_opt<rustc_middle[c13b89039089cda2]::util::bug::opt_span_bug_fmt<rustc_span[23dbc7880e66e138]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x76318cf1da20 - rustc_middle[c13b89039089cda2]::util::bug::bug_fmt
  16:     0x7631900b8c17 - rustc_query_impl[3a08df5daa2e46f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3a08df5daa2e46f1]::query_impl::local_def_id_to_hir_id::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c13b89039089cda2]::query::erase::Erased<[u8; 8usize]>>
  17:     0x7631900b84b6 - rustc_query_system[accb4f7494381bff]::query::plumbing::try_execute_query::<rustc_query_impl[3a08df5daa2e46f1]::DynamicConfig<rustc_data_structures[3d96f073365b50c5]::vec_cache::VecCache<rustc_span[23dbc7880e66e138]::def_id::LocalDefId, rustc_middle[c13b89039089cda2]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[accb4f7494381bff]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[3a08df5daa2e46f1]::plumbing::QueryCtxt, false>
  18:     0x7631900b7f0f - rustc_query_impl[3a08df5daa2e46f1]::query_impl::local_def_id_to_hir_id::get_query_non_incr::__rust_end_short_backtrace
  19:     0x76318fe564fa - <rustc_middle[c13b89039089cda2]::hir::provide::{closure#4} as core[11d5bfe1ac835d3b]::ops::function::FnOnce<(rustc_middle[c13b89039089cda2]::ty::context::TyCtxt, rustc_span[23dbc7880e66e138]::def_id::LocalDefId)>>::call_once
  20:     0x76318fe5573b - rustc_query_impl[3a08df5daa2e46f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3a08df5daa2e46f1]::query_impl::def_span::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c13b89039089cda2]::query::erase::Erased<[u8; 8usize]>>
  21:     0x76318fe53b5f - rustc_query_system[accb4f7494381bff]::query::plumbing::try_execute_query::<rustc_query_impl[3a08df5daa2e46f1]::DynamicConfig<rustc_query_system[accb4f7494381bff]::query::caches::DefIdCache<rustc_middle[c13b89039089cda2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3a08df5daa2e46f1]::plumbing::QueryCtxt, false>
  22:     0x76318fe537b1 - rustc_query_impl[3a08df5daa2e46f1]::query_impl::def_span::get_query_non_incr::__rust_end_short_backtrace
  23:     0x763190379cca - <rustc_metadata[241cef8911bf509e]::rmeta::encoder::EncodeContext>::encode_def_ids
  24:     0x763190b93b9f - <rustc_metadata[241cef8911bf509e]::rmeta::encoder::EncodeContext>::encode_crate_root
  25:     0x763190ec84d8 - rustc_metadata[241cef8911bf509e]::rmeta::encoder::encode_metadata
  26:     0x763190ecf4f6 - rustc_metadata[241cef8911bf509e]::fs::encode_and_write_metadata
  27:     0x763190ece33e - <rustc_interface[a99d718c7cf4de93]::queries::Linker>::codegen_and_build_linker
  28:     0x763190e7ef5d - rustc_interface[a99d718c7cf4de93]::interface::run_compiler::<(), rustc_driver_impl[82473e392678a029]::run_compiler::{closure#0}>::{closure#1}
  29:     0x763190dce9c7 - std[1a5d30e1e0c007d8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a99d718c7cf4de93]::util::run_in_thread_with_globals<rustc_interface[a99d718c7cf4de93]::util::run_in_thread_pool_with_globals<rustc_interface[a99d718c7cf4de93]::interface::run_compiler<(), rustc_driver_impl[82473e392678a029]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  30:     0x763190dce660 - <<std[1a5d30e1e0c007d8]::thread::Builder>::spawn_unchecked_<rustc_interface[a99d718c7cf4de93]::util::run_in_thread_with_globals<rustc_interface[a99d718c7cf4de93]::util::run_in_thread_pool_with_globals<rustc_interface[a99d718c7cf4de93]::interface::run_compiler<(), rustc_driver_impl[82473e392678a029]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[11d5bfe1ac835d3b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x763190dcda01 - std::sys::pal::unix::thread::Thread::new::thread_start::h25b199c02c59f5cc
  32:     0x76318aea339d - <unknown>
  33:     0x76318af2849c - <unknown>
  34:                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: rustc 1.85.0-nightly (f5079d00e 2024-12-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(impl_trait_in_bindings) --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [local_def_id_to_hir_id] getting HIR ID of `new::{opaque#0}`
#1 [def_span] looking up span for `new::{opaque#0}`
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@rustbot label +F-impl_trait_in_bindings

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 14, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` labels Dec 14, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: No HirId for DefId ICE: impl_trait_in_bindings: No HirId for DefId Dec 14, 2024
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Dec 14, 2024

mvce I think

#![crate_type="lib"]
#![feature(impl_trait_in_bindings)]
fn main() {
    let _: impl PartialEq = 0;
}

@fmease fmease added A-metadata Area: Crate metadata S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 14, 2024
@compiler-errors compiler-errors self-assigned this Dec 14, 2024
@bors bors closed this as completed in 81378c8 Dec 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 15, 2024
Rollup merge of rust-lang#134313 - compiler-errors:no-itib-def-id, r=oli-obk

Don't make a def id for `impl_trait_in_bindings`

The def collector is awkward, so for now just wrap let statements in a new `ImplTraitContext::InBinding` which tells `visit_ty` not to make a def id for the type. This will not generalize to other ITIB cases, like if we allow them in turbofishes (e.g. `foo::<impl Fn()>(|| {})`).

Fixes rust-lang#134307

r? oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-metadata Area: Crate metadata C-bug Category: This is a bug. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants