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

"internal compiler error" on Higher-Ranked Trait Bound for impl Trait in return position #67830

Open
TOETOE55 opened this issue Jan 3, 2020 · 2 comments

Comments

@TOETOE55
Copy link

@TOETOE55 TOETOE55 commented Jan 3, 2020

I needed a Fn like trait, and return an impl trait with Higher-Ranked Trait Bound. But rustc panicked.

I tried this code:

trait MyFn<Arg> {
    type Output;
    fn call(&self, arg: Arg) -> Self::Output;
}

struct Wrap<F>(F);

impl<A, B, F> MyFn<A> for Wrap<F>
where
    F: Fn(A) -> B
{
    type Output = B;

    fn call(&self, arg: A) -> Self::Output {
        (self.0)(arg)
    }
}


struct A;
fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
    Wrap(|a| Some(a).into_iter())
}

I expected it was checked, but I received this compiler bug:

thread 'rustc' panicked at 'assertion failed: !erased_self_ty.has_escaping_bound_vars()', src\librustc\ty\util.rs:441:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSliceMut as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: <rustc::ty::query::Providers as core::default::Default>::default
   8: rustc::ty::util::<impl rustc::ty::context::TyCtxt>::required_region_bounds
   9: rustc::infer::opaque_types::Instantiator::fold_opaque_ty
  10: rustc::ty::binding::BindingMode::convert
  11: rustc::infer::opaque_types::Instantiator::fold_opaque_ty
  12: <rustc_typeck::collect::find_opaque_ty_constraints::ConstraintLocator as rustc::hir::intravisit::Visitor>::visit_trait_item
  13: rustc_typeck::check::FnCtxt::apply_adjustments
  14: <rustc_typeck::check::GatherLocalsVisitor as rustc::hir::intravisit::Visitor>::visit_pat
  15: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  16: <rustc_typeck::check::CheckItemTypesVisitor as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  17: <rustc_typeck::check::autoderef::AutoderefKind as core::fmt::Debug>::fmt
  18: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  19: <rustc_typeck::variance::test::VarianceTest as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  20: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  21: rustc_typeck::collect::checked_type_of
  22: <rustc_typeck::collect::has_late_bound_regions::LateBoundRegionsDetector as rustc::hir::intravisit::Visitor>::visit_lifetime
  23: rustc::middle::weak_lang_items::<impl rustc::ty::context::TyCtxt>::is_weak_lang_item
  24: rustc::dep_graph::graph::DepGraph::assert_ignored
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::try_print_query_stack
  26: rustc::ty::util::Discr::checked_add
  27: rustc::ty::util::<impl rustc::ty::context::TyCtxt>::try_expand_impl_trait_type
  28: <rustc_typeck::check::check_opaque_for_inheriting_lifetimes::ProhibitOpaqueVisitor as rustc::ty::fold::TypeVisitor>::visit_region
  29: <rustc_typeck::check::autoderef::AutoderefKind as core::fmt::Debug>::fmt
  30: <rustc_typeck::check::CheckItemTypesVisitor as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  31: <rustc_typeck::check::autoderef::AutoderefKind as core::fmt::Debug>::fmt
  32: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  33: <rustc_typeck::variance::test::VarianceTest as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  34: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  35: <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt
  36: rustc_typeck::check_crate
  37: rustc_typeck::check_crate
  38: rustc_interface::passes::BoxedResolver::to_resolver_outputs
  39: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  40: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  41: <rustc_traits::chalk_context::ChalkContext as chalk_engine::context::ContextOps<rustc_traits::chalk_context::ChalkArenas>>::canonical
  42: <syntax_pos::symbol::LocalInternedString as core::fmt::Display>::fmt
  43: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  44: rustc_interface::passes::BoxedGlobalCtxt::complete
  45: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  46: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  47: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  48: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  49: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  50: _rust_maybe_catch_panic
  51: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  52: ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Send$u2b$core..marker..Sync$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  53: std::sys::windows::thread::Thread::new
  54: BaseThreadInitThunk
  55: RtlUserThreadStart
  
  
  
query stack during panic:
#0 [typeck_tables_of] processing `test`
#1 [type_of] processing `test::{{opaque}}#0`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack

Meta

rustc --version --verbose:

rustc 1.40.0 (73528e339 2019-12-16)
binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16
host: x86_64-pc-windows-msvc
release: 1.40.0
LLVM version: 9.0
@TOETOE55

This comment has been minimized.

Copy link
Author

@TOETOE55 TOETOE55 commented Jan 3, 2020

hmmm, maybe it is equivalent to (no!)

fn test<'a>() -> impl MyFn<&'a A, Output=impl Iterator + 'a>

but what about:

fn test(f: impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a>) {
    let x = A;
    f.call(&x);
}

it couldn't check:

fn test(_: impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a>) {
                                                            ^^ undeclared lifetime

but this is OK:

fn test(_: impl for<'a> MyFn<&'a A, Output=IntoIter<&'a A>>) {
    let x = A;
    f.call(&x);
}

playground here
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f15195784e3fe07799fdb4ee84d9c049

@pnkfelix

This comment has been minimized.

Copy link
Member

@pnkfelix pnkfelix commented Jan 9, 2020

triage: P-high. Removing nominaton, but cc @matthewjasper and @nikomatsakis for assistance.

@pnkfelix pnkfelix added P-high and removed I-nominated labels Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.