Skip to content

Broken MIR ICE with let chains #104843

Closed

Description

@est31

Originally reported by @flip1995 in #99938 (comment) .

Code

#![feature(let_chains)]

struct F(Box<()>);

impl F {
    fn s(&self) -> Option<&str> {
        None
    }
}

fn cex() -> Option<F> {
    None
}

pub fn main() {
    if false
        && let Some(ce) = cex()
        && let Some(_ce) = ce.s()
    {
    }
}

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:9 ~ a[8fb6]::main), const_param_did: None }) (after phase change to runtime-optimized) at bb3[0]:
                                use of local _1, which has no storage here
  --> /tmp/a.rs:21:1
   |
21 | }
   | ^
   |
   = note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:88:36

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:9 ~ a[8fb6]::main), const_param_did: None }) (after phase change to runtime-optimized) at bb4[0]:
                                use of local _1, which has no storage here
  --> /tmp/a.rs:21:1
   |
21 | }
   | ^
   |
   = note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:88:36

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1594:13

Backtrace

   0:     0x7f4776d010da - std::backtrace_rs::backtrace::libunwind::trace::h06e8f32b98d440be
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f4776d010da - std::backtrace_rs::backtrace::trace_unsynchronized::h8a56795adafc3159
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4776d010da - std::sys_common::backtrace::_print_fmt::h7ba19acb3601abb5
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f4776d010da - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha37df576307c1a49
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f4772c6fbae - core::fmt::write::hd3f2e7e755b45b01
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/core/src/fmt/mod.rs:1208:17
   5:     0x7f4776cf53a5 - std::io::Write::write_fmt::hc1388e059aac0a41
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/io/mod.rs:1682:15
   6:     0x7f4776d00ea5 - std::sys_common::backtrace::_print::h429db1082d921ab8
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f4776d00ea5 - std::sys_common::backtrace::print::h8d611e0005d3ccb9
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f4776d0320f - std::panicking::default_hook::{{closure}}::h07380c607f829a79
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/panicking.rs:267:22
   9:     0x7f4776d02f4b - std::panicking::default_hook::h78998b3f3926502a
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/panicking.rs:286:9
  10:     0x7f4775f5b284 - <rustc_driver[153e38e44d5410f9]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[1d8afb50f4e7a45]::ops::function::FnOnce<(&core[1d8afb50f4e7a45]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f4776d03a0d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hbe7c77b7cbfe1f21
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/alloc/src/boxed.rs:2032:9
  12:     0x7f4776d03a0d - std::panicking::rust_panic_with_hook::hda16cab0ff009a11
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/panicking.rs:692:13
  13:     0x7f4775f93ab1 - std[2b5db76a972e300f]::panicking::begin_panic::<rustc_errors[6e875e03adfb8e66]::ExplicitBug>::{closure#0}
  14:     0x7f4775f923e6 - std[2b5db76a972e300f]::sys_common::backtrace::__rust_end_short_backtrace::<std[2b5db76a972e300f]::panicking::begin_panic<rustc_errors[6e875e03adfb8e66]::ExplicitBug>::{closure#0}, !>
  15:     0x7f4775f8ab76 - std[2b5db76a972e300f]::panicking::begin_panic::<rustc_errors[6e875e03adfb8e66]::ExplicitBug>
  16:     0x7f4775f8e306 - std[2b5db76a972e300f]::panic::panic_any::<rustc_errors[6e875e03adfb8e66]::ExplicitBug>
  17:     0x7f4775465556 - <rustc_errors[6e875e03adfb8e66]::HandlerInner>::flush_delayed::<alloc[eb468f42ab80a7c0]::vec::Vec<rustc_errors[6e875e03adfb8e66]::diagnostic::Diagnostic>, &str>
  18:     0x7f477546485b - <rustc_errors[6e875e03adfb8e66]::HandlerInner as core[1d8afb50f4e7a45]::ops::drop::Drop>::drop
  19:     0x7f477521271e - core[1d8afb50f4e7a45]::ptr::drop_in_place::<rustc_session[729ed7505232e216]::parse::ParseSess>
  20:     0x7f47751cb42f - core[1d8afb50f4e7a45]::ptr::drop_in_place::<rustc_session[729ed7505232e216]::session::Session>
  21:     0x7f47751cb160 - core[1d8afb50f4e7a45]::ptr::drop_in_place::<rustc_interface[d2ac3f3b3bfa4614]::interface::Compiler>
  22:     0x7f47751ca26e - rustc_span[cdf434c68ce75247]::with_source_map::<core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>, rustc_interface[d2ac3f3b3bfa4614]::interface::run_compiler<core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>, rustc_driver[153e38e44d5410f9]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  23:     0x7f47751c9ba5 - <scoped_tls[2ec6d95ce5fd8213]::ScopedKey<rustc_span[cdf434c68ce75247]::SessionGlobals>>::set::<rustc_interface[d2ac3f3b3bfa4614]::interface::run_compiler<core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>, rustc_driver[153e38e44d5410f9]::run_compiler::{closure#1}>::{closure#0}, core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>>
  24:     0x7f47751c9192 - std[2b5db76a972e300f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d2ac3f3b3bfa4614]::util::run_in_thread_pool_with_globals<rustc_interface[d2ac3f3b3bfa4614]::interface::run_compiler<core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>, rustc_driver[153e38e44d5410f9]::run_compiler::{closure#1}>::{closure#0}, core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>>
  25:     0x7f47751c8ea8 - <<std[2b5db76a972e300f]::thread::Builder>::spawn_unchecked_<rustc_interface[d2ac3f3b3bfa4614]::util::run_in_thread_pool_with_globals<rustc_interface[d2ac3f3b3bfa4614]::interface::run_compiler<core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>, rustc_driver[153e38e44d5410f9]::run_compiler::{closure#1}>::{closure#0}, core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d8afb50f4e7a45]::result::Result<(), rustc_errors[6e875e03adfb8e66]::ErrorGuaranteed>>::{closure#1} as core[1d8afb50f4e7a45]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x7f4776d0ac43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0c8cfd64ff347c2f
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/alloc/src/boxed.rs:2000:9
  27:     0x7f4776d0ac43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5243ef33e0bc55ac
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/alloc/src/boxed.rs:2000:9
  28:     0x7f4776d0ac43 - std::sys::unix::thread::Thread::new::thread_start::h248bc665ee6b9bda
                               at /rustc/70f8737b2f5d3bf7d6b784fad00b663b7ff9feda/library/std/src/sys/unix/thread.rs:108:17
  29:     0x7f4772985ff2 - start_thread
  30:     0x7f4772a08bfc - clone3
  31:                0x0 - <unknown>

The ICE requires -O to be passed to rustc, or --release be passed to cargo, the param to validate MIR is not enough. It's also a regression, on nightly-2022-07-30 it does not reproduce.

cc #99938 and #99852 related issues with similar error messages, but they are fixed and this is reproducible.

@rustbot label E-needs-bisection

Activity

  1. 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 Nov 24, 2022
  2. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Nov 24, 2022
  3. est31 commented on Nov 24, 2022

    @est31
    MemberAuthor

    @rustbot label F-let_chains

  4. lukas-code commented on Nov 24, 2022

    @lukas-code
    Contributor

    searched nightlies: from nightly-2022-07-20 to nightly-2022-11-23
    regressed nightly: nightly-2022-10-20
    searched commit range: a24a020...4b8f431
    regressed commit: d7dd01f

    bisected with cargo-bisect-rustc v0.6.4

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --end=2022-11-23 --regress=ice -- rustc -- -Zvalidate-mir -O 
  5. Noratrieb commented on Nov 24, 2022

    @Noratrieb
    Member

    Looks like #103034 didn't fix everything after all..... @nathanwhit
    this feature just keeps on giving

  6. est31 commented on Nov 24, 2022

    @est31
    MemberAuthor

    @rustbot label -E-needs-bisection

  7. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Nov 24, 2022
  8. flip1995 commented on Nov 25, 2022

    @flip1995
    Member

    Thanks for opening an issue for this! I put that on my todo list, but my todo list is just way to long...

  9. dingxiangfei2009 commented on Dec 23, 2022

    @dingxiangfei2009
    Contributor

    @rustbot claim

  10. dingxiangfei2009 commented on Jan 11, 2023

    @dingxiangfei2009
    Contributor

    I have a feeling that the if-then scope tracking could be relevant to this issue. Zooming onto that.

  11. 1 remaining item

  12. est31 commented on Jan 15, 2023

    @est31
    MemberAuthor

    Note that regarding drop order, for now, until #103108 is addressed, we should drop all the let temporaries after the else has terminated. This is for consistency with if let. See #103248 and especially the message I linked at the end that closed the issue. Not sure how one can represent that with scopes though.

  13. BlueskyFR commented on Sep 29, 2023

    @BlueskyFR

    This is still happening on the nightly release, @dingxiangfei2009 did you came up with something? This seems to be blocking the let-chaining features from stabilizing

  14. est31 commented on Sep 29, 2023

    @est31
    MemberAuthor

    There is #107251 which would solve this. I haven't had the time to push it forward, but the next logical step would be to file PRs to the repos broken by the PR, not suggesting that this will break eventually, as the only time when this is 100% sure is when this PR is merged, but that there is the chance it might break. See the thread of #107251.

    The other blocker is formatting support, which depends on the style team.

    Edit: feel free to file the PRs if you want.

  15. dingxiangfei2009 commented on Sep 29, 2023

    @dingxiangfei2009
    Contributor

    I will update the draft that @est31 mentioned.

  16. added
    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
    -Zvalidate-mirUnstable option: MIR validation
    on Dec 9, 2023
  17. added a commit that references this issue on Dec 23, 2023
    7dd0955
  18. added a commit that references this issue on Dec 23, 2023
    1621059
  19. est31 commented on Nov 9, 2024

    @est31
    MemberAuthor

    Btw, this still ICEs if you pass -Zlint-mir to the compiler. It passes if you set the edition to 2024 however, so #124085 has worked.

  20. added a commit that references this issue on Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

-Zvalidate-mirUnstable option: MIR validationA-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-let-chainsArea: let chains (if-let, while-let, ...)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