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 when trying to infer parameter in impl Trait type alias #77179

Closed
funbringer opened this issue Sep 25, 2020 · 3 comments · Fixed by #87606
Closed

ICE when trying to infer parameter in impl Trait type alias #77179

funbringer opened this issue Sep 25, 2020 · 3 comments · Fixed by #87606
Labels
C-bug Category: This is a bug. E-needs-test Call 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)]` glacier ICE tracked in rust-lang/glacier. 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

@funbringer
Copy link

funbringer commented Sep 25, 2020

Code

#![feature(type_alias_impl_trait)]

type Pointer<T> = impl std::ops::Deref<Target=T>;

fn test() -> Pointer<_> {
    Box::new(1)
}

fn main() {
    test();
}

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (e599b53e6 2020-09-24)
binary: rustc
commit-hash: e599b53e67ddd197a09a3d8720eed872df481aa0
commit-date: 2020-09-24
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/mod.rs:902:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.48.0-nightly (e599b53e6 2020-09-24) running on x86_64-unknown-linux-gnu

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler/rustc_middle/src/ty/mod.rs:902:14
stack backtrace:
   0:     0x7fdb89c08af0 - std::backtrace_rs::backtrace::libunwind::trace::he85dfb3ae4206056
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:96
   1:     0x7fdb89c08af0 - std::backtrace_rs::backtrace::trace_unsynchronized::h1ad28094d7b00c21
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/../../backtrace/src/backtrace/mod.rs:66
   2:     0x7fdb89c08af0 - std::sys_common::backtrace::_print_fmt::h901b54610713cd21
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys_common/backtrace.rs:79
   3:     0x7fdb89c08af0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb0ad78ee1571f7e0
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys_common/backtrace.rs:58
   4:     0x7fdb89c76fec - core::fmt::write::h1857a60b204f1b6a
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/core/src/fmt/mod.rs:1080
   5:     0x7fdb89bfae17 - std::io::Write::write_fmt::hf7b7d7b243f84a36
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/io/mod.rs:1517
   6:     0x7fdb89c0d840 - std::sys_common::backtrace::_print::hd093978a5287b8ff
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys_common/backtrace.rs:61
   7:     0x7fdb89c0d840 - std::sys_common::backtrace::print::h20f46787581d56d7
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys_common/backtrace.rs:48
   8:     0x7fdb89c0d840 - std::panicking::default_hook::{{closure}}::h486cbb4b82ffc357
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/panicking.rs:208
   9:     0x7fdb89c0d4f8 - std::panicking::default_hook::h4190c9e3edd4d591
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/panicking.rs:227
  10:     0x7fdb8a4910e8 - rustc_driver::report_ice::h5b9a250c1f2e4e0f
  11:     0x7fdb89c0e076 - std::panicking::rust_panic_with_hook::h72e78719cdda225c
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/panicking.rs:581
  12:     0x7fdb89c0dbf9 - std::panicking::begin_panic_handler::{{closure}}::h8bd07dbd34150a96
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/panicking.rs:484
  13:     0x7fdb89c08f7c - std::sys_common::backtrace::__rust_end_short_backtrace::hdb6b3066ad29028a
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys_common/backtrace.rs:153
  14:     0x7fdb89c0dbb9 - rust_begin_unwind
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/panicking.rs:483
  15:     0x7fdb89c73ae1 - core::panicking::panic_fmt::hb15d6f55e8472f62
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/core/src/panicking.rs:85
  16:     0x7fdb89c73aa2 - core::panicking::panic_bounds_check::hec58b3e6eeb445f1
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/core/src/panicking.rs:62
  17:     0x7fdb8cf29ac7 - rustc_middle::ty::Generics::param_at::h4b1726794b54cdfd
  18:     0x7fdb8cefe7e1 - rustc_middle::ty::error::<impl rustc_middle::ty::context::TyCtxt>::note_and_explain_type_err::h7cb645c5c5b90cf5
  19:     0x7fdb8cb81493 - rustc_infer::infer::error_reporting::<impl rustc_infer::infer::InferCtxt>::note_type_err::h4c36be3957d1662d
  20:     0x7fdb8c82eb5c - <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_projection_error::h31390ab10f6360f5
  21:     0x7fdb8c822547 - <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors::hf28998efe93b7292
  22:     0x7fdb8af398c6 - rustc_typeck::check::fn_ctxt::FnCtxt::resolve_vars_with_obligations::h9a0855284bd6b881
  23:     0x7fdb8af20328 - rustc_typeck::check::coercion::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::try_coerce::hf0c46adf66073e84
  24:     0x7fdb8b1e9e5c - rustc_typeck::check::coercion::CoerceMany<E>::coerce_inner::h95afffd9898c59af
  25:     0x7fdb8af35231 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr::he4dc01cee6c0bcff
  26:     0x7fdb8b025eba - rustc_typeck::check::check::check_fn::hbcb6b1dde4bc960b
  27:     0x7fdb8b1bcc47 - rustc_infer::infer::InferCtxtBuilder::enter::h92301174ef521b3f
  28:     0x7fdb8b20c9fd - rustc_typeck::check::typeck::h7abfb32e668dfbfc
  29:     0x7fdb8b22388e - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute::h29528a7ccaa31421
  30:     0x7fdb8b11d447 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hfe41720047886ab1
  31:     0x7fdb8b12f831 - rustc_data_structures::stack::ensure_sufficient_stack::he90b63555f9da90a
  32:     0x7fdb8af89979 - rustc_query_system::query::plumbing::get_query_impl::h2b7bac3db6eab8c6
  33:     0x7fdb8b24199d - rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check::h6ac50be6d09ae2a5
  34:     0x7fdb8b235775 - rustc_hir::intravisit::Visitor::visit_nested_item::ha04543cbe532dcd4
  35:     0x7fdb8b240d6e - rustc_typeck::collect::type_of::type_of::h14b3aa413578af1c
  36:     0x7fdb8b08564f - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::type_of>::compute::h5eee1630a72dec68
  37:     0x7fdb8b115544 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::ha3cd1f15884a7c2e
  38:     0x7fdb8b1262b1 - rustc_data_structures::stack::ensure_sufficient_stack::h5010fc8cff559dfb
  39:     0x7fdb8af8c163 - rustc_query_system::query::plumbing::get_query_impl::h2f279dd41f144e86
  40:     0x7fdb8afe8a39 - rustc_query_system::query::plumbing::ensure_query_impl::hbb75094105c162e1
  41:     0x7fdb8b0ba822 - <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item::hf06b505bac38ad44
  42:     0x7fdb8b0ffba7 - rustc_middle::hir::map::Map::visit_item_likes_in_module::h2a4aee8b87b28f25
  43:     0x7fdb8b0b9dc4 - rustc_typeck::collect::collect_mod_item_types::h5891c6b98339f497
  44:     0x7fdb8b14c67e - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_mod_item_types>::compute::h3d0ade04142eb839
  45:     0x7fdb8b11ce87 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hfd690e03ba9d1ab2
  46:     0x7fdb8b128164 - rustc_data_structures::stack::ensure_sufficient_stack::h6e7f360f3e9d4857
  47:     0x7fdb8af752f2 - rustc_query_system::query::plumbing::get_query_impl::h10f6d0f964f1fc2e
  48:     0x7fdb8afe7f5e - rustc_query_system::query::plumbing::ensure_query_impl::h60712fdbfdc9a22d
  49:     0x7fdb8b1715a8 - rustc_typeck::check_crate::h9c922293ba6500e8
  50:     0x7fdb8a6e89ee - rustc_interface::passes::analysis::h2455fb25ef9b8b07
  51:     0x7fdb8a50d952 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute::h96406a6a86c63093
  52:     0x7fdb8a4d26a7 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h83289bcc6034d955
  53:     0x7fdb8a4e2f00 - rustc_data_structures::stack::ensure_sufficient_stack::hf783639b39530d12
  54:     0x7fdb8a47a688 - rustc_query_system::query::plumbing::get_query_impl::hd5770b33f5645892
  55:     0x7fdb8a50dfdf - rustc_interface::passes::QueryContext::enter::h19ffcccf6feba585
  56:     0x7fdb8a4df108 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h4073398f85d8c311
  57:     0x7fdb8a4b4417 - rustc_span::with_source_map::hcdf14978ceebb1ca
  58:     0x7fdb8a4e0c38 - rustc_interface::interface::create_compiler_and_run::h4010913171666a50
  59:     0x7fdb8a4c644a - scoped_tls::ScopedKey<T>::set::h92d9c87642fc84f8
  60:     0x7fdb8a4e3523 - std::sys_common::backtrace::__rust_begin_short_backtrace::h0f5bdd312fd56bd0
  61:     0x7fdb8a468f9e - core::ops::function::FnOnce::call_once{{vtable.shim}}::h333c57b229aeb132
  62:     0x7fdb89c1d80a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h1080dfe0ef616bdf
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/alloc/src/boxed.rs:1042
  63:     0x7fdb89c1d80a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hd2747e1f2d5cec32
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/alloc/src/boxed.rs:1042
  64:     0x7fdb89c1d80a - std::sys::unix::thread::Thread::new::thread_start::hd0f336b4ef6808a7
                               at /rustc/e599b53e67ddd197a09a3d8720eed872df481aa0/library/std/src/sys/unix/thread.rs:87
  65:     0x7fdb89b313e9 - start_thread
  66:     0x7fdb89a59293 - __GI___clone
  67:                0x0 - <unknown>

@funbringer funbringer 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 Sep 25, 2020
@jonas-schievink jonas-schievink added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Sep 25, 2020
@funbringer
Copy link
Author

The backtrace suggests that ICE is caused by error formatting machinery. This is a corner case that should be fixed, but my original intention was to provide a concrete type. Sadly, it didn't work out either:

#![feature(type_alias_impl_trait)]

type Pointer<T> = impl std::ops::Deref<Target=T>;

fn test() -> Pointer<i32> {
    Box::new(1)
}

fn main() {
    println!("{:?}", *test());
}

results in:

error: non-defining opaque type use in defining scope
 --> gat.rs:5:14
  |
5 | fn test() -> Pointer<i32> {
  |              ^^^^^^^^^^^^
  |
note: used non-generic type `i32` for generic parameter
 --> gat.rs:3:14
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |              ^

error: aborting due to previous error

Will this be possible one day? My intuition tells me that the snippet above should work. Apologies if this is an improper place for such questions.

@Alexendoo
Copy link
Member

The original no longer ICEs since #87200, however the following does

type Pointer<T> = impl std::ops::Deref<Target=T>;

fn main() {
    let p: Pointer<_> = Box::new(1);
}

Maybe a different ICE?

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: UnresolvedIntTy(_#0i)', compiler\rustc_typeck\src\check\writeback.rs:499:75
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.55.0-nightly (74ef0c3e4 2021-07-16) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `main`
#1 [type_of] computing type of `Pointer::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0658`.

@Alexendoo
Copy link
Member

And the above no longer ICEs since #87141

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jul 23, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 30, 2021
Add some TAIT-related regression tests

Closes rust-lang#74280, closes rust-lang#77179.
r? `@oli-obk`
@bors bors closed this as completed in 2bdc54f Jul 30, 2021
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. E-needs-test Call 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)]` glacier ICE tracked in rust-lang/glacier. 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.
Development

Successfully merging a pull request may close this issue.

5 participants