Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Unexpected type for constructor #119493

Closed
matthiaskrgr opened this issue Jan 1, 2024 · 5 comments · Fixed by #119715
Closed

ICE: Unexpected type for constructor #119493

matthiaskrgr opened this issue Jan 1, 2024 · 5 comments · Fixed by #119715
Assignees
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

fn r#struct() {
    #[derive(Copy, Clone)]
    struct Foo(PhantomData<T>);

    type U = impl Copy;
    let foo: U = Foo((1u32, 2u32));
    let Foo((0..=255, true)) = foo;
}
original code

original:

#![feature(type_alias_impl_trait)]
// MSAN:         call void @__msan_warning{{(_with_origin_noreturn\(i32 0\)|_noreturn\(\))}}

fn main() {
    type T = impl Copy;
    let foo: T = Some((1u32, 2u32));
    match foo {
        None => (),
        Some((a, b)) => (),
    }
}

fn upvar() {
    #[derive(Copy, Clone)]
    struct Foo((u32, u32));

    type T = impl Copy;
    let foo: T = Foo((1u32, 2u32));
    let x = move || {
        let Foo::Var(Supertype::Var(x)) = foo;
    };
}

fn enum_upvar() {
    type T = impl Copy;
    let foo: T = Some((1u32, 2u32));
    let x = move || {
        match foo {
            None => (),
            Some((a, b)) => (),
        }
    };
}

fn r#struct() {
    #[derive(Copy, Clone)]
    struct Foo(PhantomData<T>);

    type U = impl Copy;
    let foo: U = Foo((1u32, 2u32));
    let Foo((0..=255, true)) = foo;
}

mod only_pattern {
    type T = impl Copy;

    fn foo(foo: T) {
        let (mut x, mut y) = foo;
        x = 42;
        y = "foo";
    }

    type U = impl Copy;

    fn bar(bar: Option<U>) {
        match bar {
            Some((mut x, mut y)) => {
                x = 42;
                y = "foo";
            }
            None => {}
        }
    }
}

mod only_pattern_rpit {
    #[allow(unconditional_recursion)]
    fn foo(b: bool) -> impl Copy {
        let (mut x, mut y) = foo(false);
        x = 42;
        y = "foo";
        if b {
            panic!()
        } else {
            foo(true)
        }
    }

    fn bar(b: bool) -> Option<impl Copy> {
        if b {
            return None;
        }
        match bar(!b) {
            Some((mut x, mut y)) => {
                x = 42;
                y = "foo";
            }
            None => {}
        }
        None
    }
}

Version information

rustc 1.77.0-nightly (e51e98dde 2023-12-31)
binary: rustc
commit-hash: e51e98dde6a60637b6a71b8105245b629ac3fe77
commit-date: 2023-12-31
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0412]: cannot find type `PhantomData` in this scope
 --> /tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs:3:16
  |
3 |     struct Foo(PhantomData<T>);
  |                ^^^^^^^^^^^ not found in this scope
  |
help: consider importing this struct
  |
1 + use std::marker::PhantomData;
  |

error[E0412]: cannot find type `T` in this scope
 --> /tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs:3:28
  |
3 |     struct Foo(PhantomData<T>);
  |                            ^
4 |
5 |     type U = impl Copy;
  |     ------------------- similarly named type alias `U` defined here
  |
help: a type alias with a similar name exists
  |
3 |     struct Foo(PhantomData<U>);
  |                            ~
help: you might be missing a type parameter
  |
3 |     struct Foo<T>(PhantomData<T>);
  |               +++

error[E0412]: cannot find type `T` in this scope
 --> /tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs:3:28
  |
3 |     struct Foo(PhantomData<T>);
  |                            ^
4 |
5 |     type U = impl Copy;
  |     ------------------- similarly named type alias `U` defined here
  |
help: a type alias with a similar name exists
  |
3 |     struct Foo(PhantomData<U>);
  |                            ~
help: you might be missing a type parameter
  |
3 |     struct Foo<T>(PhantomData<T>);
  |               +++

error[E0658]: `impl Trait` in type aliases is unstable
 --> /tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs:5:14
  |
5 |     type U = impl Copy;
  |              ^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs:8:2
  |
8 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.jRG9tB5Z6R6s/rustc_testrunner_tmpdir_reporting.phomlM4A9Thq/mvce.rs`

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:190:22: Unexpected type for constructor `Struct`: {type error}

thread 'rustc' panicked at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/compiler/rustc_errors/src/lib.rs:1068:30:
Box<dyn Any>
stack backtrace:
   0:     0x7fd41a98b946 - std::backtrace_rs::backtrace::libunwind::trace::h44f4ca7c442c0986
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fd41a98b946 - std::backtrace_rs::backtrace::trace_unsynchronized::h8e72beef8f98799e
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd41a98b946 - std::sys_common::backtrace::_print_fmt::had1f7322c7191a83
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fd41a98b946 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc02075f68ac68e83
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fd41a9de060 - core::fmt::rt::Argument::fmt::h4fb797bf569c9381
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/fmt/rt.rs:142:9
   5:     0x7fd41a9de060 - core::fmt::write::h6f1ea15fe9368d17
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fd41a97f36f - std::io::Write::write_fmt::haaa4143b58137630
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/io/mod.rs:1810:15
   7:     0x7fd41a98b724 - std::sys_common::backtrace::_print::h16f1f390d8dff6aa
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fd41a98b724 - std::sys_common::backtrace::print::h7a4cfc718891723c
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fd41a98e4b7 - std::panicking::default_hook::{{closure}}::h66f09592313f4ce8
  10:     0x7fd41a98e219 - std::panicking::default_hook::he45e0a376ce42f7d
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:292:9
  11:     0x7fd41d76605c - std[59bbd359e4a0812d]::panicking::update_hook::<alloc[9e8bbef5278c9f16]::boxed::Box<rustc_driver_impl[f5f02e8ab7f89dcf]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fd41a98ec06 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0ebdda5c503ff158
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2029:9
  13:     0x7fd41a98ec06 - std::panicking::rust_panic_with_hook::h4f38919015b1c60f
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:783:13
  14:     0x7fd41d79f1b4 - std[59bbd359e4a0812d]::panicking::begin_panic::<rustc_errors[b2b45e62fb4172dd]::ExplicitBug>::{closure#0}
  15:     0x7fd41d79b5b6 - std[59bbd359e4a0812d]::sys_common::backtrace::__rust_end_short_backtrace::<std[59bbd359e4a0812d]::panicking::begin_panic<rustc_errors[b2b45e62fb4172dd]::ExplicitBug>::{closure#0}, !>
  16:     0x7fd41d796856 - std[59bbd359e4a0812d]::panicking::begin_panic::<rustc_errors[b2b45e62fb4172dd]::ExplicitBug>
  17:     0x7fd41d7aa101 - <rustc_errors[b2b45e62fb4172dd]::diagnostic_builder::BugAbort as rustc_errors[b2b45e62fb4172dd]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fd41db71ece - <rustc_errors[b2b45e62fb4172dd]::DiagCtxt>::bug::<alloc[9e8bbef5278c9f16]::string::String>
  19:     0x7fd41dc0e02b - rustc_middle[7d80ff9c88f366f3]::util::bug::opt_span_bug_fmt::<rustc_span[44814e3eac9e4a35]::span_encoding::Span>::{closure#0}
  20:     0x7fd41dbf690a - rustc_middle[7d80ff9c88f366f3]::ty::context::tls::with_opt::<rustc_middle[7d80ff9c88f366f3]::util::bug::opt_span_bug_fmt<rustc_span[44814e3eac9e4a35]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fd41dbf67a8 - rustc_middle[7d80ff9c88f366f3]::ty::context::tls::with_context_opt::<rustc_middle[7d80ff9c88f366f3]::ty::context::tls::with_opt<rustc_middle[7d80ff9c88f366f3]::util::bug::opt_span_bug_fmt<rustc_span[44814e3eac9e4a35]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fd41bb88960 - rustc_middle[7d80ff9c88f366f3]::util::bug::bug_fmt
  23:     0x7fd41f6ab148 - rustc_pattern_analysis[ac99d9a1120f8a2d]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[ac99d9a1120f8a2d]::rustc::RustcMatchCheckCtxt>::{closure#0}
  24:     0x7fd41f6a3e70 - rustc_pattern_analysis[ac99d9a1120f8a2d]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[ac99d9a1120f8a2d]::rustc::RustcMatchCheckCtxt>::{closure#0}
  25:     0x7fd41ed4ceb3 - rustc_pattern_analysis[ac99d9a1120f8a2d]::analyze_match
  26:     0x7fd41ba141fa - <rustc_mir_build[92ecac31500debc4]::thir::pattern::check_match::MatchVisitor>::check_binding_is_irrefutable
  27:     0x7fd41ba0b9ee - <rustc_mir_build[92ecac31500debc4]::thir::pattern::check_match::MatchVisitor as rustc_middle[7d80ff9c88f366f3]::thir::visit::Visitor>::visit_expr
  28:     0x7fd41ba0a9bd - <rustc_mir_build[92ecac31500debc4]::thir::pattern::check_match::MatchVisitor as rustc_middle[7d80ff9c88f366f3]::thir::visit::Visitor>::visit_expr
  29:     0x7fd41eb7d8e5 - rustc_mir_build[92ecac31500debc4]::thir::pattern::check_match::check_match
  30:     0x7fd41eb7d50f - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 1usize]>>
  31:     0x7fd41eb7cae1 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  32:     0x7fd41eb7c783 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7fd41ed0b78f - rustc_mir_build[92ecac31500debc4]::build::mir_built
  34:     0x7fd41ed0b5ed - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7fd41eb65c43 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  36:     0x7fd41eb655d0 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7fd41bfa928e - rustc_mir_transform[8186e48857664e14]::check_unsafety::unsafety_check_result
  38:     0x7fd41eb659c7 - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::unsafety_check_result::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  39:     0x7fd41eb65c43 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  40:     0x7fd41eb65750 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fd41eb66c39 - rustc_mir_transform[8186e48857664e14]::mir_const
  42:     0x7fd41eb66b67 - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7fd41eb65c43 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  44:     0x7fd41eb65690 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7fd41cce324c - rustc_mir_transform[8186e48857664e14]::mir_promoted
  46:     0x7fd41f02915e - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 16usize]>>
  47:     0x7fd41f02942a - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  48:     0x7fd41f029063 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7fd41f8d3a30 - rustc_borrowck[873e5fa24eb195b7]::mir_borrowck
  50:     0x7fd41f8d3979 - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  51:     0x7fd41eb65c43 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  52:     0x7fd41eb65810 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7fd41ff1989e - rustc_middle[7d80ff9c88f366f3]::query::plumbing::query_get_at::<rustc_query_system[cdab7429fb42dda2]::query::caches::VecCache<rustc_span[44814e3eac9e4a35]::def_id::LocalDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>>.llvm.6795780377887956518.cold.0
  54:     0x7fd41d8ac836 - <rustc_hir_analysis[239f966c4ce807be]::collect::type_of::opaque::TaitConstraintLocator>::check
  55:     0x7fd41d89aa50 - <rustc_hir_analysis[239f966c4ce807be]::collect::type_of::opaque::TaitConstraintLocator as rustc_hir[556501f2b35f222e]::intravisit::Visitor>::visit_item
  56:     0x7fd41f9e5ffa - rustc_hir_analysis[239f966c4ce807be]::collect::type_of::type_of_opaque
  57:     0x7fd41f9e54db - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  58:     0x7fd41ea62514 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::DefaultCache<rustc_span[44814e3eac9e4a35]::def_id::DefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  59:     0x7fd41fa2891e - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  60:     0x7fd41eb77bb8 - rustc_middle[7d80ff9c88f366f3]::query::plumbing::query_get_at::<rustc_query_system[cdab7429fb42dda2]::query::caches::DefaultCache<rustc_span[44814e3eac9e4a35]::def_id::DefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>>
  61:     0x7fd41ce27533 - rustc_hir_analysis[239f966c4ce807be]::collect::type_of::type_of
  62:     0x7fd41ea6367e - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>
  63:     0x7fd41ea62514 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::DefaultCache<rustc_span[44814e3eac9e4a35]::def_id::DefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  64:     0x7fd41ea620dd - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  65:     0x7fd41eb77bb8 - rustc_middle[7d80ff9c88f366f3]::query::plumbing::query_get_at::<rustc_query_system[cdab7429fb42dda2]::query::caches::DefaultCache<rustc_span[44814e3eac9e4a35]::def_id::DefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 8usize]>>>
  66:     0x7fd41f675b42 - rustc_hir_analysis[239f966c4ce807be]::check::check::check_item_type
  67:     0x7fd41f66f965 - rustc_hir_analysis[239f966c4ce807be]::check::check::check_mod_item_types
  68:     0x7fd41f66f917 - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 0usize]>>
  69:     0x7fd41f618dbb - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::DefaultCache<rustc_span[44814e3eac9e4a35]::def_id::LocalModDefId, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  70:     0x7fd41f61879f - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  71:     0x7fd41f2dfc25 - rustc_hir_analysis[239f966c4ce807be]::check_crate
  72:     0x7fd41f35a319 - rustc_interface[8dea96efab884454]::passes::analysis
  73:     0x7fd41f359f5f - rustc_query_impl[6eb9e4a88fa21aca]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6eb9e4a88fa21aca]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 1usize]>>
  74:     0x7fd41f997a64 - rustc_query_system[cdab7429fb42dda2]::query::plumbing::try_execute_query::<rustc_query_impl[6eb9e4a88fa21aca]::DynamicConfig<rustc_query_system[cdab7429fb42dda2]::query::caches::SingleCache<rustc_middle[7d80ff9c88f366f3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6eb9e4a88fa21aca]::plumbing::QueryCtxt, false>
  75:     0x7fd41f997855 - rustc_query_impl[6eb9e4a88fa21aca]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  76:     0x7fd41fa2d094 - rustc_interface[8dea96efab884454]::interface::run_compiler::<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}
  77:     0x7fd41f9b7306 - std[59bbd359e4a0812d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8dea96efab884454]::util::run_in_thread_with_globals<rustc_interface[8dea96efab884454]::util::run_in_thread_pool_with_globals<rustc_interface[8dea96efab884454]::interface::run_compiler<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>
  78:     0x7fd41f9b7133 - <<std[59bbd359e4a0812d]::thread::Builder>::spawn_unchecked_<rustc_interface[8dea96efab884454]::util::run_in_thread_with_globals<rustc_interface[8dea96efab884454]::util::run_in_thread_pool_with_globals<rustc_interface[8dea96efab884454]::interface::run_compiler<core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>, rustc_driver_impl[f5f02e8ab7f89dcf]::run_compiler::{closure#0}>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f50a4b4ddb6878bb]::result::Result<(), rustc_span[44814e3eac9e4a35]::ErrorGuaranteed>>::{closure#1} as core[f50a4b4ddb6878bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  79:     0x7fd41a998b35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfced58be344e2c05
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2015:9
  80:     0x7fd41a998b35 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7842a7154462ae57
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/alloc/src/boxed.rs:2015:9
  81:     0x7fd41a998b35 - std::sys::unix::thread::Thread::new::thread_start::ha365c5d9b9d0ac99
                               at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/sys/unix/thread.rs:108:17
  82:     0x7fd41a7849eb - <unknown>
  83:     0x7fd41a8087cc - <unknown>
  84:                0x0 - <unknown>

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.77.0-nightly (e51e98dde 2023-12-31) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `r#struct`
#1 [mir_built] building MIR for `r#struct`
#2 [unsafety_check_result] unsafety-checking `r#struct`
#3 [mir_const] preparing `r#struct` for borrow checking
#4 [mir_promoted] promoting constants in MIR for `r#struct`
#5 [mir_borrowck] borrow-checking `r#struct`
#6 [type_of_opaque] computing type of opaque `r#struct::U::{opaque#0}`
#7 [type_of] computing type of `r#struct::U::{opaque#0}`
#8 [check_mod_item_types] checking item types in top-level module
#9 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0412, E0601, E0658.
For more information about an error, try `rustc --explain E0412`.

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 1, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 1, 2024
@matthiaskrgr
Copy link
Member Author

Bisected to #117611 cc @Nadrieril

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 1, 2024
@Nadrieril Nadrieril self-assigned this Jan 1, 2024
@Nadrieril
Copy link
Member

You always find the best edge-cases :D

@Nadrieril
Copy link
Member

Nadrieril commented Jan 1, 2024

Reduced to:

fn foo() {
    #[derive(Copy, Clone)]
    struct Foo(NonExistent);

    type U = impl Copy;
    let foo: U = Foo(());
    let Foo(()) = foo;
}

What happens is that when we get to checking exhaustiveness of the let Foo(()), the adt Foo has a single field of type ty::Error, which crashes exhaustiveness. I'd like to skip exhaustiveness entirely in a case like this, is there a method like ty.has_error() I could call that could tell me if a ty::Error hides somewhere deep within a type?

Another angle is that without the TAIT, exhaustiveness is simply not run on the let expression. It would make sense for typeck to behave similarly in the above case.

@Nadrieril Nadrieril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns labels Jan 1, 2024
@Nadrieril Nadrieril removed their assignment Jan 1, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Jan 2, 2024

https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/visit/trait.TypeVisitableExt.html#method.references_error can be invoked on any TypeVisitable (so Ty, too). It doesn't go into struct fields though. It's also not really possible to do this correctly due to cycles. It may be more feasible to make exhaustiveness checking fallible (Result<(), ErrorGuaranteed> instead of ()), and use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/visit/trait.TypeVisitableExt.html#method.error_reported in a bunch of places (ty.error_reported()? and a bunch of extra ? on methods should be fairly painless)

@Nadrieril
Copy link
Member

Welcome back oli! Hm now that you say it, I expect rust-analyzer will have similar situations; adding a bit of error-handling feels reasonable.

@Nadrieril Nadrieril self-assigned this Jan 5, 2024
@bors bors closed this as completed in 4dcc5a0 Jan 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 11, 2024
Rollup merge of rust-lang#119715 - Nadrieril:graceful-type-error, r=compiler-errors

Exhaustiveness: abort on type error

This adds an error path to exhaustiveness checking so that we abort instead of ICEing when encountering a stray `ty::Error`.

Fixes rust-lang#119493
Fixes rust-lang#119778

r? `@compiler-errors`
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 11, 2024
…rrors

Exhaustiveness: abort on type error

This adds an error path to exhaustiveness checking so that we abort instead of ICEing when encountering a stray `ty::Error`.

Fixes rust-lang/rust#119493
Fixes rust-lang/rust#119778

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants