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 with HRTB and lifetime on subtrait #53943

Closed
alecmocatta opened this issue Sep 4, 2018 · 4 comments
Closed

ICE with HRTB and lifetime on subtrait #53943

alecmocatta opened this issue Sep 4, 2018 · 4 comments
Labels
A-trait-system Area: Trait system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@alecmocatta
Copy link
Contributor

alecmocatta commented Sep 4, 2018

I'm using a lifetime parameter on a trait such that I can constrain Item to for <'a> &'a X. I tried to "encapsulate" the lifetime into a subtrait to avoid other issues and got an ICE on stable, nightly and with/without NLL. I suspect this usage should error but I could be mistaken.

trait Sink {
    type Item;
    fn next(&mut self, Self::Item);
}
trait SinkA<'a>: Sink {}

struct X(u8);

fn abc<I>(mut i: I) where for<'a> I: SinkA<'a, Item=&'a X> {
    let x = X(0);
    i.next(&x);
}

(Playground)

error: internal compiler error: librustc/infer/higher_ranked/mod.rs:160: no representative region for `ReSkolemized(UniverseIndex(1), BrNamed(crate0:DefIndex(1:13), 'a))` in `{ReSkolemized(UniverseIndex(1), BrNamed(crate0:DefIndex(1:13), 'a))}`

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:515
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::bug_fmt
  14: rustc::infer::higher_ranked::<impl rustc::infer::combine::CombineFields<'a, 'gcx, 'tcx>>::higher_ranked_match::{{closure}}::{{closure}}::{{closure}}
  15: <std::collections::hash::map::HashMap<K, V, S> as core::iter::traits::FromIterator<(K, V)>>::from_iter
  16: rustc::infer::InferCtxt::commit_if_ok
  17: rustc::infer::InferCtxt::match_poly_projection_predicate
  18: rustc::traits::project::confirm_param_env_candidate
  19: rustc::traits::project::opt_normalize_projection_type
  20: rustc::traits::project::normalize_projection_type
  21: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  22: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  23: rustc::ty::fold::TypeFoldable::fold_with
  24: rustc::ty::fold::TypeFoldable::fold_with
  25: rustc::traits::project::normalize
  26: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
  27: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
  28: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  29: rustc::ty::wf::WfPredicates::normalize
  30: rustc::ty::wf::predicate_obligations
  31: rustc_typeck::check::wfcheck::check_where_clauses
  32: rustc_typeck::check::wfcheck::check_fn_or_method
  33: rustc::ty::context::tls::with_related_context
  34: rustc::infer::InferCtxtBuilder::enter
  35: rustc_typeck::check::wfcheck::check_item_well_formed
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::context::tls::with_related_context
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  42: rustc::hir::Crate::visit_all_item_likes
  43: rustc::session::Session::track_errors
  44: rustc::util::common::time
  45: rustc_typeck::check_crate
  46: rustc::ty::context::tls::enter_context
  47: <std::thread::local::LocalKey<T>>::with
  48: rustc::ty::context::TyCtxt::create_and_enter
  49: rustc_driver::driver::compile_input
  50: rustc_driver::run_compiler_with_pool
  51: <scoped_tls::ScopedKey<T>>::set
  52: syntax::with_globals
  53: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  54: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  55: rustc_driver::run
  56: rustc_driver::main
  57: std::rt::lang_start::{{closure}}
  58: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  59: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  60: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  61: main
  62: __libc_start_main
  63: <unknown>
query stack during panic:
#0 [check_item_well_formed] processing `abc`
end of query stackerror: aborting due to previous error

note: the compiler unexpectedly panicked. this is a bug.

note: rustc 1.28.0 (9634041f0 2018-07-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib
@csmoe csmoe added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 4, 2018
@Havvy Havvy added the A-trait-system Area: Trait system label Sep 5, 2018
@earthengine
Copy link

Minimum reproducable:

trait MyF<'a>: FnOnce() -> &'a () {}

fn test<F>(_: F) where for<'a> F: MyF<'a, Output=&'a ()> {
}

fn main(){
}

Note: This bug depends on the need to specify an associate type in the super trait, with a lifetime. Then, in the trait bound where clause, specify the associate type explicitly.

alecmocatta added a commit to alecmocatta/office-hours that referenced this issue Sep 13, 2018
I'm working on data-parallelism library, heavily inspired by Rayon but focused on describing certain computations on a dataset in an SQL-like manner, somewhat akin to Diesel.

One part of this combines HRTBs with associated types. I've bumped into a few issues that have made things a bit tricky ([#30472](rust-lang/rust#30472), [#30867](rust-lang/rust#30867), [#53943](rust-lang/rust#53943), and similar), the hardest to work around however has been that I don't believe it's currently possible to write this:
```rust
type Task = for<'a> <B as Abc<&'a A::Item>>::Task;
```
Currently I've resorted to a dummy trait, manually reimplemented on various structs without the reference, such that I can do:
```rust
type Task = <B as AbcDummy<A::Item>>::Task;
```
and (horribly) transmute between the two.

I'd be very interested to discuss

 1) issues I've bumped into combining HRTBs and associated types;
 2) how to get rid of this transmute and the dummy trait;
 3) any feedback on the library before I publish and promote it, given it's heavily inspired by your work on Rayon!

I can do any of the Monday or Friday times listed, though I have a preference for the 16 - 16.30 slots.

Again, much appreciation for you doing this, I think it's awesome!
@alecmocatta
Copy link
Contributor Author

To aid searchability here's the slightly different error from latest nightly. The backtrace is largely identical.

error: internal compiler error: librustc/infer/higher_ranked/mod.rs:162: no representative region for `RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:13), 'a) })` in `{RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:13), 'a) })}`

@cyplo
Copy link
Contributor

cyplo commented Feb 1, 2019

The minimum reproducable still ICEs on stable - rustc 1.32.0 (9fda7c2 2019-01-16).
Seems fixed on beta (1.33.0-beta.4)

@alecmocatta
Copy link
Contributor Author

Closing as fixed on beta & nightly. Thanks wonderful member(s) of the rust community that resolved this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants