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 inferring the type of existential type with trait alias bounds #57611

Closed
matprec opened this issue Jan 14, 2019 · 2 comments · Fixed by #68498
Closed

ICE when inferring the type of existential type with trait alias bounds #57611

matprec opened this issue Jan 14, 2019 · 2 comments · Fixed by #68498
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matprec
Copy link
Contributor

matprec commented Jan 14, 2019

Minimised, reproducible example:

#![feature(trait_alias)]
#![feature(existential_type)]

trait Foo {
    type Bar: Baz<Self, Self>;

    fn bar(&self) -> Self::Bar;
}

struct X;

impl Foo for X {
    existential type Bar: Baz<Self, Self>;

    fn bar(&self) -> Self::Bar {
        |x| x
    }
}

trait Baz<A, B> = Fn(&A) -> &B;

See playground

Backtrace

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/lib.rs:13:5
   |
13 |     existential type Bar: Baz<Self, Self>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(&X,)>`
              found type `std::ops::FnOnce<(&X,)>`

thread 'rustc' panicked at 'assertion failed: !ty.needs_infer() && !ty.has_placeholders()', src/librustc_typeck/check/writeback.rs:119:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::begin_panic
   7: rustc_typeck::check::writeback::WritebackCx::visit_node_id
   8: <rustc_typeck::check::writeback::WritebackCx<'cx, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr
   9: rustc_typeck::check::writeback::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::resolve_type_vars_in_body
  10: rustc::ty::context::GlobalCtxt::enter_local
  11: rustc_typeck::check::typeck_tables_of
  12: rustc::ty::query::__query_compute::typeck_tables_of
  13: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  14: rustc::dep_graph::graph::DepGraph::with_task_impl
  15: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  16: rustc_typeck::collect::find_existential_constraints::ConstraintLocator::check
  17: rustc::hir::intravisit::Visitor::visit_nested_impl_item
  18: rustc::hir::intravisit::walk_item
  19: rustc_typeck::collect::find_existential_constraints
  20: rustc_typeck::collect::type_of
  21: rustc::ty::query::__query_compute::type_of
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::type_of<'tcx>>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  25: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_impl_item
  26: rustc::hir::map::Map::visit_item_likes_in_module
  27: rustc_typeck::collect::collect_mod_item_types
  28: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::collect_mod_item_types<'tcx>>::compute
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  32: rustc_typeck::collect::collect_item_types
  33: rustc::util::common::time
  34: rustc_typeck::check_crate
  35: <std::thread::local::LocalKey<T>>::with
  36: rustc::ty::context::TyCtxt::create_and_enter
  37: rustc_driver::driver::compile_input
  38: <scoped_tls::ScopedKey<T>>::set
  39: rustc_driver::run_compiler
  40: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
#0 [typeck_tables_of] processing `<X as Foo>::bar`
#1 [type_of] processing `<X as Foo>::Bar`
#2 [collect_mod_item_types] collecting item types in top-level module
end of query stack
error: aborting due to previous error

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

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.33.0-nightly (2fadb0a16 2019-01-13) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 15, 2019
@vorner
Copy link
Contributor

vorner commented Jan 18, 2019

Hello

I'm getting the same ICE, but without any unstable features. I don't have a minimized example, though, but it may be another data point when searching for the problem.

It's this commit: https://github.com/vorner/spirit/tree/rust-crash. The commit happens with

cargo run --package spirit-tokio --example hws-tokio

The code is not correct, it wouldn't compile even if the compiler didn't panic.

rustc 1.33.0-nightly (daa53a52a 2019-01-17)

It doesn't happen on stable, but I guess it's because it bails out sooner on closures taking references:

error[E0631]: type mismatch in closure arguments
   --> spirit-tokio/examples/hws-tokio.rs:100:67
    |
96  |     let init = spirit_tokio::handlers::HandleListenerInit(|_, _| (), |conn, _| handle_connection(conn));
    |                                                                      --------------------------------- found signature of `fn(spirit_tokio::net::limits::LimitedConn<tokio::net::TcpStream>, _) -> _`
...
100 |         .with(Pipeline::new("listen").extract_cfg(Config::listen).transform(init).check())
    |                                                                   ^^^^^^^^^ expected signature of `for<'r> fn(spirit_tokio::net::limits::LimitedConn<tokio::net::TcpStream>, &'r mut _) -> _`
    |

@oli-obk oli-obk self-assigned this Jan 25, 2019
@jonas-schievink jonas-schievink added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2019
@Centril Centril added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
@Aaron1011
Copy link
Member

This still produces an error on the latest nightly (not sure if it's supposed to compile or not), but no longer ICEs.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 25, 2020
…Centril

Add some type-alias-impl-trait regression tests

Fixes rust-lang#57611
Fixes rust-lang#57807
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 25, 2020
…Centril

Add some type-alias-impl-trait regression tests

Fixes rust-lang#57611
Fixes rust-lang#57807
@bors bors closed this as completed in 1605276 Jan 26, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 4, 2022
…-sig, r=lcnr

Elaborate supertrait obligations when deducing closure signatures

We elaborate the supertrait obligations of any registered predicates for a closure to see if we can infer a closure signature.

This is not as general of a fix as it *could* be, since we just elaborate supertrait bounds instead of doing a theoretical walk of _all_ registered predicates that might cause us to deduce `Fn` trait information for a closure infer var. I don't even know how to come up with an example that fails here but would work with a more general system.

Fixes rust-lang#23012
Also fixes the existing compile failure in rust-lang#57611

r? `@ghost` for now until I do a perf run
cc `@nikomatsakis` since you commented on rust-lang#23012 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

7 participants