rust-lang / rust

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

ICE: rustc_privacy `None` #122736

Closed matthiaskrgr closed 4 months ago

matthiaskrgr commented 7 months ago

auto-reduced (treereduce-rust):

fn main_ref() {
    let array = [(); {
        let mut x = &0;
        let mut n = 0;
        while n < 5 {
            x = &0;
        }
        0
    }];

    let mut ptrs: Vec<*const [u8]> = vec![&array[0..0], &array[0..1], &array, &array[1..]];
}

fn main() {}
original code

original: ````rust // run-pass // check raw fat pointer ops in mir // FIXME: please improve this when we get monomorphization support #![feature(raw_ref_op)] use std::mem; #[derive(Debug, PartialEq, Eq)] struct ComparisonResults { lt: bool, le: bool, gt: bool, ge: bool, eq: bool, ne: bool } const LT: ComparisonResults = ComparisonResults { lt: true, le: true, gt: false, ge: false, eq: false, ne: true }; const EQ: ComparisonResults = ComparisonResults { lt: false, le: true, gt: false, ge: true, eq: true, ne: false }; const GT: ComparisonResults = ComparisonResults { lt: false, le: false, gt: true, ge: true, eq: false, ne: true }; fn compare_su8(a: *const S<[u8]>, b: *const S<[u8]>) -> ComparisonResults { ComparisonResults { lt: a < b, le: a <= b, gt: a > b, ge: a >= b, eq: a == b, ne: a != b } } fn compare_au8(a: *const [u8], b: *const [u8]) -> ComparisonResults { ComparisonResults { lt: a < b, le: a <= b, gt: a > b, ge: a >= b, eq: a == b, ne: a != b } } fn compare_foo<'a>(a: *const (dyn Foo+'a), b: *const (dyn Foo+'a)) -> ComparisonResults { ComparisonResults { lt: a < b, le: a <= b, gt: a > b, ge: a >= b, eq: a == b, ne: a != b } } fn simple_eq<'a>(a: *const (dyn Foo+'a), b: *const (dyn Foo+'a)) -> bool { let result = a == b; result } fn assert_inorder(a: &[T], compare: fn(T, T) -> ComparisonResults) { for i in 0..a.len() { for j in 0..a.len() { let cres = compare(a[i], a[j]); if i < j { assert_eq!(cres, LT); } else if i == j { assert_eq!(cres, EQ); } else { assert_eq!(cres, GT); } } } } trait Foo { fn foo(&self) -> usize; } impl Foo for T { fn foo(&self) -> usize { mem::size_of::() } } #[allow(unused_tuple_struct_fields)] struct S(u32, T); fn main_ref() { let array = [(); { let mut x = &0; let mut n = 0; while n < 5 { //~ ERROR evaluation of constant value failed [E0080] n = (n + 1) % 5; x = &0; // Materialize a new AllocId } 0 }]; let array2 = [5,6,7,8,9]; // fat ptr comparison: addr then extra // check ordering for arrays let mut ptrs: Vec<*const [u8]> = vec![ &array[0..0], &array[0..1], &array, &array[1..] ]; let array_addr = &array as *const [u8] as *const u8 as usize; let array2_addr = &array2 as *const [u8] as *const u8 as usize; if array2_addr < array_addr { ptrs.insert(0, &array2); } else { ptrs.push(&array2); } assert_inorder(&ptrs, compare_au8); let u8_ = (0u8, 1u8); let u32_ = (4u32, 5u32); // check ordering for ptrs let buf: &mut [*const dyn Foo] = &mut [ &u8_, &u8_.0, &u32_, &u32_.0, ]; buf.sort_by(|u,v| { let u : [*const (); 2] = unsafe { mem::transmute(*u) }; let v : [*const (); 2] = unsafe { mem::transmute(*v) }; u.cmp(&v) }); assert_inorder(buf, compare_foo); // check ordering for structs containing arrays let ss: (S<[u8; 2]>, S<[u8; 3]>, S<[u8; 2]>) = ( S(7, [8, 9]), S(10, [11, 12, 13]), S(4, [5, 6]) ); assert_inorder(&[ &ss.0 as *const S<[u8]>, &ss.1 as *const S<[u8]>, &ss.2 as *const S<[u8]> ], compare_su8); assert!(!simple_eq(&0u8 as *const _, &1u8 as *const _)); assert!(!simple_eq(&0u8 as *const _, &1u8 as *const _)); } // similar to above, but using &raw fn main_raw() { let array = [0,1,2,3,4]; let array2 = [5,6,7,8,9]; // fat ptr comparison: addr then extra // check ordering for arrays let mut ptrs: Vec<*const [u8]> = vec![ &raw const array[0..0], &raw const array[0..1], &raw const array, &raw const array[1..] ]; let array_addr = &raw const array as *const u8 as usize; let array2_addr = &raw const array2 as *const u8 as usize; if array2_addr < array_addr { ptrs.insert(0, &raw const array2); } else { ptrs.push(&raw const array2); } assert_inorder(&ptrs, compare_au8); let u8_ = (0u8, 1u8); let u32_ = (4u32, 5u32); // check ordering for ptrs let buf: &mut [*const dyn Foo] = &mut [ &raw const u8_, &raw const u8_.0, &raw const u32_, &raw const u32_.0, ]; buf.sort_by(|u,v| { let u : [*const (); 2] = unsafe { mem::transmute(*u) }; let v : [*const (); 2] = unsafe { mem::transmute(*v) }; u.cmp(&v) }); assert_inorder(buf, compare_foo); // check ordering for structs containing arrays let ss: (S<[u8; 2]>, S<[u8; 3]>, S<[u8; 2]>) = ( S(7, [8, 9]), S(10, [11, 12, 13]), S(4, [5, 6]) ); assert_inorder(&[ &raw const ss.0 as *const S<[u8]>, &raw const ss.1 as *const S<[u8]>, &raw const ss.2 as *const S<[u8]> ], compare_su8); } fn main() { main_ref(); main_raw(); } ````

Version information

rustc 1.79.0-nightly (3c85e5624 2024-03-18)
binary: rustc
commit-hash: 3c85e56249b0b1942339a6a989a971bf6f1c9e0f
commit-date: 2024-03-18
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

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

Program output

``` warning: variable `x` is assigned to, but never used --> /tmp/icemaker_global_tempdir.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:3:17 | 3 | let mut x = &0; | ^ | = note: consider using `_x` instead = note: `#[warn(unused_variables)]` on by default warning: value assigned to `x` is never read --> /tmp/icemaker_global_tempdir.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:6:13 | 6 | x = &0; | ^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default warning: variable does not need to be mutable --> /tmp/icemaker_global_tempdir.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:4:13 | 4 | let mut n = 0; | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default error: constant evaluation is taking a long time --> /tmp/icemaker_global_tempdir.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:5:9 | 5 | / while n < 5 { 6 | | x = &0; 7 | | } | |_________^ | = 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.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:2:22 | 2 | let array = [(); { | ______________________^ 3 | | let mut x = &0; 4 | | let mut n = 0; 5 | | while n < 5 { ... | 8 | | 0 9 | | }]; | |_____^ = note: `#[deny(long_running_const_eval)]` on by default warning: function `main_ref` is never used --> /tmp/icemaker_global_tempdir.aUyclLrLIXh2/rustc_testrunner_tmpdir_reporting.Vi8I0O53b4WC/mvce.rs:1:4 | 1 | fn main_ref() { | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default thread 'rustc' panicked at compiler/rustc_privacy/src/lib.rs:980:72: called `Option::unwrap()` on a `None` value stack backtrace: 0: 0x75146e964fa5 - std::backtrace_rs::backtrace::libunwind::trace::hf224218f29288101 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x75146e964fa5 - std::backtrace_rs::backtrace::trace_unsynchronized::h954201e62d9ea565 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x75146e964fa5 - std::sys_common::backtrace::_print_fmt::hea3a677181f12a58 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys_common/backtrace.rs:68:5 3: 0x75146e964fa5 - ::fmt::h6e9e5b34e60fa104 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys_common/backtrace.rs:44:22 4: 0x75146e9b5feb - core::fmt::rt::Argument::fmt::h0ebabaae160cfd48 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/fmt/rt.rs:142:9 5: 0x75146e9b5feb - core::fmt::write::h32314e4c5702f301 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/fmt/mod.rs:1153:17 6: 0x75146e959cbf - std::io::Write::write_fmt::h55ad21cf44927bc6 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/io/mod.rs:1843:15 7: 0x75146e964d7e - std::sys_common::backtrace::_print::hc14d175d52ea8685 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys_common/backtrace.rs:47:5 8: 0x75146e964d7e - std::sys_common::backtrace::print::h2e9f3ee9c05f6fe5 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys_common/backtrace.rs:34:9 9: 0x75146e9679f9 - std::panicking::default_hook::{{closure}}::h4ff83144486f13b0 10: 0x75146e967763 - std::panicking::default_hook::h76d100cb2c96e561 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:292:9 11: 0x75146b3bbb0f - std[fdd4e820593ddcc8]::panicking::update_hook::>::{closure#0} 12: 0x75146e968150 - as core::ops::function::Fn>::call::h00b94f5357648edd at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/alloc/src/boxed.rs:2029:9 13: 0x75146e968150 - std::panicking::rust_panic_with_hook::he12f7f70ea133701 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:783:13 14: 0x75146e967e6d - std::panicking::begin_panic_handler::{{closure}}::h5b35c95f6d446a6f at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:649:13 15: 0x75146e965469 - std::sys_common::backtrace::__rust_end_short_backtrace::hbe6c642460ab2480 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys_common/backtrace.rs:171:18 16: 0x75146e967bd7 - rust_begin_unwind at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:645:5 17: 0x75146e9b2486 - core::panicking::panic_fmt::hc5df714ebf4ebfc0 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panicking.rs:72:14 18: 0x75146e9b252f - core::panicking::panic::h17cabb89c5bcc999 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panicking.rs:145:5 19: 0x75146e9b2229 - core::option::unwrap_failed::h81cbe0aee9c9acae at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/option.rs:1985:5 20: 0x75146c7156dd - ::visit_expr 21: 0x75146c714da3 - ::visit_expr 22: 0x75146c714c61 - ::visit_expr 23: 0x75146c714e62 - ::visit_expr 24: 0x75146c714d43 - ::visit_expr 25: 0x75146c714d43 - ::visit_expr 26: 0x75146c714bd5 - ::visit_block 27: 0x75146c714ca2 - ::visit_expr 28: 0x75146c719670 - rustc_privacy[e89e02ad47920f63]::check_mod_privacy 29: 0x75146c71949d - rustc_query_impl[20c702b76dd22262]::plumbing::__rust_begin_short_backtrace::> 30: 0x75146d04f53a - rustc_query_system[2efa5914e4e1b8c1]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[20c702b76dd22262]::plumbing::QueryCtxt, true> 31: 0x75146d04ef4c - rustc_query_impl[20c702b76dd22262]::query_impl::check_mod_privacy::get_query_incr::__rust_end_short_backtrace 32: 0x75146cab804c - rustc_interface[1343a98e27f77021]::passes::analysis 33: 0x75146cab7459 - rustc_query_impl[20c702b76dd22262]::plumbing::__rust_begin_short_backtrace::> 34: 0x75146d49c722 - rustc_query_system[2efa5914e4e1b8c1]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[20c702b76dd22262]::plumbing::QueryCtxt, true> 35: 0x75146d49c31c - rustc_query_impl[20c702b76dd22262]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 36: 0x75146d27f044 - rustc_interface[1343a98e27f77021]::interface::run_compiler::, rustc_driver_impl[132c5521347d09be]::run_compiler::{closure#0}>::{closure#0} 37: 0x75146d388f85 - std[fdd4e820593ddcc8]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[132c5521347d09be]::run_compiler::{closure#0}>::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>>::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>> 38: 0x75146d388db2 - <::spawn_unchecked_, rustc_driver_impl[132c5521347d09be]::run_compiler::{closure#0}>::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>>::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>>::{closure#1} as core[b054aef7cc5b0c6f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 39: 0x75146e971919 - as core::ops::function::FnOnce>::call_once::h83b1cb39d37379a2 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/alloc/src/boxed.rs:2015:9 40: 0x75146e971919 - as core::ops::function::FnOnce>::call_once::h30c4faf6a277fd1f at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/alloc/src/boxed.rs:2015:9 41: 0x75146e971919 - std::sys::pal::unix::thread::Thread::new::thread_start::hc6ac17b3f4cadbd0 at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/sys/pal/unix/thread.rs:108:17 42: 0x75146e71155a - 43: 0x75146e78ea3c - 44: 0x0 - error: the compiler unexpectedly panicked. this is a bug. note: it seems that this compiler `1.79.0-nightly (3c85e5624 2024-03-18)` is outdated, a newer nightly should have been released in the mean time | = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists = note: if the problem still persists, 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.79.0-nightly (3c85e5624 2024-03-18) running on x86_64-unknown-linux-gnu note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 query stack during panic: #0 [check_mod_privacy] checking privacy in top-level module #1 [analysis] running analysis passes on this crate end of query stack error: aborting due to 1 previous error; 4 warnings emitted ```

matthiaskrgr commented 7 months ago

this bisects to #121669