Skip to content

ICE error when matching uninitialized constant with constant pattern in Rust #115599

Closed
@iamanonymouscs

Description

@iamanonymouscs

Code

const CONST_STRING: String = String::new();
fn main() {
    //code
    let empty_str=String::from("");
    if let CONST_STRING = empty_str {
    //code
    }
}

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (a991861ec 2023-09-05)
binary: rustc
commit-hash: a991861ec9fd8aedffbe5744a8852c7c64dd40b2
commit-date: 2023-09-05
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

This bug was also reproduced in the stable version(1.72)

Error output

warning: to use a constant of type `Vec<u8>` in a pattern, `Vec<u8>` must be annotated with `#[derive(PartialEq, Eq)]`
 --> bug.rs:5:12
  |
5 |     if let CONST_STRING = empty_str {
  |            ^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
  = note: the traits must be derived, manual `impl`s are not sufficient
  = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
  = note: `#[warn(indirect_structural_match)]` on by default
Backtrace

error: internal compiler error: compiler/rustc_mir_build/src/build/matches/test.rs:244:25: matching on `String` went through without enabling string_deref_patterns

thread 'rustc' panicked at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/compiler/rustc_errors/src/lib.rs:1651:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f53ffd3cbec - std::backtrace_rs::backtrace::libunwind::trace::h1298100820b00e42
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f53ffd3cbec - std::backtrace_rs::backtrace::trace_unsynchronized::h25ae9be29b50d68d
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f53ffd3cbec - std::sys_common::backtrace::_print_fmt::hb0a122c02a9e329f
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f53ffd3cbec - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0785508acad78739
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f53ffda2dfc - core::fmt::rt::Argument::fmt::h367a8235fd3b8ec9
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/core/src/fmt/rt.rs:138:9
   5:     0x7f53ffda2dfc - core::fmt::write::haf0f122656cf716d
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f53ffd2f71e - std::io::Write::write_fmt::h81969da61711600d
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/io/mod.rs:1714:15
   7:     0x7f53ffd3c9d4 - std::sys_common::backtrace::_print::h00e5c4a2e9966b17
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f53ffd3c9d4 - std::sys_common::backtrace::print::hbf7a0e8e19400072
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f53ffd3faca - std::panicking::panic_hook_with_disk_dump::{{closure}}::h27904b15b8804b04
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/panicking.rs:280:22
  10:     0x7f53ffd3f7c5 - std::panicking::panic_hook_with_disk_dump::h0a17a9fc902df4ec
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/panicking.rs:314:9
  11:     0x7f5402ef56d9 - rustc_driver_impl[421f961c2abd6a6c]::install_ice_hook::{closure#0}
  12:     0x7f53ffd40383 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he211df56096a7722
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/alloc/src/boxed.rs:2021:9
  13:     0x7f53ffd40383 - std::panicking::rust_panic_with_hook::h2ec7fb05ba41ff26
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/panicking.rs:757:13
  14:     0x7f540349dac4 - std[2ba0c775535575e]::panicking::begin_panic::<rustc_errors[186b26c5db3132b8]::ExplicitBug>::{closure#0}
  15:     0x7f540349cc56 - std[2ba0c775535575e]::sys_common::backtrace::__rust_end_short_backtrace::<std[2ba0c775535575e]::panicking::begin_panic<rustc_errors[186b26c5db3132b8]::ExplicitBug>::{closure#0}, !>
  16:     0x7f54033f4676 - std[2ba0c775535575e]::panicking::begin_panic::<rustc_errors[186b26c5db3132b8]::ExplicitBug>
  17:     0x7f540347f634 - <rustc_errors[186b26c5db3132b8]::HandlerInner>::bug::<alloc[143706f611eb5894]::string::String>
  18:     0x7f540347f4a6 - <rustc_errors[186b26c5db3132b8]::Handler>::bug::<alloc[143706f611eb5894]::string::String>
  19:     0x7f54034a2f2c - rustc_middle[7266ccbfd6f08af0]::util::bug::opt_span_bug_fmt::<rustc_span[e182e80647a6f439]::span_encoding::Span>::{closure#0}
  20:     0x7f54034a0a6a - rustc_middle[7266ccbfd6f08af0]::ty::context::tls::with_opt::<rustc_middle[7266ccbfd6f08af0]::util::bug::opt_span_bug_fmt<rustc_span[e182e80647a6f439]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f54034a0a38 - rustc_middle[7266ccbfd6f08af0]::ty::context::tls::with_context_opt::<rustc_middle[7266ccbfd6f08af0]::ty::context::tls::with_opt<rustc_middle[7266ccbfd6f08af0]::util::bug::opt_span_bug_fmt<rustc_span[e182e80647a6f439]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f54019968a0 - rustc_middle[7266ccbfd6f08af0]::util::bug::bug_fmt
  23:     0x7f54020ffb6c - <rustc_mir_build[442994af0620fa82]::build::Builder>::match_simplified_candidates
  24:     0x7f54021057ff - <rustc_mir_build[442994af0620fa82]::build::Builder>::match_candidates
  25:     0x7f540138ad37 - <rustc_mir_build[442994af0620fa82]::build::Builder>::lower_match_tree
  26:     0x7f54013a32b9 - <rustc_mir_build[442994af0620fa82]::build::Builder>::lower_let_expr
  27:     0x7f54013944fd - <rustc_mir_build[442994af0620fa82]::build::Builder>::then_else_break
  28:     0x7f54013935c9 - <rustc_mir_build[442994af0620fa82]::build::Builder>::then_else_break
  29:     0x7f540136917a - <rustc_mir_build[442994af0620fa82]::build::Builder>::expr_into_dest
  30:     0x7f5401368722 - <rustc_mir_build[442994af0620fa82]::build::Builder>::expr_into_dest
  31:     0x7f5401398762 - <rustc_mir_build[442994af0620fa82]::build::Builder>::ast_block_stmts
  32:     0x7f540138b568 - <rustc_mir_build[442994af0620fa82]::build::Builder>::ast_block
  33:     0x7f54013668a6 - <rustc_mir_build[442994af0620fa82]::build::Builder>::expr_into_dest
  34:     0x7f5401368722 - <rustc_mir_build[442994af0620fa82]::build::Builder>::expr_into_dest
  35:     0x7f5401368722 - <rustc_mir_build[442994af0620fa82]::build::Builder>::expr_into_dest
  36:     0x7f5401eda8a7 - rustc_mir_build[442994af0620fa82]::build::mir_built
  37:     0x7f5400fff97c - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7f5400fff95e - <rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_built::dynamic_query::{closure#2} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<(rustc_middle[7266ccbfd6f08af0]::ty::context::TyCtxt, rustc_span[e182e80647a6f439]::def_id::LocalDefId)>>::call_once
  39:     0x7f54010fa498 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::VecCache<rustc_span[e182e80647a6f439]::def_id::LocalDefId, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  40:     0x7f5402889531 - rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7f54021744e9 - rustc_mir_transform[ebf36c8e57c3f18]::check_unsafety::unsafety_check_result
  42:     0x7f5400fff9bc - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::unsafety_check_result::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7f5400fff99e - <rustc_query_impl[e4e476eeb45651d1]::query_impl::unsafety_check_result::dynamic_query::{closure#2} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<(rustc_middle[7266ccbfd6f08af0]::ty::context::TyCtxt, rustc_span[e182e80647a6f439]::def_id::LocalDefId)>>::call_once
  44:     0x7f54010fa498 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::VecCache<rustc_span[e182e80647a6f439]::def_id::LocalDefId, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  45:     0x7f540288fea1 - rustc_query_impl[e4e476eeb45651d1]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7f5402258cea - rustc_mir_transform[ebf36c8e57c3f18]::mir_const
  47:     0x7f540102d4be - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>
  48:     0x7f540102d48e - <rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_const::dynamic_query::{closure#2} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<(rustc_middle[7266ccbfd6f08af0]::ty::context::TyCtxt, rustc_span[e182e80647a6f439]::def_id::LocalDefId)>>::call_once
  49:     0x7f54010fa498 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::VecCache<rustc_span[e182e80647a6f439]::def_id::LocalDefId, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  50:     0x7f54028898a1 - rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7f5401211a7b - rustc_mir_transform[ebf36c8e57c3f18]::mir_promoted
  52:     0x7f5400fff631 - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 16usize]>>
  53:     0x7f54015ce0e2 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::VecCache<rustc_span[e182e80647a6f439]::def_id::LocalDefId, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  54:     0x7f540288a274 - rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7f5401c9ac83 - rustc_borrowck[b34d41cd82b04a8d]::mir_borrowck
  56:     0x7f540102d45e - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>
  57:     0x7f540102d42e - <rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_borrowck::dynamic_query::{closure#2} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<(rustc_middle[7266ccbfd6f08af0]::ty::context::TyCtxt, rustc_span[e182e80647a6f439]::def_id::LocalDefId)>>::call_once
  58:     0x7f54010fa498 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::VecCache<rustc_span[e182e80647a6f439]::def_id::LocalDefId, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  59:     0x7f5402893b71 - rustc_query_impl[e4e476eeb45651d1]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  60:     0x7f540235a385 - rustc_data_structures[4483c8f9b2693f2d]::sync::par_for_each_in::<&[rustc_span[e182e80647a6f439]::def_id::LocalDefId], <rustc_middle[7266ccbfd6f08af0]::hir::map::Map>::par_body_owners<rustc_interface[e402a4e95d47e40d]::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  61:     0x7f540235a0bc - <rustc_session[a813519ed55dc798]::session::Session>::time::<(), rustc_interface[e402a4e95d47e40d]::passes::analysis::{closure#1}>
  62:     0x7f5402359519 - rustc_interface[e402a4e95d47e40d]::passes::analysis
  63:     0x7f540237d5ea - rustc_query_impl[e4e476eeb45651d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4e476eeb45651d1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 1usize]>>
  64:     0x7f540237d5d9 - <rustc_query_impl[e4e476eeb45651d1]::query_impl::analysis::dynamic_query::{closure#2} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<(rustc_middle[7266ccbfd6f08af0]::ty::context::TyCtxt, ())>>::call_once
  65:     0x7f540263bc64 - rustc_query_system[44d60dfb7090b806]::query::plumbing::try_execute_query::<rustc_query_impl[e4e476eeb45651d1]::DynamicConfig<rustc_query_system[44d60dfb7090b806]::query::caches::SingleCache<rustc_middle[7266ccbfd6f08af0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[e4e476eeb45651d1]::plumbing::QueryCtxt, false>
  66:     0x7f540263b9d9 - rustc_query_impl[e4e476eeb45651d1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  67:     0x7f540240df33 - <rustc_middle[7266ccbfd6f08af0]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[421f961c2abd6a6c]::run_compiler::{closure#1}::{closure#2}::{closure#6}, core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>>
  68:     0x7f540240d03c - <rustc_interface[e402a4e95d47e40d]::interface::Compiler>::enter::<rustc_driver_impl[421f961c2abd6a6c]::run_compiler::{closure#1}::{closure#2}, core[91a7ba3c96b8fb6a]::result::Result<core[91a7ba3c96b8fb6a]::option::Option<rustc_interface[e402a4e95d47e40d]::queries::Linker>, rustc_span[e182e80647a6f439]::ErrorGuaranteed>>
  69:     0x7f5402404a38 - std[2ba0c775535575e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e402a4e95d47e40d]::util::run_in_thread_with_globals<rustc_interface[e402a4e95d47e40d]::interface::run_compiler<core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>, rustc_driver_impl[421f961c2abd6a6c]::run_compiler::{closure#1}>::{closure#0}, core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>>
  70:     0x7f54024041ae - <<std[2ba0c775535575e]::thread::Builder>::spawn_unchecked_<rustc_interface[e402a4e95d47e40d]::util::run_in_thread_with_globals<rustc_interface[e402a4e95d47e40d]::interface::run_compiler<core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>, rustc_driver_impl[421f961c2abd6a6c]::run_compiler::{closure#1}>::{closure#0}, core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[91a7ba3c96b8fb6a]::result::Result<(), rustc_span[e182e80647a6f439]::ErrorGuaranteed>>::{closure#1} as core[91a7ba3c96b8fb6a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  71:     0x7f53ffd4ad35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc5c2793cdb16fd0c
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/alloc/src/boxed.rs:2007:9
  72:     0x7f53ffd4ad35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd102196bf71bb167
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/alloc/src/boxed.rs:2007:9
  73:     0x7f53ffd4ad35 - std::sys::unix::thread::Thread::new::thread_start::hd2018bce9981ca61
                               at /rustc/a991861ec9fd8aedffbe5744a8852c7c64dd40b2/library/std/src/sys/unix/thread.rs:108:17
  74:     0x7f53ffc0b609 - start_thread
  75:     0x7f53ffb30133 - clone
  76:                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 attach the file at `/home/code/rustc-ice-2023-09-06T08:50:10.652342838Z-233.txt` to your bug report

query stack during panic:
#0 [mir_built] building MIR for `main`
#1 [unsafety_check_result] unsafety-checking `main`
#2 [mir_const] preparing `main` for borrow checking
#3 [mir_promoted] promoting constants in MIR for `main`
#4 [mir_borrowck] borrow-checking `main`
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

Activity

added
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.
on Sep 6, 2023
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 6, 2023
mu001999

mu001999 commented on Sep 6, 2023

@mu001999
Contributor

@rustbot claim

matthiaskrgr

matthiaskrgr commented on Sep 6, 2023

@matthiaskrgr
Member

Hmm this was caused by #111913 cc @oli-obk

removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 6, 2023
removed their assignment
on Sep 7, 2023
kiscad

kiscad commented on Sep 7, 2023

@kiscad
Contributor

@rustbot claim

removed their assignment
on Sep 14, 2023
added 2 commits that reference this issue on Oct 11, 2023

Rollup merge of rust-lang#116522 - bvanjoi:fix-115599, r=oli-obk

ae15846

Rollup merge of rust-lang#116522 - bvanjoi:fix-115599, r=oli-obk

74e0fd3

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthiaskrgr@kiscad@fmease@iamanonymouscs@mu001999

      Issue actions

        ICE error when matching uninitialized constant with constant pattern in Rust · Issue #115599 · rust-lang/rust