Skip to content

ICE: Field projection applied to a type other than Adt or Tuple: !. #150507

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![warn(rust_2021_incompatible_closure_captures)]

fn test3() {
    let variant: !;
    let c = || match variant {
        (2, [_, _]) => println!("good"),

        _ => {}
    };
    c();
}
original code

original:

#![warn(rust_2021_incompatible_closure_captures)]
//@ edition:2021

#![feature(never_type)]

// Should fake read the discriminant and throw an error
fn test1() {
    let x: !;
    let c1 = || match x { };
    //~^ ERROR E0381
}

// Should fake read the discriminant and throw an error
fn test2() {
    let x: !;
    let c2 = SingleVariant::Points(_)| match x { _ => () };
    //~^ ERROR E0381
}

// Testing single variant patterns
enum SingleVariant {
    Points(u32)
}

// Should fake read the discriminant and throw an error
fn test3() {
    let variant: !;
    let c = || {
    //~^ ERROR E0381
        match variant {
        (0, [_, _]) => {},
        (1, _) => {},
        (2, [_, _]) => println!("good"),
        (2, _) => println!("bad"),
        _ => {},
    }
    };
    c();
}

// Should fake read the discriminant and throw an error
fn test4() {
    let variant: !;
    let c = || { //~ ERROR E0381
        match variant {
            E::Number(_) if let _ = *value => { }
            _ => {}
        }
    };
    c();
}

fn test5() {
    let t: !;
    let g: !;

    let a = || {
        match g { }; //~ ERROR E0381
        let c = ||  {
            match t { }; //~ ERROR E0381
        };

        c();
    };

}

// Should fake read the discriminant and throw an error
fn test6() {
    let x: u8;
    let c1 = || match println { };
    //~^ ERROR E0381
    //~| ERROR: non-exhaustive patterns: type `u8` is non-empty
}

fn main() {
    test1();
    test2();
    test3();
    test4();
    test5();
    test6();
}

Version information

rustc 1.94.0-nightly (d874dce12 2025-12-30)
binary: rustc
commit-hash: d874dce1252fe409ce13e64d773046853bf5e6ca
commit-date: 2025-12-30
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

);
}
ty::Tuple(_) => {
curr_string = format!("{}.{}", curr_string, idx.index());
}
_ => {
bug!(
"Field projection applied to a type other than Adt or Tuple: {:?}.",
place.ty_before_projection(i).kind()
)
}
},
HirProjectionKind::UnwrapUnsafeBinder => {

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

Program output

error[E0658]: the `!` type is experimental
 --> /tmp/icemaker_global_tempdir.CCaKLOz9kEfN/rustc_testrunner_tmpdir_reporting.cRJ22bVbRmZF/mvce.rs:4:18
  |
4 |     let variant: !;
  |                  ^
  |
  = 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 2025-12-30; consider upgrading it if it is out of date

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

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.CCaKLOz9kEfN/rustc_testrunner_tmpdir_reporting.cRJ22bVbRmZF/mvce.rs:6:9
  |
5 |     let c = || match variant {
  |                      ------- this expression has type `!`
6 |         (2, [_, _]) => println!("good"),
  |         ^^^^^^^^^^^ expected `!`, found `(_, _)`
  |
  = note: expected type `!`
            found tuple `(_, _)`

error: internal compiler error: /rustc-dev/d874dce1252fe409ce13e64d773046853bf5e6ca/compiler/rustc_middle/src/ty/closure.rs:324:21: Field projection applied to a type other than Adt or Tuple: !.


thread 'rustc' (3872220) panicked at /rustc-dev/d874dce1252fe409ce13e64d773046853bf5e6ca/compiler/rustc_middle/src/ty/closure.rs:324:21:
Box<dyn Any>
stack backtrace:
   0:     0x7f580604cbf3 - <<std[1d851f4d98f44a43]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c01ad1edc1a578f1]::fmt::Display>::fmt
   1:     0x7f5806610b08 - core[c01ad1edc1a578f1]::fmt::write
   2:     0x7f5806063316 - <std[1d851f4d98f44a43]::sys::stdio::unix::Stderr as std[1d851f4d98f44a43]::io::Write>::write_fmt
   3:     0x7f58060234a8 - std[1d851f4d98f44a43]::panicking::default_hook::{closure#0}
   4:     0x7f5806040b33 - std[1d851f4d98f44a43]::panicking::default_hook
   5:     0x7f58050214fa - std[1d851f4d98f44a43]::panicking::update_hook::<alloc[741452e8137796b5]::boxed::Box<rustc_driver_impl[157a0bcc0a6c8b0d]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f5806040e12 - std[1d851f4d98f44a43]::panicking::panic_with_hook
   7:     0x7f580505e461 - std[1d851f4d98f44a43]::panicking::begin_panic::<rustc_errors[72c9d43fd5f09cd8]::ExplicitBug>::{closure#0}
   8:     0x7f580504e716 - std[1d851f4d98f44a43]::sys::backtrace::__rust_end_short_backtrace::<std[1d851f4d98f44a43]::panicking::begin_panic<rustc_errors[72c9d43fd5f09cd8]::ExplicitBug>::{closure#0}, !>
   9:     0x7f580504bd59 - std[1d851f4d98f44a43]::panicking::begin_panic::<rustc_errors[72c9d43fd5f09cd8]::ExplicitBug>
  10:     0x7f580507c3e1 - <rustc_errors[72c9d43fd5f09cd8]::diagnostic::BugAbort as rustc_errors[72c9d43fd5f09cd8]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f580562a919 - rustc_middle[37db470fd52aa1d5]::util::bug::opt_span_bug_fmt::<rustc_span[c72d63f7da0e5337]::span_encoding::Span>::{closure#0}
  12:     0x7f580562aaa2 - rustc_middle[37db470fd52aa1d5]::ty::context::tls::with_opt::<rustc_middle[37db470fd52aa1d5]::util::bug::opt_span_bug_fmt<rustc_span[c72d63f7da0e5337]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f580561b99b - rustc_middle[37db470fd52aa1d5]::ty::context::tls::with_context_opt::<rustc_middle[37db470fd52aa1d5]::ty::context::tls::with_opt<rustc_middle[37db470fd52aa1d5]::util::bug::opt_span_bug_fmt<rustc_span[c72d63f7da0e5337]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f58031d61f4 - rustc_middle[37db470fd52aa1d5]::util::bug::bug_fmt
  15:     0x7f58072c5be3 - rustc_middle[37db470fd52aa1d5]::ty::closure::place_to_string_for_capture
  16:     0x7f5805368fb5 - <rustc_hir_typeck[cabe4110ace5c7a6]::fn_ctxt::FnCtxt>::perform_2229_migration_analysis
  17:     0x7f580737697d - <rustc_hir_typeck[cabe4110ace5c7a6]::fn_ctxt::FnCtxt>::analyze_closure
  18:     0x7f580685d726 - <rustc_hir_typeck[cabe4110ace5c7a6]::upvar::InferBorrowKindVisitor as rustc_hir[e29ef912fd951a9a]::intravisit::Visitor>::visit_expr
  19:     0x7f580685d5a5 - <rustc_hir_typeck[cabe4110ace5c7a6]::upvar::InferBorrowKindVisitor as rustc_hir[e29ef912fd951a9a]::intravisit::Visitor>::visit_block
  20:     0x7f58072e659e - rustc_hir_typeck[cabe4110ace5c7a6]::typeck_with_inspect::{closure#0}
  21:     0x7f58072e48ce - rustc_query_impl[8f997d53b5bb2a9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8f997d53b5bb2a9]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[37db470fd52aa1d5]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7f5806844bb7 - rustc_query_system[a8f25f1a3f74a2b7]::query::plumbing::try_execute_query::<rustc_query_impl[8f997d53b5bb2a9]::DynamicConfig<rustc_data_structures[6f5dad3aaddcbc33]::vec_cache::VecCache<rustc_span[c72d63f7da0e5337]::def_id::LocalDefId, rustc_middle[37db470fd52aa1d5]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[a8f25f1a3f74a2b7]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[8f997d53b5bb2a9]::plumbing::QueryCtxt, false>
  23:     0x7f5806844489 - rustc_query_impl[8f997d53b5bb2a9]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7f5806b54ab3 - <rustc_middle[37db470fd52aa1d5]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[dada60b72de468f1]::check_crate::{closure#2}>::{closure#0}
  25:     0x7f5806b544c5 - rustc_hir_analysis[dada60b72de468f1]::check_crate
  26:     0x7f580738d45b - rustc_interface[73494817d80a485f]::passes::analysis
  27:     0x7f580738d0b5 - rustc_query_impl[8f997d53b5bb2a9]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8f997d53b5bb2a9]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[37db470fd52aa1d5]::query::erase::Erased<[u8; 0usize]>>
  28:     0x7f58077b09a6 - rustc_query_system[a8f25f1a3f74a2b7]::query::plumbing::try_execute_query::<rustc_query_impl[8f997d53b5bb2a9]::DynamicConfig<rustc_query_system[a8f25f1a3f74a2b7]::query::caches::SingleCache<rustc_middle[37db470fd52aa1d5]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[8f997d53b5bb2a9]::plumbing::QueryCtxt, false>
  29:     0x7f58077b0576 - rustc_query_impl[8f997d53b5bb2a9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f58079d5cd1 - <rustc_interface[73494817d80a485f]::passes::create_and_enter_global_ctxt<core[c01ad1edc1a578f1]::option::Option<rustc_interface[73494817d80a485f]::queries::Linker>, rustc_driver_impl[157a0bcc0a6c8b0d]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[c01ad1edc1a578f1]::ops::function::FnOnce<(&rustc_session[438cb52bb896cdbb]::session::Session, rustc_middle[37db470fd52aa1d5]::ty::context::CurrentGcx, alloc[741452e8137796b5]::sync::Arc<rustc_data_structures[6f5dad3aaddcbc33]::jobserver::Proxy>, &std[1d851f4d98f44a43]::sync::once_lock::OnceLock<rustc_middle[37db470fd52aa1d5]::ty::context::GlobalCtxt>, &rustc_data_structures[6f5dad3aaddcbc33]::sync::worker_local::WorkerLocal<rustc_middle[37db470fd52aa1d5]::arena::Arena>, &rustc_data_structures[6f5dad3aaddcbc33]::sync::worker_local::WorkerLocal<rustc_hir[e29ef912fd951a9a]::Arena>, rustc_driver_impl[157a0bcc0a6c8b0d]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  31:     0x7f580785d318 - rustc_interface[73494817d80a485f]::interface::run_compiler::<(), rustc_driver_impl[157a0bcc0a6c8b0d]::run_compiler::{closure#0}>::{closure#1}
  32:     0x7f5807797dce - std[1d851f4d98f44a43]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[73494817d80a485f]::util::run_in_thread_with_globals<rustc_interface[73494817d80a485f]::util::run_in_thread_pool_with_globals<rustc_interface[73494817d80a485f]::interface::run_compiler<(), rustc_driver_impl[157a0bcc0a6c8b0d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  33:     0x7f5807797ba0 - <std[1d851f4d98f44a43]::thread::lifecycle::spawn_unchecked<rustc_interface[73494817d80a485f]::util::run_in_thread_with_globals<rustc_interface[73494817d80a485f]::util::run_in_thread_pool_with_globals<rustc_interface[73494817d80a485f]::interface::run_compiler<(), rustc_driver_impl[157a0bcc0a6c8b0d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c01ad1edc1a578f1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7f580779d978 - <std[1d851f4d98f44a43]::sys::thread::unix::Thread>::new::thread_start
  35:     0x7f580109698b - <unknown>
  36:     0x7f580111a9cc - <unknown>
  37:                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: rustc 1.94.0-nightly (d874dce12 2025-12-30) running on x86_64-unknown-linux-gnu

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

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

@rustbot label +F-never_type

Metadata

Metadata

Assignees

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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions