rust-lang / rust

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

ICE: `unhandled type: Alias(...)` in `rustc_mir_transform/src/validate.rs` when `[mir_built]` #126680

Open cushionbadak opened 3 months ago

cushionbadak commented 3 months ago

Code

(hand-reduced)

#![feature(type_alias_impl_trait)]
type Bar = impl std::fmt::Display;

use std::path::Path;

struct A {
    pub func: fn(check: Bar, b: Option<&Path>),
}
const MY_A: A = A {
    func: |check, b| {
        if check {
            ()
        } else if let Some(_) = b.and_then(|p| p.parent()) {
            ()
        }
    },
};

fn main() {}
(original)

```Rust #![feature(type_alias_impl_trait)] type Bar = impl std::fmt::Display; async fn test() {} fn main () {} #![crate_type = "lib"] use std::path::Path; struct A { pub func: fn(check: crate::Bar, a: &Path, b: Option<&Path>), } const MY_A: A = A { func: |check, a, b| { if check { let _ = (); } else if let Some(parent) = b.and_then(|p| p.parent()) { let _ = (); } }, }; ```

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (8fcd4dd08 2024-06-18)
binary: rustc
commit-hash: 8fcd4dd08e2ba3e922d917d819ba0be066bdb005
commit-date: 2024-06-18
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

Command: rustc -Zvalidate-mir

<output>
Backtrace

``` error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:1478:30: unhandled type: Alias(Opaque, AliasTy { args: [], def_id: DefId(0:11 ~ r_validate1478_9BFC3853[e0e8]::Bar::{opaque#0}), _use_alias_ty_new_instead: () }) thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:1478:30: Box stack backtrace: 0: std::panicking::begin_panic:: 1: ::emit_producing_guarantee 2: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0} 3: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 5: rustc_middle::util::bug::bug_fmt 6: ::visit_terminator 7: rustc_mir_transform::validate::validate_types 8: ::run_pass 9: rustc_mir_transform::pass_manager::run_passes_inner 10: rustc_mir_transform::mir_built [... omitted 1 frame ...] 11: rustc_middle::query::plumbing::query_get_at::>> 12: rustc_mir_transform::ffi_unwind_calls::has_ffi_unwind_calls [... omitted 1 frame ...] 13: rustc_mir_transform::mir_promoted [... omitted 2 frames ...] 14: rustc_middle::query::plumbing::query_get_at::>> 15: rustc_borrowck::mir_borrowck [... omitted 1 frame ...] 16: rustc_middle::query::plumbing::query_get_at::>> 17: ::prove_closure_bounds 18: ::check_rvalue 19: ::typeck_mir 20: rustc_borrowck::type_check::type_check 21: rustc_borrowck::nll::compute_regions 22: rustc_borrowck::do_mir_borrowck 23: rustc_borrowck::mir_borrowck [... omitted 1 frame ...] 24: rustc_middle::query::plumbing::query_get_at::>> 25: ::check 26: rustc_hir_analysis::collect::type_of::type_of_opaque [... omitted 1 frame ...] 27: rustc_middle::query::plumbing::query_get_at::>> 28: rustc_hir_analysis::collect::type_of::type_of [... omitted 1 frame ...] 29: rustc_middle::query::plumbing::query_get_at::>> 30: rustc_hir_analysis::check::check::check_item_type 31: rustc_hir_analysis::check::wfcheck::check_well_formed [... omitted 1 frame ...] 32: rustc_middle::query::plumbing::query_ensure_error_guaranteed::>, ()> 33: rustc_hir_analysis::check::wfcheck::check_mod_type_wf [... omitted 1 frame ...] 34: rustc_hir_analysis::check_crate 35: rustc_interface::passes::run_required_analyses 36: rustc_interface::passes::analysis [... omitted 1 frame ...] 37: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}> 38: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 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 make sure that you have updated to the latest nightly note: please attach the file at `/Volumes/T7/workspace/240615_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-19T10_52_49-61021.txt` to your bug report note: compiler flags: -Z validate-mir query stack during panic: #0 [mir_built] building MIR for `MY_A::{closure#0}` #1 [has_ffi_unwind_calls] checking if `MY_A::{closure#0}` contains FFI-unwind calls #2 [mir_promoted] promoting constants in MIR for `MY_A::{closure#0}` #3 [mir_borrowck] borrow-checking `MY_A::{closure#0}` #4 [mir_borrowck] borrow-checking `MY_A` #5 [type_of_opaque] computing type of opaque `Bar::{opaque#0}` #6 [type_of] computing type of `Bar::{opaque#0}` #7 [check_well_formed] checking that `Bar::{opaque#0}` is well-formed #8 [check_mod_type_wf] checking that types are well-formed in top-level module #9 [analysis] running analysis passes on this crate end of query stack error: aborting due to 1 previous error ```

Note

@rustbot label +Zvalidate-mir +F-type_alias_impl_trait +Zpolymorphize

rustbot commented 3 months ago

Error: Label Zvalidate-mir can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

cushionbadak commented 3 months ago

@rustbot label +F-type_alias_impl_trait