Skip to content

ICE: lazy type alias: IOOB compiler/rustc_hir_analysis/src/variance/constraints.rs #114468

Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

original code from tests/ui/issues/issue-20797.rs

// build-pass

// Regression test for #20797.

use std::default::Default;
use std::io;
use std::fs;
use std::path::PathBuf;

pub trait PathExtensions {
    fn is_dir(&self) -> bool { false }
}

impl PathExtensions for PathBuf {}

/// A strategy for acquiring more subpaths to walk.
pub trait Strategy {
    type P: PathExtensions;
    /// Gets additional subpaths from a given path.
    fn get_more(&self, item: &Self::P) -> io::Result<Vec<Self::P>>;
    /// Determine whether a path should be walked further.
    /// This is run against each item from `get_more()`.
    fn prune(&self, p: &Self::P) -> bool;
}

/// The basic fully-recursive strategy. Nothing is pruned.
#[derive(Copy, Clone, Default)]
pub struct Recursive;

impl Strategy for Recursive {
    type P = PathBuf;
    fn get_more(&self, p: &PathBuf) -> io::Result<Vec<PathBuf>> {
        Ok(fs::read_dir(p).unwrap().map(|s| s.unwrap().path()).collect())
    }

    fn prune(&self, _: &PathBuf) -> bool { false }
}

/// A directory walker of `P` using strategy `S`.
pub struct Subpaths<S: Strategy> {
    stack: Vec<S::P>,
    strategy: S,
}

impl<S: Strategy> Subpaths<S> {
    /// Creates a directory walker with a root path and strategy.
    pub fn new(p: &S::P, strategy: S) -> io::Result<Subpaths<S>> {
        let stack = strategy.get_more(p)?;
        Ok(Subpaths { stack: stack, strategy: strategy })
    }
}

impl<S: Default + Strategy> Subpaths<S> {
    /// Creates a directory walker with a root path and a default strategy.
    pub fn walk(p: &S::P) -> io::Result<Subpaths<S>> {
        Subpaths::new(p, Default::default())
    }
}

impl<S: Default + Strategy> Default for Subpaths<S> {
    fn default() -> Subpaths<S> {
        Subpaths { stack: Vec::new(), strategy: Default::default() }
    }
}

impl<S: Strategy> Iterator for Subpaths<S> {
    type Item = S::P;
    fn next (&mut self) -> Option<S::P> {
        let mut opt_path = self.stack.pop();
        while opt_path.is_some() && self.strategy.prune(opt_path.as_ref().unwrap()) {
            opt_path = self.stack.pop();
        }
        match opt_path {
            Some(path) => {
                if path.is_dir() {
                    let result = self.strategy.get_more(&path);
                    match result {
                        Ok(dirs) => { self.stack.extend(dirs); },
                        Err(..) => { }
                    }
                }
                Some(path)
            }
            None => None,
        }
    }
}

fn _foo() {
    let _walker: Subpaths<Recursive> = Subpaths::walk(&PathBuf::from("/home")).unwrap();
}

fn main() {}

reduced

#![feature(lazy_type_alias)]

use std::io;

pub trait Strategy {}

pub struct Subpaths<S: Strategy> {}

impl<S: Strategy> Subpaths<S> {
    pub fn new() -> io::Result<Subpaths<S>> {}
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (474709a9a 2023-08-03)
binary: rustc
commit-hash: 474709a9a2a74a8bcf0055fadb335d0ca0d2d939
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

<output>
Backtrace

warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
 --> treereduce.out:1:12
  |
1 | #![feature(lazy_type_alias)]
  |            ^^^^^^^^^^^^^^^
  |
  = note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `treereduce.out`

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/variance/constraints.rs:362:36:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0:     0x7f2b33b6313c - std::backtrace_rs::backtrace::libunwind::trace::h607c5cae6680b0fb
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2b33b6313c - std::backtrace_rs::backtrace::trace_unsynchronized::hc1cbea2e412d60ef
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2b33b6313c - std::sys_common::backtrace::_print_fmt::h62a9831c7ff163f5
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f2b33b6313c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf49ca0eb9dc1b6fd
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2b33bc983c - core::fmt::rt::Argument::fmt::h9cc0ab3f56c44ea1
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/core/src/fmt/rt.rs:138:9
   5:     0x7f2b33bc983c - core::fmt::write::h87aa5f2149ab03a1
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f2b33b556de - std::io::Write::write_fmt::h04dc89e115afce4f
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/io/mod.rs:1714:15
   7:     0x7f2b33b62f25 - std::sys_common::backtrace::_print::h4e2feb31096e94de
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2b33b62f25 - std::sys_common::backtrace::print::h2c16c4ace2baa3ab
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2b33b6607a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h18ad7c40aef108e0
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/panicking.rs:278:22
  10:     0x7f2b33b65d13 - std::panicking::panic_hook_with_disk_dump::hce08e9b5439b012b
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/panicking.rs:312:9
  11:     0x7f2b36e59f99 - rustc_driver_impl[2f92a0ccc46c059]::install_ice_hook::{closure#0}
  12:     0x7f2b33b66920 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h02014ddf1cce8192
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/alloc/src/boxed.rs:2021:9
  13:     0x7f2b33b66920 - std::panicking::rust_panic_with_hook::h07367ca72cc1b034
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/panicking.rs:733:13
  14:     0x7f2b33b666a7 - std::panicking::begin_panic_handler::{{closure}}::h1091911fd2e9526e
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/panicking.rs:621:13
  15:     0x7f2b33b63676 - std::sys_common::backtrace::__rust_end_short_backtrace::h6770f526fbcecfe3
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f2b33b663f2 - rust_begin_unwind
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/panicking.rs:617:5
  17:     0x7f2b33bc5bf3 - core::panicking::panic_fmt::h2ea3095a9e99667b
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/core/src/panicking.rs:67:14
  18:     0x7f2b33bc5d52 - core::panicking::panic_bounds_check::hf798c1571563a745
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/core/src/panicking.rs:162:5
  19:     0x7f2b36fbe3c3 - <rustc_hir_analysis[1f87ebcc916a8bb0]::variance::constraints::ConstraintContext>::add_constraints_from_args
  20:     0x7f2b35734c40 - <rustc_hir_analysis[1f87ebcc916a8bb0]::variance::constraints::ConstraintContext>::build_constraints_for_item
  21:     0x7f2b357337d9 - rustc_hir_analysis[1f87ebcc916a8bb0]::variance::crate_variances
  22:     0x7f2b36509694 - rustc_query_impl[49f881e28274e957]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49f881e28274e957]::query_impl::crate_variances::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7f2b36509679 - <rustc_query_impl[49f881e28274e957]::query_impl::crate_variances::dynamic_query::{closure#2} as core[71fbaba24b011fa4]::ops::function::FnOnce<(rustc_middle[1d4c141020d5ff1d]::ty::context::TyCtxt, ())>>::call_once
  24:     0x7f2b362ae62c - rustc_query_system[cfe4b6087db7ea89]::query::plumbing::try_execute_query::<rustc_query_impl[49f881e28274e957]::DynamicConfig<rustc_query_system[cfe4b6087db7ea89]::query::caches::SingleCache<rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[49f881e28274e957]::plumbing::QueryCtxt, false>
  25:     0x7f2b367bbc45 - rustc_query_impl[49f881e28274e957]::query_impl::crate_variances::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f2b35a7ef4c - rustc_hir_analysis[1f87ebcc916a8bb0]::variance::variances_of
  27:     0x7f2b34e23893 - rustc_query_impl[49f881e28274e957]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49f881e28274e957]::query_impl::variances_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 16usize]>>
  28:     0x7f2b34e23855 - <rustc_query_impl[49f881e28274e957]::query_impl::variances_of::dynamic_query::{closure#2} as core[71fbaba24b011fa4]::ops::function::FnOnce<(rustc_middle[1d4c141020d5ff1d]::ty::context::TyCtxt, rustc_span[87ac8800f9b2bd45]::def_id::DefId)>>::call_once
  29:     0x7f2b34ea5964 - rustc_query_system[cfe4b6087db7ea89]::query::plumbing::try_execute_query::<rustc_query_impl[49f881e28274e957]::DynamicConfig<rustc_query_system[cfe4b6087db7ea89]::query::caches::DefaultCache<rustc_span[87ac8800f9b2bd45]::def_id::DefId, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[49f881e28274e957]::plumbing::QueryCtxt, false>
  30:     0x7f2b367bbfd3 - rustc_query_impl[49f881e28274e957]::query_impl::variances_of::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7f2b35771bdf - rustc_middle[1d4c141020d5ff1d]::query::plumbing::query_get_at::<rustc_query_system[cfe4b6087db7ea89]::query::caches::DefaultCache<rustc_span[87ac8800f9b2bd45]::def_id::DefId, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 16usize]>>>
  32:     0x7f2b357925ec - rustc_hir_analysis[1f87ebcc916a8bb0]::check::wfcheck::check_variances_for_type_defn
  33:     0x7f2b3576fd0f - rustc_hir_analysis[1f87ebcc916a8bb0]::check::wfcheck::check_well_formed
  34:     0x7f2b34e11a7c - rustc_query_impl[49f881e28274e957]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49f881e28274e957]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 0usize]>>
  35:     0x7f2b35799986 - rustc_query_system[cfe4b6087db7ea89]::query::plumbing::try_execute_query::<rustc_query_impl[49f881e28274e957]::DynamicConfig<rustc_query_system[cfe4b6087db7ea89]::query::caches::VecCache<rustc_hir[4b4119f5a2aa97da]::hir_id::OwnerId, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[49f881e28274e957]::plumbing::QueryCtxt, false>
  36:     0x7f2b357996a2 - rustc_query_impl[49f881e28274e957]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f2b3608a5bc - rustc_data_structures[d4f5b56d4da9ff99]::sync::par_for_each_in::<&[rustc_hir[4b4119f5a2aa97da]::hir::ImplItemId], <rustc_middle[1d4c141020d5ff1d]::hir::ModuleItems>::par_impl_items<rustc_hir_analysis[1f87ebcc916a8bb0]::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>
  38:     0x7f2b3608a39a - rustc_hir_analysis[1f87ebcc916a8bb0]::check::wfcheck::check_mod_type_wf
  39:     0x7f2b35ab967c - rustc_query_impl[49f881e28274e957]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49f881e28274e957]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 0usize]>>
  40:     0x7f2b35ab965e - <rustc_query_impl[49f881e28274e957]::query_impl::check_mod_type_wf::dynamic_query::{closure#2} as core[71fbaba24b011fa4]::ops::function::FnOnce<(rustc_middle[1d4c141020d5ff1d]::ty::context::TyCtxt, rustc_span[87ac8800f9b2bd45]::def_id::LocalDefId)>>::call_once
  41:     0x7f2b356d75df - rustc_query_system[cfe4b6087db7ea89]::query::plumbing::try_execute_query::<rustc_query_impl[49f881e28274e957]::DynamicConfig<rustc_query_system[cfe4b6087db7ea89]::query::caches::VecCache<rustc_span[87ac8800f9b2bd45]::def_id::LocalDefId, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[49f881e28274e957]::plumbing::QueryCtxt, false>
  42:     0x7f2b367c0eb2 - rustc_query_impl[49f881e28274e957]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7f2b362c2ed7 - rustc_data_structures[d4f5b56d4da9ff99]::sync::par_for_each_in::<&[rustc_hir[4b4119f5a2aa97da]::hir_id::OwnerId], <rustc_middle[1d4c141020d5ff1d]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[1f87ebcc916a8bb0]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  44:     0x7f2b362c228e - rustc_hir_analysis[1f87ebcc916a8bb0]::check_crate
  45:     0x7f2b362bcb7a - rustc_interface[6d12d522b9b133dc]::passes::analysis
  46:     0x7f2b36331c9a - rustc_query_impl[49f881e28274e957]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[49f881e28274e957]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 1usize]>>
  47:     0x7f2b36331c89 - <rustc_query_impl[49f881e28274e957]::query_impl::analysis::dynamic_query::{closure#2} as core[71fbaba24b011fa4]::ops::function::FnOnce<(rustc_middle[1d4c141020d5ff1d]::ty::context::TyCtxt, ())>>::call_once
  48:     0x7f2b364cf5d8 - rustc_query_system[cfe4b6087db7ea89]::query::plumbing::try_execute_query::<rustc_query_impl[49f881e28274e957]::DynamicConfig<rustc_query_system[cfe4b6087db7ea89]::query::caches::SingleCache<rustc_middle[1d4c141020d5ff1d]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[49f881e28274e957]::plumbing::QueryCtxt, false>
  49:     0x7f2b364cf367 - rustc_query_impl[49f881e28274e957]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7f2b360ca1c5 - <rustc_middle[1d4c141020d5ff1d]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[2f92a0ccc46c059]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>
  51:     0x7f2b360c97f2 - <rustc_interface[6d12d522b9b133dc]::interface::Compiler>::enter::<rustc_driver_impl[2f92a0ccc46c059]::run_compiler::{closure#1}::{closure#2}, core[71fbaba24b011fa4]::result::Result<core[71fbaba24b011fa4]::option::Option<rustc_interface[6d12d522b9b133dc]::queries::Linker>, rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>
  52:     0x7f2b360c28c8 - std[b67388f384878aed]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6d12d522b9b133dc]::util::run_in_thread_pool_with_globals<rustc_interface[6d12d522b9b133dc]::interface::run_compiler<core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>, rustc_driver_impl[2f92a0ccc46c059]::run_compiler::{closure#1}>::{closure#0}, core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>
  53:     0x7f2b360c204e - <<std[b67388f384878aed]::thread::Builder>::spawn_unchecked_<rustc_interface[6d12d522b9b133dc]::util::run_in_thread_pool_with_globals<rustc_interface[6d12d522b9b133dc]::interface::run_compiler<core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>, rustc_driver_impl[2f92a0ccc46c059]::run_compiler::{closure#1}>::{closure#0}, core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[71fbaba24b011fa4]::result::Result<(), rustc_span[87ac8800f9b2bd45]::ErrorGuaranteed>>::{closure#1} as core[71fbaba24b011fa4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  54:     0x7f2b33b710c5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h50b018fa15c55b61
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/alloc/src/boxed.rs:2007:9
  55:     0x7f2b33b710c5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h30bf8c9edaaa8962
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/alloc/src/boxed.rs:2007:9
  56:     0x7f2b33b710c5 - std::sys::unix::thread::Thread::new::thread_start::hd4703b35fe8f9aee
                               at /rustc/4f7bb9890c0402cd145556ac1929d13d7524959e/library/std/src/sys/unix/thread.rs:108:17
  57:     0x7f2b3390244b - <unknown>
  58:     0x7f2b33985e40 - <unknown>
  59:                0x0 - <unknown>

error: 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: please attach the file at `/tmp/im/rustc-ice-2023-08-04T15:16:50.896216586Z-99271.txt` to your bug report

query stack during panic:
#0 [crate_variances] computing the variances for items in this crate
#1 [variances_of] computing the variances of `Subpaths`
#2 [check_well_formed] checking that `Subpaths` is well-formed
#3 [check_mod_type_wf] checking that types are well-formed in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0601`.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-lazy_type_alias`#![feature(lazy_type_alias)]`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.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions