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 using anonymization in impl Trait with HRTB #54895

Open
ubnt-intrepid opened this issue Oct 7, 2018 · 3 comments

Comments

@ubnt-intrepid
Copy link

commented Oct 7, 2018

I tried this code:

trait Trait<'a> {
    type Out;
    fn call(&'a self) -> Self::Out;
}

struct X(());

impl<'a> Trait<'a> for X {
    type Out = ();
    fn call(&'a self) -> Self::Out {
        ()
    }
}

fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
    X(())
}

fn main() {
    let _ = f();
}

It uses the anonymization of associated type inside of impl Trait in return type position.
The compiler reports an ICE as follows:

thread 'main' panicked at 'assertion failed: !erased_self_ty.has_escaping_regions()', librustc/ty/util.rs:369:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: internal compiler error: unexpected panic

Meta

rustc --version --verbose:

rustc 1.29.1 (b801ae664 2018-09-20)
binary: rustc
commit-hash: b801ae66425cf7c3c71052b19ef8f145b0d0513d
commit-date: 2018-09-20
host: x86_64-unknown-linux-gnu
release: 1.29.1
LLVM version: 7.0
backtrace:
thread 'main' panicked at 'assertion failed: !erased_self_ty.has_escaping_regions()', librustc/ty/util.rs:369: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:479
   6: std::panicking::begin_panic
   7: rustc::infer::anon_types::Instantiator::fold_anon_ty
   8: <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F, G> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
   9: rustc::ty::fold::TypeFoldable::fold_with
  10: rustc::infer::anon_types::Instantiator::fold_anon_ty
  11: <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F, G> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  12: rustc::infer::anon_types::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::instantiate_anon_types
  13: rustc_typeck::check::check_fn
  14: rustc::ty::context::tls::with_related_context
  15: rustc::infer::InferCtxtBuilder::enter
  16: rustc_typeck::check::typeck_tables_of
  17: rustc::ty::query::__query_compute::typeck_tables_of
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::context::tls::with_related_context
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  23: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  24: rustc_typeck::collect::type_of
  25: rustc::ty::query::__query_compute::type_of
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::type_of<'tcx>>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::context::tls::with_related_context
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  31: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::type_of
  32: rustc_typeck::check::check_item_type
  33: rustc::hir::Crate::visit_all_item_likes
  34: rustc_typeck::check::check_item_types
  35: rustc::util::common::time
  36: rustc_typeck::check_crate
  37: rustc::ty::context::tls::enter_context
  38: <std::thread::local::LocalKey<T>>::with
  39: rustc::ty::context::TyCtxt::create_and_enter
  40: rustc_driver::driver::compile_input
  41: rustc_driver::run_compiler_with_pool
  42: <scoped_tls::ScopedKey<T>>::set
  43: <scoped_tls::ScopedKey<T>>::set
  44: syntax::with_globals
  45: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  46: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  47: rustc_driver::run
  48: rustc_driver::main
  49: std::rt::lang_start::{{closure}}
  50: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  51: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  52: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  53: main
  54: __libc_start_main
  55: <unknown>
query stack during panic:
#0 [typeck_tables_of] processing `f`
#1 [type_of] processing `f::{{impl-Trait}}`
end of query stack

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.29.1 (b801ae664 2018-09-20) running on x86_64-unknown-linux-gnu
@ubnt-intrepid

This comment has been minimized.

Copy link
Author

commented Oct 7, 2018

The ICE does only appear when the anonymization uses the lifetime parameter from HRTB. ICE does not occur in all of the following cases:

fn f() -> impl for<'a> Trait<'a, Out = impl Sized> { ... }
fn f<'b>() -> impl for<'a> Trait<'a, Out = impl Sized + 'b> { ... }
fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'static> { ... }

@zackmdavis zackmdavis added the I-ICE label Oct 8, 2018

@earthengine

This comment has been minimized.

Copy link

commented Oct 8, 2018

You don't need newtype nor a method in the trait:

trait Trait<'a> {
    type Out;
}
impl<'a> Trait<'a> for () {
    type Out = ();
}
fn main() -> impl for<'a> Trait<'a, Out = impl ?Sized + 'a> {
    ()
}

It is not even need a FnXXX trait variants. But it is still very much like #53420 (and so duplicates #29997), except that the error message is different. In both cases, the normalization didn't erase the HRTB lifetime, which is expected to already happened later.

Furthermore, if fill in the body with the one like in #53420 the error message is this, not the other one. So this error message is closer to the actual defeat.

I didn't realized we can have impl Trait in the associated type binding position before. But it looks problematic:

//error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
//fn f1() -> impl FnOnce() -> impl Clone
//OK with #![feature(unboxed_closures)]
fn f2() -> impl FnOnce<(), Output=impl Clone> {...}
@jonas-schievink

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

Triage: Still reproduces on current stable and nightly.

@nagisa nagisa added P-high I-ICE and removed I-ICE I-nominated labels Aug 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.