Skip to content

Const generic default ICE: The type checker should prevent reading from a never-written local #93646

Closed
@DutchGhost

Description

@DutchGhost

Const generic defaults are being stabilized, #90207. But I found an issue that occured earlier in the length expressions of arrays, see #72115

Code

struct X<const N: usize = {
    let s: &str; s.len()
}>;

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (4e8fb743c 2022-02-03)

Error output

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:202:17: The type checker should prevent reading from a never-written local

Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1160:9
stack backtrace:
   0:     0x7fd976ea7ebc - std::backtrace_rs::backtrace::libunwind::trace::hddd5a7e459ce4327
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fd976ea7ebc - std::backtrace_rs::backtrace::trace_unsynchronized::h69db3e09cfd8bf11
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd976ea7ebc - std::sys_common::backtrace::_print_fmt::h83b461b46804fdab
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fd976ea7ebc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2f6e5cd8872f3d74
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fd976f092dc - core::fmt::write::hd64a00f3787c90bd
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/core/src/fmt/mod.rs:1190:17
   5:     0x7fd976e97383 - std::io::Write::write_fmt::h6347402c88d40325
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/io/mod.rs:1653:15
   6:     0x7fd976eac181 - std::sys_common::backtrace::_print::h989064c3e0b39e3c
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fd976eac181 - std::sys_common::backtrace::print::h4af8c55ce731a045
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fd976eac181 - std::panicking::default_hook::{{closure}}::h41ef6f6a9fac6b53
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/panicking.rs:295:22
   9:     0x7fd976eabe3f - std::panicking::default_hook::hbaf11e031e0e4a5f
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/panicking.rs:314:9
  10:     0x7fd977689541 - rustc_driver[7b59b981d4c23d31]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fd976eaca5b - std::panicking::rust_panic_with_hook::h4788f0bd625b1005
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/panicking.rs:702:17
  12:     0x7fd97874d281 - std[daefdbcf0dca51d0]::panicking::begin_panic::<rustc_errors[b77837aed2b0d3e7]::ExplicitBug>::{closure#0}
  13:     0x7fd97874d1f6 - std[daefdbcf0dca51d0]::sys_common::backtrace::__rust_end_short_backtrace::<std[daefdbcf0dca51d0]::panicking::begin_panic<rustc_errors[b77837aed2b0d3e7]::ExplicitBug>::{closure#0}, !>
  14:     0x7fd978751a2f - std[daefdbcf0dca51d0]::panicking::begin_panic::<rustc_errors[b77837aed2b0d3e7]::ExplicitBug>
  15:     0x7fd97875e0cd - std[daefdbcf0dca51d0]::panic::panic_any::<rustc_errors[b77837aed2b0d3e7]::ExplicitBug>
  16:     0x7fd97875d37d - <rustc_errors[b77837aed2b0d3e7]::HandlerInner>::bug
  17:     0x7fd97875ced0 - <rustc_errors[b77837aed2b0d3e7]::Handler>::bug
  18:     0x7fd9785e36d9 - rustc_middle[e664fb30aec2b69e]::ty::context::tls::with_opt::<rustc_middle[e664fb30aec2b69e]::util::bug::opt_span_bug_fmt<rustc_span[26d1c5a8904e1196]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7fd9785e4830 - rustc_middle[e664fb30aec2b69e]::util::bug::opt_span_bug_fmt::<rustc_span[26d1c5a8904e1196]::span_encoding::Span>
  20:     0x7fd9785e47a6 - rustc_middle[e664fb30aec2b69e]::util::bug::bug_fmt
  21:     0x7fd978e7fcf6 - <rustc_const_eval[55e19033940159c7]::interpret::eval_context::InterpCx<rustc_const_eval[55e19033940159c7]::const_eval::machine::CompileTimeInterpreter>>::run
  22:     0x7fd978ebed71 - rustc_const_eval[55e19033940159c7]::const_eval::eval_queries::eval_to_allocation_raw_provider
  23:     0x7fd978f40a9c - rustc_query_system[59fab566a51c2c24]::query::plumbing::try_execute_query::<rustc_query_impl[ae50953882263c5d]::plumbing::QueryCtxt, rustc_query_system[59fab566a51c2c24]::query::caches::DefaultCache<rustc_middle[e664fb30aec2b69e]::ty::ParamEnvAnd<rustc_middle[e664fb30aec2b69e]::mir::interpret::GlobalId>, core[90c82cfbe27f5d33]::result::Result<rustc_middle[e664fb30aec2b69e]::mir::interpret::value::ConstAlloc, rustc_middle[e664fb30aec2b69e]::mir::interpret::error::ErrorHandled>>>
  24:     0x7fd978fb1ebf - <rustc_query_impl[ae50953882263c5d]::Queries as rustc_middle[e664fb30aec2b69e]::ty::query::QueryEngine>::eval_to_allocation_raw
  25:     0x7fd978ebd9b2 - rustc_const_eval[55e19033940159c7]::const_eval::eval_queries::eval_to_const_value_raw_provider
  26:     0x7fd978f4194b - rustc_query_system[59fab566a51c2c24]::query::plumbing::try_execute_query::<rustc_query_impl[ae50953882263c5d]::plumbing::QueryCtxt, rustc_query_system[59fab566a51c2c24]::query::caches::DefaultCache<rustc_middle[e664fb30aec2b69e]::ty::ParamEnvAnd<rustc_middle[e664fb30aec2b69e]::mir::interpret::GlobalId>, core[90c82cfbe27f5d33]::result::Result<rustc_middle[e664fb30aec2b69e]::mir::interpret::value::ConstValue, rustc_middle[e664fb30aec2b69e]::mir::interpret::error::ErrorHandled>>>
  27:     0x7fd978fb207b - <rustc_query_impl[ae50953882263c5d]::Queries as rustc_middle[e664fb30aec2b69e]::ty::query::QueryEngine>::eval_to_const_value_raw
  28:     0x7fd9793b9b4a - <rustc_middle[e664fb30aec2b69e]::ty::context::TyCtxt>::const_eval_global_id
  29:     0x7fd979d3fa49 - <rustc_middle[e664fb30aec2b69e]::ty::context::TyCtxt>::const_eval_resolve
  30:     0x7fd979ce2391 - <rustc_infer[835d7697e80d8145]::infer::InferCtxt>::const_eval_resolve
  31:     0x7fd979cb6659 - rustc_trait_selection[99ac7681cfb15a86]::traits::const_evaluatable::is_const_evaluatable
  32:     0x7fd9792a1679 - <rustc_trait_selection[99ac7681cfb15a86]::traits::fulfill::FulfillProcessor>::progress_changed_obligations
  33:     0x7fd9792aa834 - <rustc_data_structures[9901de6203b925f4]::obligation_forest::ObligationForest<rustc_trait_selection[99ac7681cfb15a86]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[99ac7681cfb15a86]::traits::fulfill::FulfillProcessor, rustc_data_structures[9901de6203b925f4]::obligation_forest::Outcome<rustc_trait_selection[99ac7681cfb15a86]::traits::fulfill::PendingPredicateObligation, rustc_infer[835d7697e80d8145]::traits::FulfillmentErrorCode>>
  34:     0x7fd97929d198 - <rustc_trait_selection[99ac7681cfb15a86]::traits::fulfill::FulfillmentContext as rustc_infer[835d7697e80d8145]::traits::engine::TraitEngine>::select_all_or_error
  35:     0x7fd978a5eda5 - <rustc_typeck[95242508bb98a5fb]::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  36:     0x7fd979796ba7 - <rustc_infer[835d7697e80d8145]::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck[95242508bb98a5fb]::check::inherited::InheritedBuilder>::enter<<rustc_typeck[95242508bb98a5fb]::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck[95242508bb98a5fb]::check::wfcheck::check_type_defn<rustc_typeck[95242508bb98a5fb]::check::wfcheck::check_item_well_formed::{closure#2}>::{closure#0}>::{closure#0}, ()>::{closure#0}>
  37:     0x7fd978b2caae - rustc_typeck[95242508bb98a5fb]::check::wfcheck::check_item_well_formed
  38:     0x7fd978f55d9e - rustc_query_system[59fab566a51c2c24]::query::plumbing::try_execute_query::<rustc_query_impl[ae50953882263c5d]::plumbing::QueryCtxt, rustc_query_system[59fab566a51c2c24]::query::caches::DefaultCache<rustc_span[26d1c5a8904e1196]::def_id::LocalDefId, ()>>
  39:     0x7fd978fb7ee5 - <rustc_query_impl[ae50953882263c5d]::Queries as rustc_middle[e664fb30aec2b69e]::ty::query::QueryEngine>::check_item_well_formed
  40:     0x7fd978af6b74 - <rustc_middle[e664fb30aec2b69e]::hir::map::Map>::par_visit_all_item_likes::<rustc_typeck[95242508bb98a5fb]::check::wfcheck::CheckTypeWellFormedVisitor>
  41:     0x7fd97978b21c - <rustc_session[bcbf86d149cb5e94]::session::Session>::track_errors::<rustc_typeck[95242508bb98a5fb]::check_crate::{closure#5}, ()>
  42:     0x7fd9797707cb - rustc_typeck[95242508bb98a5fb]::check_crate
  43:     0x7fd979523287 - rustc_interface[be440f50dcda62f9]::passes::analysis
  44:     0x7fd9799bb729 - rustc_query_system[59fab566a51c2c24]::query::plumbing::try_execute_query::<rustc_query_impl[ae50953882263c5d]::plumbing::QueryCtxt, rustc_query_system[59fab566a51c2c24]::query::caches::DefaultCache<(), core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>>
  45:     0x7fd9799f98a5 - rustc_query_system[59fab566a51c2c24]::query::plumbing::get_query::<rustc_query_impl[ae50953882263c5d]::queries::analysis, rustc_query_impl[ae50953882263c5d]::plumbing::QueryCtxt>
  46:     0x7fd9794f980d - <rustc_interface[be440f50dcda62f9]::passes::QueryContext>::enter::<rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>
  47:     0x7fd9794f781a - <rustc_interface[be440f50dcda62f9]::interface::Compiler>::enter::<rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}::{closure#2}, core[90c82cfbe27f5d33]::result::Result<core[90c82cfbe27f5d33]::option::Option<rustc_interface[be440f50dcda62f9]::queries::Linker>, rustc_errors[b77837aed2b0d3e7]::ErrorReported>>
  48:     0x7fd9794fa876 - rustc_span[26d1c5a8904e1196]::with_source_map::<core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>, rustc_interface[be440f50dcda62f9]::interface::create_compiler_and_run<core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>, rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}>::{closure#1}>
  49:     0x7fd9794f71fe - rustc_interface[be440f50dcda62f9]::interface::create_compiler_and_run::<core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>, rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}>
  50:     0x7fd9794dd302 - std[daefdbcf0dca51d0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[be440f50dcda62f9]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[be440f50dcda62f9]::interface::run_compiler<core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>, rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}>::{closure#0}, core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>::{closure#0}, core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>
  51:     0x7fd9794daa19 - <<std[daefdbcf0dca51d0]::thread::Builder>::spawn_unchecked_<rustc_interface[be440f50dcda62f9]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[be440f50dcda62f9]::interface::run_compiler<core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>, rustc_driver[7b59b981d4c23d31]::run_compiler::{closure#1}>::{closure#0}, core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>::{closure#0}, core[90c82cfbe27f5d33]::result::Result<(), rustc_errors[b77837aed2b0d3e7]::ErrorReported>>::{closure#1} as core[90c82cfbe27f5d33]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x7fd976eb8803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hed49a6c6e767ba83
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/alloc/src/boxed.rs:1854:9
  53:     0x7fd976eb8803 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h14238373d01dc9bc
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/alloc/src/boxed.rs:1854:9
  54:     0x7fd976eb8803 - std::sys::unix::thread::Thread::new::thread_start::hc6dbf73cd24f68cc
                               at /rustc/4e8fb743ccbec27344b2dd42de7057f41d4ebfdd/library/std/src/sys/unix/thread.rs:108:17
  55:     0x7fd976dec609 - start_thread
  56:     0x7fd976d06293 - clone
  57:                0x0 - <unknown>

Metadata

Metadata

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.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.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions