rust-lang / rust

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

Regression from 1.61 to 1.62 #98932

Closed 0xdeafbeef closed 2 years ago

0xdeafbeef commented 2 years ago

Code

cd $(mktemp -d) &&  git clone https://github.com/broxus/ton-indexer.git && cd ton-indexer && git checkout c17e57d00f3e881ad32c867094edb738b5e47b5a && cargo check

Meta

rustc --version --verbose:

rustc 1.62.0 (a8314ef7d 2022-06-27)
binary: rustc
commit-hash: a8314ef7d0ec7b75c336af2c9857bfaf43002bfc
commit-date: 2022-06-27
host: x86_64-unknown-linux-gnu
release: 1.62.0
LLVM version: 14.0.5

Error output

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:810:36: cannot convert `ReEarlyBound(1, '_)` to a region vid
Backtrace

``` error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:810:36: cannot convert `ReEarlyBound(1, '_)` to a region vid thread 'rustc' panicked at 'Box', /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/compiler/rustc_errors/src/lib.rs:1335:9 stack backtrace: 0: 0x7fbb88e9dfed - std::backtrace_rs::backtrace::libunwind::trace::hb729d9642bb971eb at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7fbb88e9dfed - std::backtrace_rs::backtrace::trace_unsynchronized::h373bb774579df5c7 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fbb88e9dfed - std::sys_common::backtrace::_print_fmt::hfbd4e92d240c89bb at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:66:5 3: 0x7fbb88e9dfed - ::fmt::h8f618991fbf64972 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:45:22 4: 0x7fbb88ef9c7c - core::fmt::write::hc69b5b640d88cce8 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/fmt/mod.rs:1196:17 5: 0x7fbb88e8f6c1 - std::io::Write::write_fmt::h3403cef06a24a303 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/io/mod.rs:1654:15 6: 0x7fbb88ea0d05 - std::sys_common::backtrace::_print::h368f27cdedea0e52 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:48:5 7: 0x7fbb88ea0d05 - std::sys_common::backtrace::print::ha105c9cf5a64cd17 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys_common/backtrace.rs:35:9 8: 0x7fbb88ea0d05 - std::panicking::default_hook::{{closure}}::h48ed2c3707d5e20e at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:295:22 9: 0x7fbb88ea0979 - std::panicking::default_hook::h8744fc5cea5e3110 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:314:9 10: 0x7fbb896e9961 - rustc_driver[cc15f272104f8c81]::DEFAULT_HOOK::{closure#0}::{closure#0} 11: 0x7fbb78609683 - as core::ops::function::Fn>::call::hf270ccd282d441e1 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/alloc/src/boxed.rs:1886:9 12: 0x7fbb786371cd - proc_macro::bridge::client::::enter::{{closure}}::{{closure}}::h47be12298b431f57 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/proc_macro/src/bridge/client.rs:335:21 13: 0x7fbb88ea14d6 - std::panicking::rust_panic_with_hook::hc82286af2030e925 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:702:17 14: 0x7fbb8a763e61 - std[62a6aef941a414a5]::panicking::begin_panic::::{closure#0} 15: 0x7fbb8a75e3b6 - std[62a6aef941a414a5]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7fbb8a6f3dc6 - std[62a6aef941a414a5]::panicking::begin_panic:: 17: 0x7fbb8a6ab536 - std[62a6aef941a414a5]::panic::panic_any:: 18: 0x7fbb8a6a4c75 - ::bug::<&alloc[678093063b977939]::string::String> 19: 0x7fbb8a6a4680 - ::bug::<&alloc[678093063b977939]::string::String> 20: 0x7fbb8a76c7ad - rustc_middle[2b9dbf3985a9058b]::ty::context::tls::with_opt::::{closure#0}, ()> 21: 0x7fbb8a76cb26 - rustc_middle[2b9dbf3985a9058b]::util::bug::opt_span_bug_fmt:: 22: 0x7fbb8a76caa3 - rustc_middle[2b9dbf3985a9058b]::util::bug::bug_fmt 23: 0x7fbb8af30451 - ::convert_all 24: 0x7fbb8af58e8b - ::fully_perform_op::<(), rustc_middle[2b9dbf3985a9058b]::ty::ParamEnvAnd> 25: 0x7fbb8af41e6c - rustc_borrowck[c373a10a95822b25]::type_check::type_check 26: 0x7fbb8af1deec - rustc_borrowck[c373a10a95822b25]::nll::compute_regions 27: 0x7fbb8af8babe - rustc_borrowck[c373a10a95822b25]::do_mir_borrowck 28: 0x7fbb8af84749 - rustc_borrowck[c373a10a95822b25]::mir_borrowck 29: 0x7fbb8af814b0 - >::call_once 30: 0x7fbb8bc16cc0 - >::with_task:: 31: 0x7fbb8b1b3761 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 32: 0x7fbb8b17e3ea - ::mir_borrowck 33: 0x7fbb8b61e831 - ::mir_borrowck_opt_const_arg 34: 0x7fbb8ab250f7 - rustc_mir_transform[34692f6d13108f5a]::mir_drops_elaborated_and_const_checked 35: 0x7fbb8bc0b23c - >::with_task::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal> 36: 0x7fbb8b1a01a6 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal>> 37: 0x7fbb8b17cf28 - ::mir_drops_elaborated_and_const_checked 38: 0x7fbb8b91d286 - rustc_mir_transform[34692f6d13108f5a]::inner_mir_for_ctfe 39: 0x7fbb8b91cafc - rustc_mir_transform[34692f6d13108f5a]::mir_for_ctfe 40: 0x7fbb8bc22e87 - >::with_task:: 41: 0x7fbb8b1c33ec - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 42: 0x7fbb8bcff2bc - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::get_query:: 43: 0x7fbb8bb8120f - >::load_mir 44: 0x7fbb8b0cbcab - rustc_const_eval[654e2017a2411b4b]::const_eval::eval_queries::eval_to_allocation_raw_provider 45: 0x7fbb8bc09c49 - >::with_task::, core[6724bec812d80be0]::result::Result> 46: 0x7fbb8b19cab7 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, core[6724bec812d80be0]::result::Result>> 47: 0x7fbb8b17e533 - ::eval_to_allocation_raw 48: 0x7fbb8b0caad4 - rustc_const_eval[654e2017a2411b4b]::const_eval::eval_queries::eval_to_const_value_raw_provider 49: 0x7fbb8bc0a1f9 - >::with_task::, core[6724bec812d80be0]::result::Result> 50: 0x7fbb8b19dc4e - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, core[6724bec812d80be0]::result::Result>> 51: 0x7fbb8b17e6e0 - ::eval_to_const_value_raw 52: 0x7fbb8b0ca842 - rustc_const_eval[654e2017a2411b4b]::const_eval::eval_queries::eval_to_const_value_raw_provider 53: 0x7fbb8bc0a1f9 - >::with_task::, core[6724bec812d80be0]::result::Result> 54: 0x7fbb8b19dc4e - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, core[6724bec812d80be0]::result::Result>> 55: 0x7fbb8b17e6e0 - ::eval_to_const_value_raw 56: 0x7fbb8b60d475 - ::const_eval_global_id 57: 0x7fbb8bf87179 - ::const_eval_resolve 58: 0x7fbb8a63e71a - rustc_middle[2b9dbf3985a9058b]::ty::relate::super_relate_consts:: 59: 0x7fbb8a61b7c3 - ::super_combine_consts:: 60: 0x7fbb8b545107 - rustc_middle[2b9dbf3985a9058b]::ty::relate::super_relate_tys:: 61: 0x7fbb8b527127 - ::super_combine_tys:: 62: 0x7fbb8b544e92 - rustc_middle[2b9dbf3985a9058b]::ty::relate::super_relate_tys:: 63: 0x7fbb8b59fbbc - ::tys 64: 0x7fbb8b49709e - rustc_trait_selection[5d73681df2441a7c]::traits::project::project_and_unify_type 65: 0x7fbb8b4c594f - ::process_changed_obligations 66: 0x7fbb8b4eb787 - >::process_obligations::> 67: 0x7fbb8b4c2df1 - ::select_where_possible 68: 0x7fbb8ab94129 - ::type_inference_fallback 69: 0x7fbb8ac3730d - ::enter::<&rustc_middle[2b9dbf3985a9058b]::ty::context::TypeckResults, ::enter::{closure#1}, &rustc_middle[2b9dbf3985a9058b]::ty::context::TypeckResults>::{closure#0}> 70: 0x7fbb8abf6fe0 - rustc_typeck[9a0dbd9e1b6c9fb9]::check::typeck 71: 0x7fbb8bc162c0 - >::with_task:: 72: 0x7fbb8b1b2786 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 73: 0x7fbb8b17e178 - ::typeck 74: 0x7fbb8b61e2a2 - ::typeck_opt_const_arg 75: 0x7fbb8ae3ce7a - rustc_mir_build[47e1d63702a692cd]::build::mir_built 76: 0x7fbb8bc0b23c - >::with_task::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal> 77: 0x7fbb8b1a01a6 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal>> 78: 0x7fbb8b17cb25 - ::mir_built 79: 0x7fbb8ab349ce - rustc_mir_transform[34692f6d13108f5a]::check_unsafety::unsafety_check_result 80: 0x7fbb8ab2c1b0 - >::call_once 81: 0x7fbb8bc171c0 - >::with_task:: 82: 0x7fbb8b1b47a6 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 83: 0x7fbb8b17dd7e - ::unsafety_check_result 84: 0x7fbb8ab22e4f - rustc_mir_transform[34692f6d13108f5a]::mir_const 85: 0x7fbb8bc0b23c - >::with_task::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal> 86: 0x7fbb8b1a01a6 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal>> 87: 0x7fbb8b17cc5c - ::mir_const 88: 0x7fbb8ab24985 - rustc_mir_transform[34692f6d13108f5a]::mir_promoted 89: 0x7fbb8bc0b75b - >::with_task::, (&rustc_data_structures[e6d5a572b4e9612f]::steal::Steal, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal>)> 90: 0x7fbb8b1a16ce - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::, (&rustc_data_structures[e6d5a572b4e9612f]::steal::Steal, &rustc_data_structures[e6d5a572b4e9612f]::steal::Steal>)>> 91: 0x7fbb8b17d074 - ::mir_promoted 92: 0x7fbb8af843f9 - rustc_borrowck[c373a10a95822b25]::mir_borrowck 93: 0x7fbb8af814b0 - >::call_once 94: 0x7fbb8bc16cc0 - >::with_task:: 95: 0x7fbb8b1b3761 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 96: 0x7fbb8b17e3ea - ::mir_borrowck 97: 0x7fbb8acce506 - rustc_typeck[9a0dbd9e1b6c9fb9]::collect::type_of::type_of 98: 0x7fbb8b14b8b7 - >::with_task:: 99: 0x7fbb8b1f9f0a - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::get_query:: 100: 0x7fbb8acbf442 - rustc_typeck[9a0dbd9e1b6c9fb9]::check::check::check_item_type 101: 0x7fbb8acc433b - rustc_typeck[9a0dbd9e1b6c9fb9]::check::check::check_mod_item_types 102: 0x7fbb8bc17baf - >::with_task:: 103: 0x7fbb8b1b578e - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::> 104: 0x7fbb8bd06f83 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::get_query:: 105: 0x7fbb8ba1c95d - ::for_each_module:: 106: 0x7fbb8b9e8138 - ::time::<(), rustc_typeck[9a0dbd9e1b6c9fb9]::check_crate::{closure#6}> 107: 0x7fbb8b9db748 - rustc_typeck[9a0dbd9e1b6c9fb9]::check_crate 108: 0x7fbb8b7844d7 - rustc_interface[a10bc87377f6ea4]::passes::analysis 109: 0x7fbb8bc2f3b5 - >::with_task::> 110: 0x7fbb8bcd4ca1 - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::try_execute_query::>> 111: 0x7fbb8bd15fbe - rustc_query_system[a16ac1cefdea5f76]::query::plumbing::get_query:: 112: 0x7fbb8b764f97 - ::enter::> 113: 0x7fbb8b74ffe8 - ::enter::, rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>> 114: 0x7fbb8b7786ef - rustc_span[aeddd698d19619f]::with_source_map::, rustc_interface[a10bc87377f6ea4]::interface::create_compiler_and_run, rustc_driver[cc15f272104f8c81]::run_compiler::{closure#1}>::{closure#1}> 115: 0x7fbb8b764024 - rustc_interface[a10bc87377f6ea4]::interface::create_compiler_and_run::, rustc_driver[cc15f272104f8c81]::run_compiler::{closure#1}> 116: 0x7fbb8b74e4f2 - >::set::, rustc_driver[cc15f272104f8c81]::run_compiler::{closure#1}>::{closure#0}, core[6724bec812d80be0]::result::Result<(), rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>> 117: 0x7fbb8b76561f - std[62a6aef941a414a5]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[cc15f272104f8c81]::run_compiler::{closure#1}>::{closure#0}, core[6724bec812d80be0]::result::Result<(), rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>>::{closure#0}, core[6724bec812d80be0]::result::Result<(), rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>> 118: 0x7fbb8b765759 - <::spawn_unchecked_, rustc_driver[cc15f272104f8c81]::run_compiler::{closure#1}>::{closure#0}, core[6724bec812d80be0]::result::Result<(), rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>>::{closure#0}, core[6724bec812d80be0]::result::Result<(), rustc_errors[7cc8b2502942d635]::ErrorGuaranteed>>::{closure#1} as core[6724bec812d80be0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 119: 0x7fbb88eab3f3 - as core::ops::function::FnOnce>::call_once::hcbca3baf872b7fe4 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/alloc/src/boxed.rs:1872:9 120: 0x7fbb88eab3f3 - as core::ops::function::FnOnce>::call_once::h18790338ce1743e2 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/alloc/src/boxed.rs:1872:9 121: 0x7fbb88eab3f3 - std::sys::unix::thread::Thread::new::thread_start::hb1067183bad48893 at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/sys/unix/thread.rs:108:17 122: 0x7fbb88c8054d - 123: 0x7fbb88d05874 - clone 124: 0x0 - note: the compiler unexpectedly panicked. this is a bug. 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.62.0 (a8314ef7d 2022-06-27) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [mir_borrowck] borrow-checking `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` #1 [mir_drops_elaborated_and_const_checked] elaborating drops for `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` #2 [mir_for_ctfe] caching mir of `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` for CTFE #3 [eval_to_allocation_raw] const-evaluating + checking `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` #4 [eval_to_const_value_raw] simplifying constant for the type system `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` #5 [eval_to_const_value_raw] simplifying constant for the type system `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}::{constant#0}` #6 [typeck] type-checking `db::shard_state_storage::entries_buffer::::iter_child_buffers` #7 [mir_built] building MIR for `db::shard_state_storage::entries_buffer::::iter_child_buffers` #8 [unsafety_check_result] unsafety-checking `db::shard_state_storage::entries_buffer::::iter_child_buffers` #9 [mir_const] processing MIR for `db::shard_state_storage::entries_buffer::::iter_child_buffers` #10 [mir_promoted] processing `db::shard_state_storage::entries_buffer::::iter_child_buffers` #11 [mir_borrowck] borrow-checking `db::shard_state_storage::entries_buffer::::iter_child_buffers` #12 [type_of] computing type of `db::shard_state_storage::entries_buffer::::iter_child_buffers::{opaque#0}` #13 [check_mod_item_types] checking item types in module `db::shard_state_storage::entries_buffer` #14 [analysis] running analysis passes on this crate end of query stack ```

0xdeafbeef commented 2 years ago

Mre:

pub struct EntriesBuffer(Box<[[u8; HashesEntry::LEN]; 5]>);

impl EntriesBuffer {
    pub fn new() -> Self {
        Self(Box::new([[0; HashesEntry::LEN]; 5]))
    }

    pub fn current_entry_buffer(&mut self) -> &mut [u8; HashesEntry::LEN] {
        &mut self.0[0]
    }

    pub fn iter_child_buffers(&mut self) -> impl Iterator<Item = &mut [u8; HashesEntry::LEN]> {
        self.0.iter_mut().skip(1)
    }

    pub fn split_children<'a, 'b>(
        &'a mut self,
        references: &'b [u32],
    ) -> (HashesEntryWriter<'a>, EntriesBufferChildren<'b>)
    where
        'a: 'b,
    {
        let [first, tail @ ..] = &mut *self.0;
        (
            HashesEntryWriter(first),
            EntriesBufferChildren(references, tail),
        )
    }
}

pub struct EntriesBufferChildren<'a>(&'a [u32], &'a [[u8; HashesEntry::LEN]]);

impl EntriesBufferChildren<'_> {
    pub fn iter(&self) -> impl Iterator<Item = (&u32, HashesEntry)> {
        self.0
            .iter()
            .zip(self.1)
            .map(|(index, item)| (index, HashesEntry(item)))
    }
}

pub struct HashesEntryWriter<'a>(&'a mut [u8]);

impl HashesEntryWriter<'_> {
    pub fn as_reader(&self) -> HashesEntry {
        HashesEntry(self.0)
    }

    pub fn clear(&mut self) {
        for byte in &mut *self.0 {
            *byte = 0;
        }
    }

    pub fn set_tree_bits_count(&mut self, count: u64) {
        self.0[4..12].copy_from_slice(&count.to_le_bytes());
    }

    pub fn set_tree_cell_count(&mut self, count: u64) {
        self.0[12..20].copy_from_slice(&count.to_le_bytes());
    }

    pub fn get_tree_counters(&mut self) -> &[u8] {
        &self.0[4..20]
    }

    pub fn set_hash(&mut self, i: u8, hash: &[u8]) {
        self.get_hash_slice(i).copy_from_slice(hash);
    }

    pub fn get_hash_slice(&mut self, i: u8) -> &mut [u8] {
        let offset = HashesEntry::HASHES_OFFSET + 32 * i as usize;
        &mut self.0[offset..offset + 32]
    }

    pub fn set_depth(&mut self, i: u8, depth: u16) {
        self.get_depth_slice(i)
            .copy_from_slice(&depth.to_le_bytes());
    }

    pub fn get_depth_slice(&mut self, i: u8) -> &mut [u8] {
        let offset = HashesEntry::DEPTHS_OFFSET + 2 * i as usize;
        &mut self.0[offset..offset + 2]
    }
}

pub struct HashesEntry<'a>(&'a [u8]);

impl<'a> HashesEntry<'a> {
    // 4 bytes - info (1 byte level mask, 1 byte cell type, 2 bytes padding)
    // 8 bytes - tree bits count
    // 4 bytes - cell count
    // 32 * 4 bytes - hashes
    // 2 * 4 bytes - depths
    pub const LEN: usize = 4 + 8 + 8 + 32 * 4 + 2 * 4;
    pub const HASHES_OFFSET: usize = 4 + 8 + 8;
    pub const DEPTHS_OFFSET: usize = 4 + 8 + 8 + 32 * 4;

    pub fn tree_bits_count(&self) -> u64 {
        u64::from_le_bytes(self.0[4..12].try_into().unwrap())
    }

    pub fn tree_cell_count(&self) -> u64 {
        u64::from_le_bytes(self.0[12..20].try_into().unwrap())
    }

    pub fn hash(&self, n: u8) -> &[u8] {
        let offset = Self::HASHES_OFFSET + 32 * self.level_mask().calc_hash_index(n as usize);
        &self.0[offset..offset + 32]
    }

    pub fn depth(&self, n: u8) -> u16 {
        let offset = Self::DEPTHS_OFFSET + 2 * self.level_mask().calc_hash_index(n as usize);
        u16::from_le_bytes([self.0[offset], self.0[offset + 1]])
    }

    pub fn pruned_branch_hash<'b>(&self, n: u8, data: &'b [u8]) -> &'b [u8]
    where
        'a: 'b,
    {
        let level_mask = self.level_mask();
        let index = level_mask.calc_hash_index(n as usize);
        let level = level_mask.level() as usize;

        if index == level {
            let offset = Self::HASHES_OFFSET;
            &self.0[offset..offset + 32]
        } else {
            let offset = 1 + 1 + index * 32;
            &data[offset..offset + 32]
        }
    }

    pub fn pruned_branch_depth(&self, n: u8, data: &[u8]) -> u16 {
        let level_mask = self.level_mask();
        let index = level_mask.calc_hash_index(n as usize);
        let level = level_mask.level() as usize;

        if index == level {
            let offset = Self::DEPTHS_OFFSET;
            u16::from_le_bytes([self.0[offset], self.0[offset + 1]])
        } else {
            let offset = 1 + 1 + level * 32 + index * 2;
            u16::from_be_bytes([data[offset], data[offset + 1]])
        }
    }
}

searched nightlies: from nightly-2022-04-15 to nightly-2022-05-02 regressed nightly: nightly-2022-05-01 searched commit range: https://github.com/rust-lang/rust/compare/a707f401074bc769bab4efb2bfdde7f6c5a4068d...7c4b47696907d64eff5621a64eb3c6e795a9ec77 regressed commit: https://github.com/rust-lang/rust/commit/76d4862fdd131b6f79dc0a31857f888d26bcdb27

bisected with cargo-bisect-rustc v0.6.3 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --test-dir=. --start=2022-04-15 --end=2022-05-02 ```
apiraino commented 2 years ago

WG-prioritization assigning priority (Zulip discussion). Tagging PR #95776

@rustbot label -I-prioritize +P-medium

apiraino commented 2 years ago

Before the regression, the sample code reported a compile error:

error summary ```sh ~/tmp/issue-98932$ cargo +nightly-2022-04-15-x86_64-unknown-linux-gnu check Checking issue-98932 v0.1.0 (~/tmp/issue-98932) error[E0599]: no method named `level_mask` found for reference `&HashesEntry<'a>` in the current scope --> src/main.rs:108:54 | 108 | let offset = Self::HASHES_OFFSET + 32 * self.level_mask().calc_hash_index(n as usize); | ^^^^^^^^^^ method not found in `&HashesEntry<'a>` error[E0599]: no method named `level_mask` found for reference `&HashesEntry<'a>` in the current scope --> src/main.rs:113:53 | 113 | let offset = Self::DEPTHS_OFFSET + 2 * self.level_mask().calc_hash_index(n as usize); | ^^^^^^^^^^ method not found in `&HashesEntry<'a>` error[E0599]: no method named `level_mask` found for reference `&HashesEntry<'a>` in the current scope --> src/main.rs:121:31 | 121 | let level_mask = self.level_mask(); | ^^^^^^^^^^ method not found in `&HashesEntry<'a>` error[E0599]: no method named `level_mask` found for reference `&HashesEntry<'a>` in the current scope --> src/main.rs:135:31 | 135 | let level_mask = self.level_mask(); | ^^^^^^^^^^ method not found in `&HashesEntry<'a>` For more information about this error, try `rustc --explain E0599`. error: could not compile `issue-98932` due to 4 previous errors ```
lqd commented 2 years ago

so the ICE is from #95776, cc PR author @cjgillot

Rexagon commented 2 years ago

Slightly smaller example which successfully compiles on 1.61 and failed with ICE on 1.62:

pub struct EntriesBuffer(Box<[[u8; HashesEntry::LEN]; 5]>);

impl EntriesBuffer {
    pub fn iter_child_buffers(&mut self) -> impl Iterator<Item = &mut [u8; HashesEntry::LEN]> {
        self.0.iter_mut()
    }

//     Compiles successfully if `'static` lifetime is specified:
//
//     pub fn iter_child_buffers(&mut self) -> impl Iterator<Item = &mut [u8; HashesEntry::<'static>::LEN]> {
//        self.0.iter_mut()
//    }
}

pub struct HashesEntry<'a>(&'a [u8]);

impl HashesEntry<'_> {
    pub const LEN: usize = 1;
}