Skip to content

ICE: rustc_privacy None #122736

Closed
Closed

Description

@matthiaskrgr

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:

// 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<T: Copy>(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<T> Foo for T {
    fn foo(&self) -> usize {
        mem::size_of::<T>()
    }
}

#[allow(unused_tuple_struct_fields)]
struct S<T:?Sized>(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 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::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::<alloc[2df66dffbcd8682a]::boxed::Box<rustc_driver_impl[132c5521347d09be]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x75146e968150 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::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 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  21:     0x75146c714da3 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  22:     0x75146c714c61 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  23:     0x75146c714e62 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  24:     0x75146c714d43 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  25:     0x75146c714d43 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  26:     0x75146c714bd5 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_block
  27:     0x75146c714ca2 - <rustc_privacy[e89e02ad47920f63]::NamePrivacyVisitor as rustc_hir[d482c373cc8be1bf]::intravisit::Visitor>::visit_expr
  28:     0x75146c719670 - rustc_privacy[e89e02ad47920f63]::check_mod_privacy
  29:     0x75146c71949d - rustc_query_impl[20c702b76dd22262]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[20c702b76dd22262]::query_impl::check_mod_privacy::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb1d9e4622d2efcc]::query::erase::Erased<[u8; 0usize]>>
  30:     0x75146d04f53a - rustc_query_system[2efa5914e4e1b8c1]::query::plumbing::try_execute_query::<rustc_query_impl[20c702b76dd22262]::DynamicConfig<rustc_query_system[2efa5914e4e1b8c1]::query::caches::DefaultCache<rustc_span[a24a661074ce7508]::def_id::LocalModDefId, rustc_middle[fb1d9e4622d2efcc]::query::erase::Erased<[u8; 0usize]>>, 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::<rustc_query_impl[20c702b76dd22262]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb1d9e4622d2efcc]::query::erase::Erased<[u8; 1usize]>>
  34:     0x75146d49c722 - rustc_query_system[2efa5914e4e1b8c1]::query::plumbing::try_execute_query::<rustc_query_impl[20c702b76dd22262]::DynamicConfig<rustc_query_system[2efa5914e4e1b8c1]::query::caches::SingleCache<rustc_middle[fb1d9e4622d2efcc]::query::erase::Erased<[u8; 1usize]>>, 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::<core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>, rustc_driver_impl[132c5521347d09be]::run_compiler::{closure#0}>::{closure#0}
  37:     0x75146d388f85 - std[fdd4e820593ddcc8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1343a98e27f77021]::util::run_in_thread_with_globals<rustc_interface[1343a98e27f77021]::util::run_in_thread_pool_with_globals<rustc_interface[1343a98e27f77021]::interface::run_compiler<core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>, 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 - <<std[fdd4e820593ddcc8]::thread::Builder>::spawn_unchecked_<rustc_interface[1343a98e27f77021]::util::run_in_thread_with_globals<rustc_interface[1343a98e27f77021]::util::run_in_thread_pool_with_globals<rustc_interface[1343a98e27f77021]::interface::run_compiler<core[b054aef7cc5b0c6f]::result::Result<(), rustc_span[a24a661074ce7508]::ErrorGuaranteed>, 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 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h83b1cb39d37379a2
                               at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/alloc/src/boxed.rs:2015:9
  40:     0x75146e971919 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::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 - <unknown>
  43:     0x75146e78ea3c - <unknown>
  44:                0x0 - <unknown>

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


Activity

  1. added
    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.
    C-bugCategory: This is a bug.
    on Mar 19, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 19, 2024
  3. matthiaskrgr commented on Mar 19, 2024

    @matthiaskrgr
    MemberAuthor

    this bisects to #121669

  4. added
    A-visibilityArea: Visibility / privacy
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 21, 2024
  5. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Apr 15, 2024
  6. added a commit that references this issue on Jun 17, 2024
  7. added a commit that references this issue on Jun 17, 2024
  8. added a commit that references this issue on Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions