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: sty: called Option::unwrap() on a None value #137896

Closed
matthiaskrgr opened this issue Mar 2, 2025 · 3 comments · Fixed by #137913
Closed

ICE: sty: called Option::unwrap() on a None value #137896

matthiaskrgr opened this issue Mar 2, 2025 · 3 comments · Fixed by #137913
Assignees
Labels
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.

Comments

@matthiaskrgr
Copy link
Member

snippet:

struct A<const X: usize> {
    x: Vec<&'pin mut Self> = Vec::new(),
}

Version information

rustc 1.87.0-nightly (7c4a55c2a 2025-03-02)
binary: rustc
commit-hash: 7c4a55c2ac6497629c273ccd00e185583542f0d2
commit-date: 2025-03-02
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

}
}
_ => None,
}
});
let ty = candidates.next().unwrap();
assert!(candidates.next().is_none());
ty
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2 -Clink-dead-code=true -Zvalidate-mir --edition=2024

Program output

error[E0261]: use of undeclared lifetime name `'pin`
 --> /tmp/icemaker_global_tempdir.M9ihYdd57QVg/rustc_testrunner_tmpdir_reporting.ySMuC7g3iyRl/mvce.rs:2:13
  |
1 | struct A<const X: usize> {
  |          - help: consider introducing lifetime `'pin` here: `'pin,`
2 |     x: Vec<&'pin mut Self> = Vec::new(),
  |             ^^^^ undeclared lifetime

error[E0658]: default values on fields are experimental
 --> /tmp/icemaker_global_tempdir.M9ihYdd57QVg/rustc_testrunner_tmpdir_reporting.ySMuC7g3iyRl/mvce.rs:2:27
  |
2 |     x: Vec<&'pin mut Self> = 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-03-02; consider upgrading it if it is out of date

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


thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:362:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7327865bef14 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc495f1899fa849d6
   1:     0x732786e057e2 - core::fmt::write::h39ac2b6780eacb0b
   2:     0x7327881e5291 - std::io::Write::write_fmt::hce3ca50e4f9c3d70
   3:     0x7327865bed72 - std::sys::backtrace::BacktraceLock::print::h6721b52240ac06b8
   4:     0x7327865c1652 - std::panicking::default_hook::{{closure}}::h7fd0541ed74fb3ce
   5:     0x7327865c1244 - std::panicking::default_hook::hccc7d640d5ba2811
   6:     0x732785718a87 - std[673d9073d68e8c5f]::panicking::update_hook::<alloc[956ce29f8aa768f9]::boxed::Box<rustc_driver_impl[6af4072765422930]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7327865c1ec3 - std::panicking::rust_panic_with_hook::h0da458b51069d3a7
   8:     0x7327865c1b86 - std::panicking::begin_panic_handler::{{closure}}::ha16ec4ccc9cec913
   9:     0x7327865bf3d9 - std::sys::backtrace::__rust_end_short_backtrace::h2aacb06ecfcbe368
  10:     0x7327865c187d - rust_begin_unwind
  11:     0x73278325b930 - core::panicking::panic_fmt::h41765f7bbf5784a9
  12:     0x732783cbc44c - core::panicking::panic::h9beefec10d0ae431
  13:     0x732783ac04b9 - core::option::unwrap_failed::haed1e72e8d3dc5a5
  14:     0x732788a33f66 - <rustc_middle[149f66fe1de159a6]::ty::sty::ParamConst>::find_ty_from_env.cold
  15:     0x7327876e14fb - <rustc_trait_selection[7cd3b6c2e2dd783b]::traits::fulfill::FulfillProcessor as rustc_data_structures[c5d5d3efdb2e4cc2]::obligation_forest::ObligationProcessor>::process_obligation
  16:     0x732786e074e9 - <rustc_data_structures[c5d5d3efdb2e4cc2]::obligation_forest::ObligationForest<rustc_trait_selection[7cd3b6c2e2dd783b]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[7cd3b6c2e2dd783b]::traits::fulfill::FulfillProcessor>
  17:     0x73278793f523 - <rustc_hir_typeck[22905d68007d48b0]::fn_ctxt::FnCtxt>::check_expr_path
  18:     0x732787c4ccca - <rustc_hir_typeck[22905d68007d48b0]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  19:     0x732787c4e80b - <rustc_hir_typeck[22905d68007d48b0]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  20:     0x7327871395f5 - <rustc_hir_typeck[22905d68007d48b0]::fn_ctxt::FnCtxt>::check_expr_coercible_to_type
  21:     0x73278720b161 - rustc_hir_typeck[22905d68007d48b0]::typeck_with_inspect::{closure#0}
  22:     0x732787207fb0 - rustc_query_impl[ad7e806203de0335]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ad7e806203de0335]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7327871fe9c8 - rustc_query_system[30512ec7f96497de]::query::plumbing::try_execute_query::<rustc_query_impl[ad7e806203de0335]::DynamicConfig<rustc_data_structures[c5d5d3efdb2e4cc2]::vec_cache::VecCache<rustc_span[8b0dd42cecff55ed]::def_id::LocalDefId, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[30512ec7f96497de]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ad7e806203de0335]::plumbing::QueryCtxt, true>
  24:     0x7327871fb107 - rustc_query_impl[ad7e806203de0335]::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  25:     0x7327871fce81 - rustc_query_impl[ad7e806203de0335]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ad7e806203de0335]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7327871fe9c8 - rustc_query_system[30512ec7f96497de]::query::plumbing::try_execute_query::<rustc_query_impl[ad7e806203de0335]::DynamicConfig<rustc_data_structures[c5d5d3efdb2e4cc2]::vec_cache::VecCache<rustc_span[8b0dd42cecff55ed]::def_id::LocalDefId, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[30512ec7f96497de]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[ad7e806203de0335]::plumbing::QueryCtxt, true>
  27:     0x73278701b178 - rustc_query_impl[ad7e806203de0335]::query_impl::used_trait_imports::get_query_incr::__rust_end_short_backtrace
  28:     0x732787660594 - rustc_middle[149f66fe1de159a6]::query::plumbing::query_get_at::<rustc_data_structures[c5d5d3efdb2e4cc2]::vec_cache::VecCache<rustc_span[8b0dd42cecff55ed]::def_id::LocalDefId, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[30512ec7f96497de]::dep_graph::graph::DepNodeIndex>>
  29:     0x73278765fcad - rustc_hir_analysis[21d9bf831ff42857]::check_unused::check_unused_traits
  30:     0x73278765fa07 - rustc_query_impl[ad7e806203de0335]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ad7e806203de0335]::query_impl::check_unused_traits::dynamic_query::{closure#2}::{closure#0}, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 0usize]>>
  31:     0x732787ebda1f - rustc_query_system[30512ec7f96497de]::query::plumbing::try_execute_query::<rustc_query_impl[ad7e806203de0335]::DynamicConfig<rustc_query_system[30512ec7f96497de]::query::caches::SingleCache<rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ad7e806203de0335]::plumbing::QueryCtxt, true>
  32:     0x732787ebcd8c - rustc_query_impl[ad7e806203de0335]::query_impl::check_unused_traits::get_query_incr::__rust_end_short_backtrace
  33:     0x7327871fa2b7 - rustc_hir_analysis[21d9bf831ff42857]::check_crate
  34:     0x7327871f3c9c - rustc_interface[d8c24ebf2384fa83]::passes::run_required_analyses
  35:     0x732787d3efba - rustc_interface[d8c24ebf2384fa83]::passes::analysis
  36:     0x732787d3ef99 - rustc_query_impl[ad7e806203de0335]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ad7e806203de0335]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 0usize]>>
  37:     0x732787ebd8aa - rustc_query_system[30512ec7f96497de]::query::plumbing::try_execute_query::<rustc_query_impl[ad7e806203de0335]::DynamicConfig<rustc_query_system[30512ec7f96497de]::query::caches::SingleCache<rustc_middle[149f66fe1de159a6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ad7e806203de0335]::plumbing::QueryCtxt, true>
  38:     0x732787ebd2a2 - rustc_query_impl[ad7e806203de0335]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  39:     0x732787d72efd - rustc_interface[d8c24ebf2384fa83]::passes::create_and_enter_global_ctxt::<core[fd72b707659d9093]::option::Option<rustc_interface[d8c24ebf2384fa83]::queries::Linker>, rustc_driver_impl[6af4072765422930]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  40:     0x732787f11220 - rustc_interface[d8c24ebf2384fa83]::interface::run_compiler::<(), rustc_driver_impl[6af4072765422930]::run_compiler::{closure#0}>::{closure#1}
  41:     0x732787d53cc8 - std[673d9073d68e8c5f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d8c24ebf2384fa83]::util::run_in_thread_with_globals<rustc_interface[d8c24ebf2384fa83]::util::run_in_thread_pool_with_globals<rustc_interface[d8c24ebf2384fa83]::interface::run_compiler<(), rustc_driver_impl[6af4072765422930]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  42:     0x732787d545b4 - <<std[673d9073d68e8c5f]::thread::Builder>::spawn_unchecked_<rustc_interface[d8c24ebf2384fa83]::util::run_in_thread_with_globals<rustc_interface[d8c24ebf2384fa83]::util::run_in_thread_pool_with_globals<rustc_interface[d8c24ebf2384fa83]::interface::run_compiler<(), rustc_driver_impl[6af4072765422930]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[fd72b707659d9093]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x732787d559b7 - std::sys::pal::unix::thread::Thread::new::thread_start::hb86ea38ca4860a5f
  44:     0x732781ea370a - <unknown>
  45:     0x732781f27aac - <unknown>
  46:                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: rustc 1.87.0-nightly (7c4a55c2a 2025-03-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 -C link-dead-code=true -Z validate-mir

query stack during panic:
#0 [typeck] type-checking `A::x::{constant#0}`
#1 [used_trait_imports] finding used_trait_imports `A::x::{constant#0}`
#2 [check_unused_traits] checking unused trait imports in crate
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

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

bisects to #129514

@cyrgani
Copy link
Contributor

cyrgani commented Mar 2, 2025

struct A<const X: usize> {
    x: Vec<Self> = Vec::new(),
}

@compiler-errors
Copy link
Member

compiler-errors commented Mar 3, 2025

Less dependent on libstd:

use std::marker::PhantomData;

struct W<T>(PhantomData<T>);

impl<T> W<T> {
    const fn new() -> Self { W(PhantomData) }
}

struct Z<const X: usize> {
    x: W<Self> = W::new(),
}

@compiler-errors compiler-errors self-assigned this Mar 3, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 4, 2025
…lt-generic, r=BoxyUwU

Allow struct field default values to reference struct's generics

Right now, the default field value feature (rust-lang#132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit.

This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly.

There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do.

r? `@boxyuwu` or reassign

I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted.

Fixes rust-lang#137896
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 4, 2025
…lt-generic, r=BoxyUwU

Allow struct field default values to reference struct's generics

Right now, the default field value feature (rust-lang#132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit.

This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly.

There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do.

r? ``@boxyuwu`` or reassign

I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted.

Fixes rust-lang#137896
tgross35 added a commit to tgross35/rust that referenced this issue Mar 4, 2025
…lt-generic, r=BoxyUwU

Allow struct field default values to reference struct's generics

Right now, the default field value feature (rust-lang#132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit.

This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly.

There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do.

r? ```@boxyuwu``` or reassign

I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted.

Fixes rust-lang#137896
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 4, 2025
…lt-generic, r=BoxyUwU

Allow struct field default values to reference struct's generics

Right now, the default field value feature (rust-lang#132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit.

This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly.

There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do.

r? ````@boxyuwu```` or reassign

I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted.

Fixes rust-lang#137896
@bors bors closed this as completed in b3d7c14 Mar 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 5, 2025
Rollup merge of rust-lang#137913 - compiler-errors:struct-field-default-generic, r=BoxyUwU

Allow struct field default values to reference struct's generics

Right now, the default field value feature (rust-lang#132162) lowers anon consts whose types may reference ADT params that the const doesn't inherit.

This PR fixes this, so that these defaults can reference ADTs' generics, and sets the `generics_of` parenting up correctly.

There doesn't seem to be a good reason not to support this, since the anon const has a well-defined type from the field, and the anon const doesn't interact with the type system like generic parameter defaults do.

r? `````@boxyuwu````` or reassign

I could also make this into an error if this seems problematic (https://github.com/rust-lang/rust/compare/master...compiler-errors:rust:default-field-value-implicit-param?expand=1)...... but I'd rather make this work and register an open question on the tracking issue about validating that this is well-vetted.

Fixes rust-lang#137896
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 12, 2025
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. 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