Skip to content

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

Description

@cushionbadak

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)

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

async fn test<const N: crate::Bar>() {}

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<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_mir_transform::validate::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_terminator
   7: rustc_mir_transform::validate::validate_types
   8: <rustc_mir_transform::validate::Validator as rustc_middle::mir::MirPass>::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::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  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::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 16]>>>
  15: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
  16: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  17: <rustc_borrowck::type_check::TypeChecker>::prove_closure_bounds
  18: <rustc_borrowck::type_check::TypeChecker>::check_rvalue
  19: <rustc_borrowck::type_check::TypeChecker>::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::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  25: <rustc_hir_analysis::collect::type_of::opaque::TaitConstraintLocator>::check
  26: rustc_hir_analysis::collect::type_of::type_of_opaque
      [... omitted 1 frame ...]
  27: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  28: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 1 frame ...]
  29: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  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::<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
  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: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  38: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, 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

  • ICE location: compiler/rustc_mir_transform/src/validate.rs#L1478

    fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
    match &terminator.kind {
    TerminatorKind::SwitchInt { targets, discr } => {
    let switch_ty = discr.ty(&self.body.local_decls, self.tcx);
    let target_width = self.tcx.sess.target.pointer_width;
    let size = Size::from_bits(match switch_ty.kind() {
    ty::Uint(uint) => uint.normalize(target_width).bit_width().unwrap(),
    ty::Int(int) => int.normalize(target_width).bit_width().unwrap(),
    ty::Char => 32,
    ty::Bool => 1,
    other => bug!("unhandled type: {:?}", other),
    });

  • ICE: unhandled type: {type error} #125185 points to identical ICE-triggering function compiler/rustc_const_eval/src/transform/validate.rs#L1478 in commit-97bf25c8c

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

Activity

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

    @rustbot
    Collaborator

    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.

  4. cushionbadak commented on Jun 19, 2024

    @cushionbadak
    Author

    @rustbot label +F-type_alias_impl_trait

  5. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Jun 30, 2024
  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 20, 2024
  7. jakubadamw commented on Jul 17, 2026

    @jakubadamw
    Contributor

    The examples don’t ICE on nightly any more.

    @rustbot label +E-needs-test

  8. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Jul 17, 2026
  9. added
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    on Oct 5, 2026
  10. added 3 commits that reference this issue on Oct 7, 2026
  11. added a commit that references this issue on Oct 8, 2026
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

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions