Skip to content

ICE when using anonymization in impl Trait with HRTB #54895

Closed
@ubnt-intrepid

Description

@ubnt-intrepid

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

Metadata

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-traitsWorking group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions