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: entered unreachable code: no sub-expr expected for Pat #133947

Closed
matthiaskrgr opened this issue Dec 6, 2024 · 1 comment · Fixed by #134103
Closed

ICE: entered unreachable code: no sub-expr expected for Pat #133947

matthiaskrgr opened this issue Dec 6, 2024 · 1 comment · Fixed by #134103
Assignees
Labels
C-bug Category: This is a bug. F-never_type `#![feature(never_type)]` 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):

fn test2() {
    let x: !;
    let c2 = SingleVariant::Points(0)
        | match 1 {
            0..=x => {}
        };
}

original:

#![feature(never_type)]

fn test2() {
    let x: !;
    let c2 = SingleVariant::Points(0)
        | match 1 {
        0 ..= x => {}
        //~^ ERROR: runtime values cannot be referenced in patterns
        0 ..= FOO => {}
        //~^ ERROR: statics cannot be referenced in patterns
    };
}

enum B { B }

fn main() {}

Version information

rustc 1.85.0-nightly (c94848c04 2024-12-05)
binary: rustc
commit-hash: c94848c046d29f9a80c09aae758e27e418a289f2
commit-date: 2024-12-05
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Possibly related line of code:

| hir::Node::GenericParam(_)
| hir::Node::Crate(_)
| hir::Node::Infer(_)
| hir::Node::WherePredicate(_)
| hir::Node::PreciseCapturingNonLifetimeArg(_)
| hir::Node::OpaqueTy(_) => {
unreachable!("no sub-expr expected for {parent_node:?}")
}
}
}
/// Whether this pattern constitutes a read of value of the scrutinee that
/// it is matching against. This is used to determine whether we should

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

Program output

error[E0658]: the `!` type is experimental
 --> /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:2:12
  |
