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
Closed

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

matprec opened this issue Jan 14, 2019 · 2 comments

Comments

@matprec
Copy link
Contributor

@matprec 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.
@vorner
Copy link
Contributor

@vorner 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 _) -> _`
    |

Loading

@Aaron1011
Copy link
Member

@Aaron1011 Aaron1011 commented Jul 30, 2019

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

Loading

Aaron1011 added a commit to Aaron1011/rust that referenced this issue Jan 23, 2020
Aaron1011 added a commit to Aaron1011/rust that referenced this issue Jan 24, 2020
Dylan-DPC added a commit to Dylan-DPC/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 in 1605276 Jan 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants