rust-lang / rust-lang/rust

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

Open
#126,680 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-needs-test F-type_alias_impl_trait I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the hand-reduced example and reproduce it using rustc -Zvalidate-mir. Read compiler/rustc_mir_transform/src/validate.rs around line 1478, then compare the related validation location in compiler/rustc_const_eval/src/transform/validate.rs and issue #125185. Done means the example no longer triggers an internal compiler error under the reported validation and polymorphization paths, with an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.