rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.87k stars 12.67k forks source link

ice: `named field access on non-ADT` #120615

Closed matthiaskrgr closed 8 months ago

matthiaskrgr commented 8 months ago

auto-reduced (treereduce-rust):

fn main() {
    let s = [(); {
        let mut n = 113383;
        while n != 0 {}
        n
    }];

    s.nonexistent_methodisize;
}

original:

//! This test tests two things at once:
//! 1. we error if a const evaluation hits the deny-by-default lint limit
//! 2. we do not ICE on invalid follow-up code

// compile-flags: -Z tiny-const-eval-limit

fn main() {
    // Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
    // The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
    let s = [(); {
        let mut n = 113383; // #20 in https://oeis.org/A006884
        while n != 0 {
            //~^ ERROR is taking a long time
            n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
        }
        n
    }];

    s.nonexistent_methodisize;
}

Version information

rustc 1.77.0-nightly (bf3c6c5be 2024-02-01)
binary: rustc
commit-hash: bf3c6c5bed498f41ad815641319a1ad9bcecb8e8
commit-date: 2024-02-01
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

``` warning: variable does not need to be mutable --> /tmp/icemaker_global_tempdir.aIHYhz8MWTTj/rustc_testrunner_tmpdir_reporting.BWUL70tAHs3y/mvce.rs:3:13 | 3 | let mut n = 113383; | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default error: constant evaluation is taking a long time --> /tmp/icemaker_global_tempdir.aIHYhz8MWTTj/rustc_testrunner_tmpdir_reporting.BWUL70tAHs3y/mvce.rs:4:9 | 4 | while n != 0 {} | ^^^^^^^^^^^^^^^ | = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval. If your compilation actually takes a long time, you can safely allow the lint. help: the constant being evaluated --> /tmp/icemaker_global_tempdir.aIHYhz8MWTTj/rustc_testrunner_tmpdir_reporting.BWUL70tAHs3y/mvce.rs:2:18 | 2 | let s = [(); { | __________________^ 3 | | let mut n = 113383; 4 | | while n != 0 {} 5 | | n 6 | | }]; | |_____^ = note: `#[deny(long_running_const_eval)]` on by default error: internal compiler error: compiler/rustc_passes/src/dead.rs:145:18: named field access on non-ADT --> /tmp/icemaker_global_tempdir.aIHYhz8MWTTj/rustc_testrunner_tmpdir_reporting.BWUL70tAHs3y/mvce.rs:8:5 | 8 | s.nonexistent_methodisize; | ^ thread 'rustc' panicked at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/compiler/rustc_errors/src/lib.rs:855:41: Box stack backtrace: 0: 0x7feb52fafd16 - std::backtrace_rs::backtrace::libunwind::trace::he544685250360e22 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 1: 0x7feb52fafd16 - std::backtrace_rs::backtrace::trace_unsynchronized::h664adef12633380a at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7feb52fafd16 - std::sys_common::backtrace::_print_fmt::hba7ee045aeee07b0 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7feb52fafd16 - ::fmt::hc80b7ff177a688f2 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7feb53002770 - core::fmt::rt::Argument::fmt::h605309ab4829b6b5 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/core/src/fmt/rt.rs:142:9 5: 0x7feb53002770 - core::fmt::write::h5f24f526de99e105 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/core/src/fmt/mod.rs:1120:17 6: 0x7feb52fa361f - std::io::Write::write_fmt::h711c920f97cd3d8c at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/io/mod.rs:1846:15 7: 0x7feb52fafaf4 - std::sys_common::backtrace::_print::ha279702af2871260 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7feb52fafaf4 - std::sys_common::backtrace::print::hc1f3820f405abdd3 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7feb52fb2887 - std::panicking::default_hook::{{closure}}::h5058841d19c78172 10: 0x7feb52fb25e9 - std::panicking::default_hook::h60a42497ec033f97 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/panicking.rs:292:9 11: 0x7feb4fd371fc - std[4337b1e3d1c66af6]::panicking::update_hook::>::{closure#0} 12: 0x7feb52fb2fd6 - as core::ops::function::Fn>::call::h437fd8fcb0ff0cea at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/alloc/src/boxed.rs:2029:9 13: 0x7feb52fb2fd6 - std::panicking::rust_panic_with_hook::h294fbe090fe44fa4 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/panicking.rs:785:13 14: 0x7feb4fd693b4 - std[4337b1e3d1c66af6]::panicking::begin_panic::::{closure#0} 15: 0x7feb4fd65aa6 - std[4337b1e3d1c66af6]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7feb4fd60d06 - std[4337b1e3d1c66af6]::panicking::begin_panic:: 17: 0x7feb4fd74591 - ::emit_producing_guarantee 18: 0x7feb503fc8bd - rustc_middle[9b442554c155189d]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7feb503fc8ea - rustc_middle[9b442554c155189d]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7feb503f81a8 - rustc_middle[9b442554c155189d]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7feb503f7574 - rustc_middle[9b442554c155189d]::util::bug::span_bug_fmt:: 22: 0x7feb510f474f - ::visit_expr 23: 0x7feb510f1c04 - ::visit_block 24: 0x7feb5131bc26 - rustc_hir[1f4f973af63e82cc]::intravisit::walk_item:: 25: 0x7feb51fce711 - rustc_passes[4dd4d7a412ef7d49]::dead::live_symbols_and_ignored_derived_traits 26: 0x7feb51fcd7ac - rustc_query_impl[5a78334436849816]::plumbing::__rust_begin_short_backtrace::> 27: 0x7feb51da4af2 - rustc_query_system[f1aaee53077b1b15]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[5a78334436849816]::plumbing::QueryCtxt, false> 28: 0x7feb51da4286 - rustc_query_impl[5a78334436849816]::query_impl::live_symbols_and_ignored_derived_traits::get_query_non_incr::__rust_end_short_backtrace 29: 0x7feb5188dc09 - rustc_passes[4dd4d7a412ef7d49]::dead::check_mod_deathness 30: 0x7feb5188daab - rustc_query_impl[5a78334436849816]::plumbing::__rust_begin_short_backtrace::> 31: 0x7feb51bdf8bb - rustc_query_system[f1aaee53077b1b15]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[5a78334436849816]::plumbing::QueryCtxt, false> 32: 0x7feb51bdec83 - rustc_query_impl[5a78334436849816]::query_impl::check_mod_deathness::get_query_non_incr::__rust_end_short_backtrace 33: 0x7feb519eb050 - rustc_interface[e57535df52585ed5]::passes::analysis 34: 0x7feb519e9d9f - rustc_query_impl[5a78334436849816]::plumbing::__rust_begin_short_backtrace::> 35: 0x7feb51d0b6b2 - rustc_query_system[f1aaee53077b1b15]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[5a78334436849816]::plumbing::QueryCtxt, false> 36: 0x7feb51d0b415 - rustc_query_impl[5a78334436849816]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 37: 0x7feb51d182b6 - rustc_interface[e57535df52585ed5]::interface::run_compiler::, rustc_driver_impl[e51f6499da6a94b9]::run_compiler::{closure#0}>::{closure#0} 38: 0x7feb519ada86 - std[4337b1e3d1c66af6]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[e51f6499da6a94b9]::run_compiler::{closure#0}>::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>>::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>> 39: 0x7feb519ad8b3 - <::spawn_unchecked_, rustc_driver_impl[e51f6499da6a94b9]::run_compiler::{closure#0}>::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>>::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cc6cd760d986f799]::result::Result<(), rustc_span[ecf473d7733698d2]::ErrorGuaranteed>>::{closure#1} as core[cc6cd760d986f799]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 40: 0x7feb52fbc675 - as core::ops::function::FnOnce>::call_once::hc4b9a6efba849e51 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/alloc/src/boxed.rs:2015:9 41: 0x7feb52fbc675 - as core::ops::function::FnOnce>::call_once::hc525ee5ac423ddcd at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/alloc/src/boxed.rs:2015:9 42: 0x7feb52fbc675 - std::sys::pal::unix::thread::Thread::new::thread_start::h31b81f67226864c0 at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys/pal/unix/thread.rs:108:17 43: 0x7feb4ce9b9eb - 44: 0x7feb4cf1f7cc - 45: 0x0 - 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.77.0-nightly (bf3c6c5be 2024-02-01) running on x86_64-unknown-linux-gnu query stack during panic: #0 [live_symbols_and_ignored_derived_traits] finding live symbols in crate #1 [check_mod_deathness] checking deathness of variables in top-level module #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors; 1 warning emitted ```

matthiaskrgr commented 8 months ago

Bisects to nightly-2023-06-02

commit[0] 2023-05-31: Auto merge of #111913 - oli-obk:valtrees2, r=lcnr commit[1] 2023-05-31: Auto merge of #110807 - petrochenkov:strictflavor, r=lqd,wesleywiser commit[2] 2023-06-01: Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naber commit[3] 2023-06-01: Auto merge of #103877 - oli-obk:const_eval_step_limit, r=fee1-dead commit[4] 2023-06-01: Auto merge of #112164 - Dylan-DPC:rollup-93zj7jw, r=Dylan-DPC commit[5] 2023-06-01: Auto merge of #112002 - saethlin:enable-sroa, r=oli-obk,scottmcm commit[6] 2023-06-01: Auto merge of #112040 - cjgillot:separate-const-switch, r=oli-obk commit[7] 2023-06-01: Auto merge of #111660 - Kobzol:try-build-skip-docs, r=mark-simulacrum

ERROR: no CI builds available between 871b5952023139738f72eba235063575062bc2e9 and d59363ad0b6391b7fc5bbb02c9ccf9300eef3753 within last 167 days

fmease commented 8 months ago

Minimized:

fn main() {
    [(); loop {}].field;
}
fmease commented 8 months ago

Very likely #103877 btw.