2 |     let x: !;
  |            ^
  |
  = note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
  = help: add `#![feature(never_type)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-05; consider upgrading it if it is out of date

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

error[E0433]: failed to resolve: use of undeclared type `SingleVariant`
 --> /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:3:14
  |
3 |     let c2 = SingleVariant::Points(0)
  |              ^^^^^^^^^^^^^ use of undeclared type `SingleVariant`

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/expr.rs:430:17:
internal error: entered unreachable code: no sub-expr expected for Pat(Pat { hir_id: HirId(DefId(0:3 ~ mvce[ef52]::test2).15), kind: Range(Some(Expr { hir_id: HirId(DefId(0:3 ~ mvce[ef52]::test2).16), kind: Lit(Spanned { node: Int(Pu128(0), Unsuffixed), span: /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:5:13: 5:14 (#0) }), span: /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:5:13: 5:14 (#0) }), Some(Expr { hir_id: HirId(DefId(0:3 ~ mvce[ef52]::test2).17), kind: Path(Resolved(None, Path { span: /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:5:17: 5:18 (#0), res: Local(HirId(DefId(0:3 ~ mvce[ef52]::test2).5)), segments: [PathSegment { ident: x#0, hir_id: HirId(DefId(0:3 ~ mvce[ef52]::test2).18), res: Local(HirId(DefId(0:3 ~ mvce[ef52]::test2).5)), args: None, infer_args: true }] })), span: /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:5:17: 5:18 (#0) }), Included), span: /tmp/icemaker_global_tempdir.j7zmU1Vhf0Zs/rustc_testrunner_tmpdir_reporting.1W4prXpGdnHk/mvce.rs:5:13: 5:18 (#0), default_binding_modes: true })
stack backtrace:
   0:     0x723d3353f0fa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6672795076376ec8
   1:     0x723d33c13e26 - core::fmt::write::h792a60ae9bb2dbda
   2:     0x723d34c08391 - std::io::Write::write_fmt::hfc5b1a97b7b0eb31
   3:     0x723d3353ef52 - std::sys::backtrace::BacktraceLock::print::h2c102308db74512c
   4:     0x723d3354146a - std::panicking::default_hook::{{closure}}::h63a255606d7053aa
   5:     0x723d335412b3 - std::panicking::default_hook::h114da533e3893438
   6:     0x723d326b9068 - std[339c42a0e0e1cbc8]::panicking::update_hook::<alloc[4b645d2b808d60e5]::boxed::Box<rustc_driver_impl[a450451a1b077cae]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x723d33541c28 - std::panicking::rust_panic_with_hook::hadbdcb738271374d
   8:     0x723d3354191a - std::panicking::begin_panic_handler::{{closure}}::hf015953bfb7b98c8
   9:     0x723d3353f5a9 - std::sys::backtrace::__rust_end_short_backtrace::h8eb8f61d86c09a66
  10:     0x723d335415dd - rust_begin_unwind
  11:     0x723d301afd10 - core::panicking::panic_fmt::h8558f71ff16f773d
  12:     0x723d33d70d6b - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  13:     0x723d33df968c - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_pat
  14:     0x723d34d3cbc4 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args::{closure#0}
  15:     0x723d33d6dea6 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  16:     0x723d33d8776f - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_overloaded_binop
  17:     0x723d34d3cc95 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args::{closure#0}
  18:     0x723d33d6dea6 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  19:     0x723d33d68eb9 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_decl
  20:     0x723d33d6b6a1 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_block
  21:     0x723d34d3b4e9 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args::{closure#0}
  22:     0x723d33d6dea6 - <rustc_hir_typeck[17bac021c3c291fe]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x723d340134e6 - rustc_hir_typeck[17bac021c3c291fe]::check::check_fn
  24:     0x723d3401b441 - rustc_hir_typeck[17bac021c3c291fe]::typeck
  25:     0x723d3401a05d - rustc_query_impl[3a63db0db156c2ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3a63db0db156c2ea]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aab370552e9df2de]::query::erase::Erased<[u8; 8usize]>>
  26:     0x723d34026f11 - rustc_query_system[924318b55d1b9da5]::query::plumbing::try_execute_query::<rustc_query_impl[3a63db0db156c2ea]::DynamicConfig<rustc_data_structures[904645e0e499155f]::vec_cache::VecCache<rustc_span[cf656b7144c9c5c5]::def_id::LocalDefId, rustc_middle[aab370552e9df2de]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[924318b55d1b9da5]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[3a63db0db156c2ea]::plumbing::QueryCtxt, false>
  27:     0x723d340261cd - rustc_query_impl[3a63db0db156c2ea]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  28:     0x723d34025e7f - <rustc_middle[aab370552e9df2de]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[c0842703e669cd]::check_crate::{closure#4}>::{closure#0}
  29:     0x723d34023e92 - rustc_hir_analysis[c0842703e669cd]::check_crate
  30:     0x723d3402e9c4 - rustc_interface[b7068c2f67f9e538]::passes::run_required_analyses
  31:     0x723d34be5f9e - rustc_interface[b7068c2f67f9e538]::passes::analysis
  32:     0x723d34be5f6f - rustc_query_impl[3a63db0db156c2ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3a63db0db156c2ea]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[aab370552e9df2de]::query::erase::Erased<[u8; 1usize]>>
  33:     0x723d34bbdd7a - rustc_query_system[924318b55d1b9da5]::query::plumbing::try_execute_query::<rustc_query_impl[3a63db0db156c2ea]::DynamicConfig<rustc_query_system[924318b55d1b9da5]::query::caches::SingleCache<rustc_middle[aab370552e9df2de]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3a63db0db156c2ea]::plumbing::QueryCtxt, false>
  34:     0x723d34bbda4e - rustc_query_impl[3a63db0db156c2ea]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x723d34c9142b - rustc_interface[b7068c2f67f9e538]::interface::run_compiler::<core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>, rustc_driver_impl[a450451a1b077cae]::run_compiler::{closure#0}>::{closure#1}
  36:     0x723d34adc387 - std[339c42a0e0e1cbc8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b7068c2f67f9e538]::util::run_in_thread_with_globals<rustc_interface[b7068c2f67f9e538]::util::run_in_thread_pool_with_globals<rustc_interface[b7068c2f67f9e538]::interface::run_compiler<core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>, rustc_driver_impl[a450451a1b077cae]::run_compiler::{closure#0}>::{closure#1}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>::{closure#0}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>
  37:     0x723d34adc022 - <<std[339c42a0e0e1cbc8]::thread::Builder>::spawn_unchecked_<rustc_interface[b7068c2f67f9e538]::util::run_in_thread_with_globals<rustc_interface[b7068c2f67f9e538]::util::run_in_thread_pool_with_globals<rustc_interface[b7068c2f67f9e538]::interface::run_compiler<core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>, rustc_driver_impl[a450451a1b077cae]::run_compiler::{closure#0}>::{closure#1}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>::{closure#0}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a08a8da589f49b02]::result::Result<(), rustc_span[cf656b7144c9c5c5]::ErrorGuaranteed>>::{closure#1} as core[a08a8da589f49b02]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x723d34adb76b - std::sys::pal::unix::thread::Thread::new::thread_start::hc40c233155f425ee
  39:     0x723d2eea339d - <unknown>
  40:     0x723d2ef2849c - <unknown>
  41:                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.85.0-nightly (c94848c04 2024-12-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `test2`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

@rustbot label +F-never_type

@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 6, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-never_type `#![feature(never_type)]` labels Dec 6, 2024
@matthiaskrgr
Copy link
Member Author

fn main() {
    let b: ! = todo!();
    match 0..0 { 0..b }
}

@jieyouxu jieyouxu added 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 6, 2024
@compiler-errors compiler-errors self-assigned this Dec 10, 2024
fmease added a commit to fmease/rust that referenced this issue Dec 10, 2024
…=oli-obk

Don't ICE when encountering never in range pattern

Fixes rust-lang#133947

r? oli-obk
@bors bors closed this as completed in c5a8386 Dec 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 11, 2024
Rollup merge of rust-lang#134103 - compiler-errors:never-pat-range, r=oli-obk

Don't ICE when encountering never in range pattern

Fixes rust-lang#133947

r? oli-obk
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-never_type `#![feature(never_type)]` 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