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: cannot convert to a region vid #135649

Closed
matthiaskrgr opened this issue Jan 17, 2025 · 2 comments · Fixed by #135711
Closed

ICE: cannot convert to a region vid #135649

matthiaskrgr opened this issue Jan 17, 2025 · 2 comments · Fixed by #135711
Assignees
Labels
C-bug Category: This is a bug. F-default_field_values `#![feature(default_field_values)]` 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.

Comments

@matthiaskrgr
Copy link
Member

snippet:

struct A<'a> {
    x: Vec<A> = Vec::new(),
}

Version information

rustc 1.86.0-nightly (bcd0683e5 2025-01-17)
binary: rustc
commit-hash: bcd0683e5dce1945b5d940714742e7502883bb5c
commit-date: 2025-01-17
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Possibly related line of code:

// errors are being emitted and 2) it leaves the happy path unaffected.
self.fr_static
} else {
*self
.indices
.get(&r)
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))
}
}
/// Replaces all free regions in `value` with region vids, as
/// returned by `to_region_vid`.
fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T

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

Program output

error[E0106]: missing lifetime specifier
 --> /tmp/icemaker_global_tempdir.65vzQ3rSPMlN/rustc_testrunner_tmpdir_reporting.9LgfFhJdaXkA/mvce.rs:2:12
  |
2 |     x: Vec<A> = Vec::new(),
  |            ^ expected named lifetime parameter
  |
help: consider using the `'a` lifetime
  |
2 |     x: Vec<A<'a>> = Vec::new(),
  |             ++++

error[E0658]: default values on fields are experimental
 --> /tmp/icemaker_global_tempdir.65vzQ3rSPMlN/rustc_testrunner_tmpdir_reporting.9LgfFhJdaXkA/mvce.rs:2:14
  |
2 |     x: Vec<A> = Vec::new(),
  |              ^^^^^^^^^^^^^
  |
  = note: see issue #132162 <https://github.com/rust-lang/rust/issues/132162> for more information
  = help: add `#![feature(default_field_values)]` to the crate attributes to enable
  = note: this compiler was built on 2025-01-17; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.65vzQ3rSPMlN/rustc_testrunner_tmpdir_reporting.9LgfFhJdaXkA/mvce.rs:3:2
  |
3 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.65vzQ3rSPMlN/rustc_testrunner_tmpdir_reporting.9LgfFhJdaXkA/mvce.rs`

error[E0392]: lifetime parameter `'a` is never used
 --> /tmp/icemaker_global_tempdir.65vzQ3rSPMlN/rustc_testrunner_tmpdir_reporting.9LgfFhJdaXkA/mvce.rs:1:10
  |
1 | struct A<'a> {
  |          ^^ unused lifetime parameter
  |
  = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:888:36: cannot convert `'a/#0` to a region vid


thread 'rustc' panicked at compiler/rustc_borrowck/src/universal_regions.rs:888:36:
Box<dyn Any>
stack backtrace:
   0:     0x730ea98f502a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4fb5b0de48364101
   1:     0x730eaa012d66 - core::fmt::write::h6eb54c31028066ca
   2:     0x730eaafa43d1 - std::io::Write::write_fmt::hd9e9dfb2c5e220cc
   3:     0x730ea98f4e82 - std::sys::backtrace::BacktraceLock::print::ha2ddb07494fe7b3b
   4:     0x730ea98f7302 - std::panicking::default_hook::{{closure}}::h4eed2bdbab3e3d9c
   5:     0x730ea98f718a - std::panicking::default_hook::h520b49f6397a0732
   6:     0x730ea8a58e1b - std[3244471bfd6eaa61]::panicking::update_hook::<alloc[8ba9d48c156baf43]::boxed::Box<rustc_driver_impl[df45097da6562dc6]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x730ea98f7e43 - std::panicking::rust_panic_with_hook::ha20255168d758ad1
   8:     0x730ea8a94761 - std[3244471bfd6eaa61]::panicking::begin_panic::<rustc_errors[af9a6eaf1dbd0244]::ExplicitBug>::{closure#0}
   9:     0x730ea8a89666 - std[3244471bfd6eaa61]::sys::backtrace::__rust_end_short_backtrace::<std[3244471bfd6eaa61]::panicking::begin_panic<rustc_errors[af9a6eaf1dbd0244]::ExplicitBug>::{closure#0}, !>
  10:     0x730ea8a89423 - std[3244471bfd6eaa61]::panicking::begin_panic::<rustc_errors[af9a6eaf1dbd0244]::ExplicitBug>
  11:     0x730ea8a9e691 - <rustc_errors[af9a6eaf1dbd0244]::diagnostic::BugAbort as rustc_errors[af9a6eaf1dbd0244]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x730ea907bc53 - rustc_middle[352907c3633efb2c]::util::bug::opt_span_bug_fmt::<rustc_span[2bc6ccfbd90abceb]::span_encoding::Span>::{closure#0}
  13:     0x730ea90615da - rustc_middle[352907c3633efb2c]::ty::context::tls::with_opt::<rustc_middle[352907c3633efb2c]::util::bug::opt_span_bug_fmt<rustc_span[2bc6ccfbd90abceb]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x730ea906146b - rustc_middle[352907c3633efb2c]::ty::context::tls::with_context_opt::<rustc_middle[352907c3633efb2c]::ty::context::tls::with_opt<rustc_middle[352907c3633efb2c]::util::bug::opt_span_bug_fmt<rustc_span[2bc6ccfbd90abceb]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x730ea6f596b0 - rustc_middle[352907c3633efb2c]::util::bug::bug_fmt
  16:     0x730eab54beb3 - <rustc_borrowck[55cebfbcecacd79c]::universal_regions::UniversalRegionIndices>::to_region_vid.cold
  17:     0x730eaa060745 - <rustc_middle[352907c3633efb2c]::ty::Ty as rustc_type_ir[ba8c709077c11182]::fold::TypeSuperFoldable<rustc_middle[352907c3633efb2c]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_type_ir[ba8c709077c11182]::fold::RegionFolder<rustc_middle[352907c3633efb2c]::ty::context::TyCtxt>>
  18:     0x730eaa05f068 - <rustc_middle[352907c3633efb2c]::ty::Ty as rustc_type_ir[ba8c709077c11182]::fold::TypeSuperFoldable<rustc_middle[352907c3633efb2c]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_type_ir[ba8c709077c11182]::fold::RegionFolder<rustc_middle[352907c3633efb2c]::ty::context::TyCtxt>>
  19:     0x730eab0c21f6 - rustc_borrowck[55cebfbcecacd79c]::do_mir_borrowck
  20:     0x730eab0bfbef - rustc_query_impl[43ade5033af9534a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43ade5033af9534a]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[352907c3633efb2c]::query::erase::Erased<[u8; 8usize]>>
  21:     0x730eaa33c04e - rustc_query_system[eb70713c06242342]::query::plumbing::try_execute_query::<rustc_query_impl[43ade5033af9534a]::DynamicConfig<rustc_data_structures[dc2c66faf0aa2c5f]::vec_cache::VecCache<rustc_span[2bc6ccfbd90abceb]::def_id::LocalDefId, rustc_middle[352907c3633efb2c]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[eb70713c06242342]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[43ade5033af9534a]::plumbing::QueryCtxt, false>
  22:     0x730eaa33bb53 - rustc_query_impl[43ade5033af9534a]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  23:     0x730eaa3309f0 - rustc_interface[508537c9f518ed83]::passes::run_required_analyses
  24:     0x730eaaf9fade - rustc_interface[508537c9f518ed83]::passes::analysis
  25:     0x730eaaf9faaf - rustc_query_impl[43ade5033af9534a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[43ade5033af9534a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[352907c3633efb2c]::query::erase::Erased<[u8; 0usize]>>
  26:     0x730eaaf5a9d5 - rustc_query_system[eb70713c06242342]::query::plumbing::try_execute_query::<rustc_query_impl[43ade5033af9534a]::DynamicConfig<rustc_query_system[eb70713c06242342]::query::caches::SingleCache<rustc_middle[352907c3633efb2c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[43ade5033af9534a]::plumbing::QueryCtxt, false>
  27:     0x730eaaf5a70e - rustc_query_impl[43ade5033af9534a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  28:     0x730eab0391e9 - rustc_interface[508537c9f518ed83]::passes::create_and_enter_global_ctxt::<core[24a92a8ec63ee5f4]::option::Option<rustc_interface[508537c9f518ed83]::queries::Linker>, rustc_driver_impl[df45097da6562dc6]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  29:     0x730eab02c416 - rustc_interface[508537c9f518ed83]::interface::run_compiler::<(), rustc_driver_impl[df45097da6562dc6]::run_compiler::{closure#0}>::{closure#1}
  30:     0x730eaae73a07 - std[3244471bfd6eaa61]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[508537c9f518ed83]::util::run_in_thread_with_globals<rustc_interface[508537c9f518ed83]::util::run_in_thread_pool_with_globals<rustc_interface[508537c9f518ed83]::interface::run_compiler<(), rustc_driver_impl[df45097da6562dc6]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  31:     0x730eaae736d9 - <<std[3244471bfd6eaa61]::thread::Builder>::spawn_unchecked_<rustc_interface[508537c9f518ed83]::util::run_in_thread_with_globals<rustc_interface[508537c9f518ed83]::util::run_in_thread_pool_with_globals<rustc_interface[508537c9f518ed83]::interface::run_compiler<(), rustc_driver_impl[df45097da6562dc6]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[24a92a8ec63ee5f4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x730eaae72e6f - std::sys::pal::unix::thread::Thread::new::thread_start::h5d259864ca2af1e4
  33:     0x730ea52a339d - <unknown>
  34:     0x730ea532849c - <unknown>
  35:                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/im2/rustc-ice-2025-01-17T19_45_25-2933219.txt` to your bug report

query stack during panic:
#0 [mir_borrowck] borrow-checking `A::x::{constant#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0106, E0392, E0601, E0658.
For more information about an error, try `rustc --explain E0106`.

@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 Jan 17, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 17, 2025
@matthiaskrgr
Copy link
Member Author

bisection points to #129514 cc @estebank

@estebank
Copy link
Contributor

Enable the #![feature(default_field_values)] and fn main() {} to reduce the number of errors. I think the error is because of the new const. I think we likely need to change the following code to account for default field value consts:

BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => {
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
if self.mir_def.to_def_id() == typeck_root_def_id {
let args =
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_args);
DefiningTy::Const(self.mir_def.to_def_id(), args)
} else {
// FIXME this line creates a dependency between borrowck and typeck.
//
// This is required for `AscribeUserType` canonical query, which will call
// `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes
// into borrowck, which is ICE #78174.
//
// As a workaround, inline consts have an additional generic param (`ty`
// below), so that `type_of(inline_const_def_id).args(args)` uses the
// proper type with NLL infer vars.
let ty = tcx
.typeck(self.mir_def)
.node_type(tcx.local_def_id_to_hir_id(self.mir_def));
let args = InlineConstArgs::new(tcx, InlineConstArgsParts {
parent_args: identity_args,
ty,
})
.args;
let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args);
DefiningTy::InlineConst(self.mir_def.to_def_id(), args)
}
}

@estebank estebank self-assigned this Jan 22, 2025
@clubby789 clubby789 removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 24, 2025
@fmease fmease added the F-default_field_values `#![feature(default_field_values)]` label Feb 16, 2025
@fmease fmease marked this as a duplicate of #137136 Feb 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 18, 2025
Do not ICE on default_field_value const with lifetimes

`#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in rust-lang#78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck.

Fix rust-lang#135649.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 18, 2025
Do not ICE on default_field_value const with lifetimes

`#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in rust-lang#78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck.

Fix rust-lang#135649.
@bors bors closed this as completed in 08ee5f5 Feb 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 19, 2025
Rollup merge of rust-lang#135711 - estebank:issue-135649, r=davidtwco

Do not ICE on default_field_value const with lifetimes

`#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in rust-lang#78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck.

Fix rust-lang#135649.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-default_field_values `#![feature(default_field_values)]` 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants