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 in type checking when use type alias to construct struct #103053

Closed
mikialex opened this issue Oct 14, 2022 · 2 comments · Fixed by #103116
Closed

ICE in type checking when use type alias to construct struct #103053

mikialex opened this issue Oct 14, 2022 · 2 comments · Fixed by #103116
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mikialex
Copy link

Code

also playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=605d6253e0286ecce2ac39a229a15ebd

use std::marker::PhantomData;

struct Node<T> {
  phantom: PhantomData<T>,
}

fn make_node<T>(v: T) -> Node<T> {
  todo!()
}

trait TypeMapper {
  type MapType;
}

pub type Mapped<T> = <T as TypeMapper>::MapType;

struct TestMeta {
  node: f32,
}

struct Test {
  node: Node<f32>,
}

impl TypeMapper for TestMeta {
  type MapType = Test;
}

fn test() -> Mapped<TestMeta> {
  let node = Ok(make_node(1.))
    .or_else(|_| Ok(make_node(1.)))
    .unwrap_or_else(|_| make_node(0.3));

  Mapped::<TestMeta> { node }
}

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (878aef79d 2022-08-20)
binary: rustc
commit-hash: 878aef79dcdf59d19bb8482202dc55e58ceb62ff
commit-date: 2022-08-20
host: x86_64-pc-windows-msvc
release: 1.65.0-nightly
LLVM version: 15.0.0

I also checked on latest nightly

Error output

error: internal compiler error: unexpected panic

note: 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: rustc 1.66.0-nightly (6b3ede3f7 2022-10-13) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `test`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
Backtrace

thread 'rustc' panicked at 'range end index 1 out of range for slice of length 0', compiler/rustc_middle/src/ty/generics.rs:293:20
stack backtrace:
   0:     0x7fab34504510 - std::backtrace_rs::backtrace::libunwind::trace::h5fd4ba8cd3f3b043
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7fab34504510 - std::backtrace_rs::backtrace::trace_unsynchronized::h6b8ff17e84b06344
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fab34504510 - std::sys_common::backtrace::_print_fmt::h2a62246ce4798f58
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fab34504510 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf764488cdbda71ea
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fab3456052e - core::fmt::write::h449e808f9f40276b
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/core/src/fmt/mod.rs:1209:17
   5:     0x7fab344f48d5 - std::io::Write::write_fmt::hd7b0087c2e6dbebc
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/io/mod.rs:1680:15
   6:     0x7fab34507143 - std::sys_common::backtrace::_print::hf7b092f93b76d882
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fab34507143 - std::sys_common::backtrace::print::hdf0c27a1f1e747c6
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fab34507143 - std::panicking::default_hook::{{closure}}::h5891167ca195e6a8
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/panicking.rs:267:22
   9:     0x7fab34506e1a - std::panicking::default_hook::he044f2ad9b0871df
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/panicking.rs:286:9
  10:     0x7fab36e3f6c4 - <rustc_driver[96a78d505a155f82]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[4789b31b67b14f2c]::ops::function::FnOnce<(&core[4789b31b67b14f2c]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7fab34507a79 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0266072becdeb9d9
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/alloc/src/boxed.rs:1952:9
  12:     0x7fab34507a79 - std::panicking::rust_panic_with_hook::h4c36a8e39d3b1546
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/panicking.rs:692:13
  13:     0x7fab345077f7 - std::panicking::begin_panic_handler::{{closure}}::h1ad7cae6847bde08
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/panicking.rs:579:13
  14:     0x7fab345049bc - std::sys_common::backtrace::__rust_end_short_backtrace::h6c67c761e3d1141c
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7fab34507512 - rust_begin_unwind
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/panicking.rs:575:5
  16:     0x7fab3455cf13 - core::panicking::panic_fmt::h552ae8977ad87247
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/core/src/panicking.rs:65:14
  17:     0x7fab345637d2 - core::slice::index::slice_end_index_len_fail_rt::h1c2cc5023b211b61
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/core/src/slice/index.rs:76:5
  18:     0x7fab34563757 - core::slice::index::slice_end_index_len_fail::h23deb4de6ddc0f1e
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/core/src/slice/index.rs:69:9
  19:     0x7fab37e35a94 - <rustc_middle[6dbd2462fc060d2b]::ty::generics::Generics>::own_substs
  20:     0x7fab37d7c6df - <rustc_infer[f8ef610796372df6]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[1f1fbd514ec97001]::intravisit::Visitor>::visit_expr
  21:     0x7fab37d7c53b - <rustc_infer[f8ef610796372df6]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[1f1fbd514ec97001]::intravisit::Visitor>::visit_expr
  22:     0x7fab37dbcb34 - <rustc_infer[f8ef610796372df6]::infer::error_reporting::TypeErrCtxt>::emit_inference_failure_err
  23:     0x7fab37cf88d2 - <rustc_infer[f8ef610796372df6]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d25599a44813fce7]::traits::error_reporting::InferCtxtPrivExt>::maybe_report_ambiguity
  24:     0x7fab37cebdf2 - <rustc_infer[f8ef610796372df6]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[d25599a44813fce7]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  25:     0x7fab36312af5 - <rustc_hir_analysis[664218718b8589c1]::check::inherited::InheritedBuilder>::enter::<rustc_hir_analysis[664218718b8589c1]::check::typeck_with_fallback<rustc_hir_analysis[664218718b8589c1]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[6dbd2462fc060d2b]::ty::context::TypeckResults>
  26:     0x7fab3630f27c - rustc_hir_analysis[664218718b8589c1]::check::typeck
  27:     0x7fab3644e005 - rustc_query_system[e331cc205febeb47]::query::plumbing::try_execute_query::<rustc_query_impl[bde3f7ee5c39de55]::plumbing::QueryCtxt, rustc_query_system[e331cc205febeb47]::query::caches::DefaultCache<rustc_span[3592ef59ed235133]::def_id::LocalDefId, &rustc_middle[6dbd2462fc060d2b]::ty::context::TypeckResults>>
  28:     0x7fab36d4450e - <rustc_query_impl[bde3f7ee5c39de55]::Queries as rustc_middle[6dbd2462fc060d2b]::ty::query::QueryEngine>::typeck
  29:     0x7fab36b7a057 - rustc_data_structures[8d749e1e363ae678]::sync::par_for_each_in::<&[rustc_span[3592ef59ed235133]::def_id::LocalDefId], <rustc_middle[6dbd2462fc060d2b]::hir::map::Map>::par_body_owners<rustc_hir_analysis[664218718b8589c1]::check::typeck_item_bodies::{closure#0}>::{closure#0}>
  30:     0x7fab36b79e13 - rustc_hir_analysis[664218718b8589c1]::check::typeck_item_bodies
  31:     0x7fab36a8ebfa - rustc_query_system[e331cc205febeb47]::query::plumbing::try_execute_query::<rustc_query_impl[bde3f7ee5c39de55]::plumbing::QueryCtxt, rustc_query_system[e331cc205febeb47]::query::caches::DefaultCache<(), ()>>
  32:     0x7fab36a8e927 - rustc_query_system[e331cc205febeb47]::query::plumbing::get_query::<rustc_query_impl[bde3f7ee5c39de55]::queries::typeck_item_bodies, rustc_query_impl[bde3f7ee5c39de55]::plumbing::QueryCtxt>
  33:     0x7fab3683452f - <rustc_session[68dc535c7179149b]::session::Session>::time::<(), rustc_hir_analysis[664218718b8589c1]::check_crate::{closure#7}>
  34:     0x7fab368340ff - rustc_hir_analysis[664218718b8589c1]::check_crate
  35:     0x7fab36833c07 - rustc_interface[523bd19883029b4c]::passes::analysis
  36:     0x7fab36bd4ab4 - rustc_query_system[e331cc205febeb47]::query::plumbing::try_execute_query::<rustc_query_impl[bde3f7ee5c39de55]::plumbing::QueryCtxt, rustc_query_system[e331cc205febeb47]::query::caches::DefaultCache<(), core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>>
  37:     0x7fab36bd47e7 - rustc_query_system[e331cc205febeb47]::query::plumbing::get_query::<rustc_query_impl[bde3f7ee5c39de55]::queries::analysis, rustc_query_impl[bde3f7ee5c39de55]::plumbing::QueryCtxt>
  38:     0x7fab35a40d33 - <rustc_interface[523bd19883029b4c]::passes::QueryContext>::enter::<rustc_driver[96a78d505a155f82]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>
  39:     0x7fab35a39b68 - rustc_interface[523bd19883029b4c]::interface::create_compiler_and_run::<core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>, rustc_driver[96a78d505a155f82]::run_compiler::{closure#1}>
  40:     0x7fab35a38992 - <scoped_tls[2dd69a52c14e2135]::ScopedKey<rustc_span[3592ef59ed235133]::SessionGlobals>>::set::<rustc_interface[523bd19883029b4c]::interface::run_compiler<core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>, rustc_driver[96a78d505a155f82]::run_compiler::{closure#1}>::{closure#0}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>
  41:     0x7fab35a37e6f - std[3c0b16f342cb28c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[523bd19883029b4c]::util::run_in_thread_pool_with_globals<rustc_interface[523bd19883029b4c]::interface::run_compiler<core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>, rustc_driver[96a78d505a155f82]::run_compiler::{closure#1}>::{closure#0}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>::{closure#0}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>
  42:     0x7fab36c5f87f - <<std[3c0b16f342cb28c]::thread::Builder>::spawn_unchecked_<rustc_interface[523bd19883029b4c]::util::run_in_thread_pool_with_globals<rustc_interface[523bd19883029b4c]::interface::run_compiler<core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>, rustc_driver[96a78d505a155f82]::run_compiler::{closure#1}>::{closure#0}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>::{closure#0}, core[4789b31b67b14f2c]::result::Result<(), rustc_errors[fd73173ee5a3bff8]::ErrorGuaranteed>>::{closure#1} as core[4789b31b67b14f2c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7fab34511593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h443ce3efa86ddcda
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/alloc/src/boxed.rs:1938:9
  44:     0x7fab34511593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h530c0799f48af0fa
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/alloc/src/boxed.rs:1938:9
  45:     0x7fab34511593 - std::sys::unix::thread::Thread::new::thread_start::hc1d2cc56d17cceb4
                               at /rustc/6b3ede3f7bc502eba7bbd202b4b9312d812adcd7/library/std/src/sys/unix/thread.rs:108:17
  46:     0x7fab343e3609 - start_thread
  47:     0x7fab34306133 - clone
  48:                0x0 - <unknown>

@mikialex mikialex added C-bug Category: This is a bug. 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. labels Oct 14, 2022
@aliemjay
Copy link
Member

Minimized: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2eff9d1bc6f57cc73fc8778ad947a45c

trait TypeMapper {
    type MapType;
}

type Mapped<T> = <T as TypeMapper>::MapType;

struct Test {}

impl TypeMapper for () {
    type MapType = Test;
}

fn test() {
    Mapped::<()> {};
    None;
}

@TaKO8Ki TaKO8Ki self-assigned this Oct 14, 2022
@TaKO8Ki TaKO8Ki added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Oct 14, 2022
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Oct 14, 2022

Regression in #89862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

3 participants