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: tuple pattern not applied to a tuple #121410

Closed
matthiaskrgr opened this issue Feb 21, 2024 · 4 comments
Closed

ICE: tuple pattern not applied to a tuple #121410

matthiaskrgr opened this issue Feb 21, 2024 · 4 comments
Assignees
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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 test_missing_unsafe_warning_on_repr_packed() {
    struct Foo {
        x: String,
    }

    let foo = Foo {};

    let c = || {
        let (_, t2) = foo.x;
    };

    c();
}
original code

original:

//@ edition:2021

// Given how the closure desugaring is implemented (at least at the time of writing this test),
// we don't need to truncate the captured path to a reference into a packed-struct if the field
// being referenced will be moved into the closure, since it's safe to move out a field from a
// packed-struct.
//
// However to avoid surprises for the user, or issues when the closure is
// inlined we will truncate the capture to access just the struct regardless of if the field
// might get moved into the closure.
//
// It is possible for someone to try writing the code that relies on the desugaring to create a ref
// into a packed-struct. Here we test that the compiler still detects that case.
fn test_missing_unsafe_warning_on_repr_packed() {
    #[derive(Debug, PartialEq, Eq)]
    struct Foo { x: String }

    let foo = Foo { x: String::new() };

    let c = || {
        println!(unused_must_use);
        //~^ ERROR: reference to packed field is unaligned
        let (_, t2) = foo.x;
    };

    c();
}

fn main() {
    test_missing_unsafe_warning_on_repr_packed();
}

Version information

rustc 1.78.0-nightly (f8131a48a 2024-02-21)
binary: rustc
commit-hash: f8131a48a46ac3bc8a3d0fe0477055b132cffdc3
commit-date: 2024-02-21
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

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

Program output

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

error[E0063]: missing field `x` in initializer of `Foo`
  --> /tmp/icemaker_global_tempdir.d70TvpvoHEvu/rustc_testrunner_tmpdir_reporting.gabpX6WsInFl/mvce.rs:10:15
   |
10 |     let foo = Foo {};
   |               ^^^ missing `x`

error[E0308]: mismatched types
  --> /tmp/icemaker_global_tempdir.d70TvpvoHEvu/rustc_testrunner_tmpdir_reporting.gabpX6WsInFl/mvce.rs:13:13
   |
13 |         let (_, t2) = foo.x;
   |             ^^^^^^^   ----- this expression has type `String`
   |             |
   |             expected `String`, found `(_, _)`
   |
   = note: expected struct `String`
               found tuple `(_, _)`

error: internal compiler error: tuple pattern not applied to a tuple
  --> /tmp/icemaker_global_tempdir.d70TvpvoHEvu/rustc_testrunner_tmpdir_reporting.gabpX6WsInFl/mvce.rs:13:13
   |
13 |         let (_, t2) = foo.x;
   |             ^^^^^^^

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/mem_categorization.rs:585:34:
Box<dyn Any>
stack backtrace:
   0:     0x7f82c541daf6 - std::backtrace_rs::backtrace::libunwind::trace::hbec2edc838b433e2
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f82c541daf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h88c30257ee0dd166
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f82c541daf6 - std::sys_common::backtrace::_print_fmt::h9176654d509e3088
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f82c541daf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h671feaee1776bf19
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f82c546ea7c - core::fmt::rt::Argument::fmt::h59605c83ae32d935
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/core/src/fmt/rt.rs:142:9
   5:     0x7f82c546ea7c - core::fmt::write::hf7af8dfcfd20db5b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f82c54124bf - std::io::Write::write_fmt::h92a5dbf489025e71
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/io/mod.rs:1846:15
   7:     0x7f82c541d8a4 - std::sys_common::backtrace::_print::h00080302d23998ae
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f82c541d8a4 - std::sys_common::backtrace::print::h6b23124445400245
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f82c54205eb - std::panicking::default_hook::{{closure}}::hd67b2f9d36675a28
  10:     0x7f82c5420339 - std::panicking::default_hook::h10a39ef11c714e42
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/panicking.rs:292:9
  11:     0x7f82c207a94c - std[5a8e7f94216a9138]::panicking::update_hook::<alloc[e14ab1f516d287ab]::boxed::Box<rustc_driver_impl[e279e4f1fedd9109]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f82c5420d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h37ba37dc48823c1d
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2030:9
  13:     0x7f82c5420d50 - std::panicking::rust_panic_with_hook::he3e3bc7c345bf54b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/panicking.rs:786:13
  14:     0x7f82c20a7524 - std[5a8e7f94216a9138]::panicking::begin_panic::<rustc_errors[34364e5c712fab73]::ExplicitBug>::{closure#0}
  15:     0x7f82c20a4176 - std[5a8e7f94216a9138]::sys_common::backtrace::__rust_end_short_backtrace::<std[5a8e7f94216a9138]::panicking::begin_panic<rustc_errors[34364e5c712fab73]::ExplicitBug>::{closure#0}, !>
  16:     0x7f82c209f936 - std[5a8e7f94216a9138]::panicking::begin_panic::<rustc_errors[34364e5c712fab73]::ExplicitBug>
  17:     0x7f82c0a17631 - <rustc_errors[34364e5c712fab73]::diagnostic::BugAbort as rustc_errors[34364e5c712fab73]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f82c3b1b06c - <rustc_hir_typeck[7492106fe3468815]::mem_categorization::MemCategorizationContext>::cat_pattern_::<<rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::walk_pat::{closure#1}>
  19:     0x7f82c3b19e18 - <rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::walk_pat
  20:     0x7f82c3a89048 - <rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::walk_block
  21:     0x7f82c138fb84 - <rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::walk_expr
  22:     0x7f82c3a89c4d - <rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::consume_expr
  23:     0x7f82c3a895e4 - <rustc_hir_typeck[7492106fe3468815]::expr_use_visitor::ExprUseVisitor>::consume_body
  24:     0x7f82c3ecb08a - <rustc_hir_typeck[7492106fe3468815]::fn_ctxt::FnCtxt>::analyze_closure
  25:     0x7f82c027c57b - <rustc_hir_typeck[7492106fe3468815]::upvar::InferBorrowKindVisitor as rustc_hir[170b9793d794ea06]::intravisit::Visitor>::visit_expr
  26:     0x7f82c3660659 - <rustc_hir_typeck[7492106fe3468815]::upvar::InferBorrowKindVisitor as rustc_hir[170b9793d794ea06]::intravisit::Visitor>::visit_block
  27:     0x7f82c3653ddd - rustc_hir_typeck[7492106fe3468815]::typeck
  28:     0x7f82c3652d17 - rustc_query_impl[9d4c51777e2bb749]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4c51777e2bb749]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7f82c35098b0 - rustc_query_system[9b2ccfe41ae3bb1b]::query::plumbing::try_execute_query::<rustc_query_impl[9d4c51777e2bb749]::DynamicConfig<rustc_query_system[9b2ccfe41ae3bb1b]::query::caches::VecCache<rustc_span[adb133ac03280fc1]::def_id::LocalDefId, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9d4c51777e2bb749]::plumbing::QueryCtxt, false>
  30:     0x7f82c35093cc - rustc_query_impl[9d4c51777e2bb749]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7f82c3daf412 - <rustc_middle[446dd094ad85939e]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[71d4294717f7f2b7]::check_crate::{closure#6}>::{closure#0}
  32:     0x7f82c3dadcdd - rustc_hir_analysis[71d4294717f7f2b7]::check_crate
  33:     0x7f82c3ea2dd3 - rustc_interface[7ca501d7f8f3a34f]::passes::analysis
  34:     0x7f82c3ea2a29 - rustc_query_impl[9d4c51777e2bb749]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9d4c51777e2bb749]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7f82c413d4a5 - rustc_query_system[9b2ccfe41ae3bb1b]::query::plumbing::try_execute_query::<rustc_query_impl[9d4c51777e2bb749]::DynamicConfig<rustc_query_system[9b2ccfe41ae3bb1b]::query::caches::SingleCache<rustc_middle[446dd094ad85939e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9d4c51777e2bb749]::plumbing::QueryCtxt, false>
  36:     0x7f82c413d209 - rustc_query_impl[9d4c51777e2bb749]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f82c414c719 - rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler::<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}
  38:     0x7f82c43be705 - std[5a8e7f94216a9138]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_with_globals<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_pool_with_globals<rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>
  39:     0x7f82c43be532 - <<std[5a8e7f94216a9138]::thread::Builder>::spawn_unchecked_<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_with_globals<rustc_interface[7ca501d7f8f3a34f]::util::run_in_thread_pool_with_globals<rustc_interface[7ca501d7f8f3a34f]::interface::run_compiler<core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>, rustc_driver_impl[e279e4f1fedd9109]::run_compiler::{closure#0}>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[85b4fd477ce5bb21]::result::Result<(), rustc_span[adb133ac03280fc1]::ErrorGuaranteed>>::{closure#1} as core[85b4fd477ce5bb21]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7f82c542a725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1bff3efb61c3fa6b
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2016:9
  41:     0x7f82c542a725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h83141cf549dced8a
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/alloc/src/boxed.rs:2016:9
  42:     0x7f82c542a725 - std::sys::pal::unix::thread::Thread::new::thread_start::hbe9287fdd7c325bc
                               at /rustc/f8131a48a46ac3bc8a3d0fe0477055b132cffdc3/library/std/src/sys/pal/unix/thread.rs:108:17
  43:     0x7f82bf0aa9eb - <unknown>
  44:     0x7f82bf12e7cc - <unknown>
  45:                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: rustc 1.78.0-nightly (f8131a48a 2024-02-21) running on x86_64-unknown-linux-gnu

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

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

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Feb 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 21, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Feb 21, 2024

  • Does not ICE on stable
  • Does not ICE on older nightly (rustc 1.78.0-nightly (bb594538f 2024-02-20))

@jieyouxu jieyouxu added the regression-untriaged Untriaged performance or correctness regression. label Feb 21, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 21, 2024
@jieyouxu jieyouxu added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Feb 21, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 21, 2024
@jieyouxu jieyouxu added the A-patterns Relating to patterns and pattern matching label Feb 21, 2024
@jieyouxu
Copy link
Member

Seems closure is required, moving let (_, t2) = foo.x; out of closure does not ICE.

@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 Feb 21, 2024
@matthiaskrgr
Copy link
Member Author

#121208 cc @nnethercote 🙈

@nnethercote nnethercote self-assigned this Feb 21, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 22, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 22, 2024
@bors bors closed this as completed in 4f83e50 Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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

No branches or pull requests

5 participants