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

Closed
ubnt-intrepid opened this issue Oct 7, 2018 · 6 comments · Fixed by #94081
Closed

ICE when using anonymization in impl Trait with HRTB #54895

ubnt-intrepid opened this issue Oct 7, 2018 · 6 comments · Fixed by #94081
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

Comments

@ubnt-intrepid
Copy link

ubnt-intrepid 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
Copy link
Author

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 Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 8, 2018
@earthengine
Copy link

earthengine 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 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. A-lifetimes Area: Lifetimes / regions I-nominated labels Aug 6, 2019
@jonas-schievink
Copy link
Contributor

Triage: Still reproduces on current stable and nightly.

@nagisa nagisa added P-high High priority I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated labels Aug 8, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@pnkfelix
Copy link
Member

triage: I'm going to leave this as P-high because the ICE message is so inscrutable. (I'd be tempted to downgrade to P-medium if the message included some hint as to how one could work around the bug.)

Self-assigning.

@pnkfelix pnkfelix self-assigned this Nov 14, 2019
@Centril
Copy link
Contributor

Centril commented Mar 10, 2020

Triage: Still reproduces, cc @matthewjasper @Aaron1011

@matthiaskrgr
Copy link
Member

This is a regression since 1.28
@rustbot modify labels: +regression-from-stable-to-stable

@rustbot rustbot added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 20, 2020
@jackh726 jackh726 added the WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 label Feb 1, 2022
@bors bors closed this as completed in f132bcf Mar 30, 2022
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. A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
Projects
None yet
Development

Successfully merging a pull request may close this issue.