Skip to content

Rust panics at typecheck ICE stable 1.34.1 and nightly 1.35.0 #60283

Closed
@RustyYato

Description

@RustyYato

possibly related to #60070, #52812, and #29997

pub trait Trait<'a> {
    type Item;
}

impl<'a> Trait<'a> for () {
    type Item= ();
}

pub fn foo<T, F>(_: T, _: F)
where T: for<'a> Trait<'a>,
      F: for<'a> FnMut(<T as Trait<'a>>::Item) {}

fn main() {
    foo((), drop)
}

stack trace

error: internal compiler error: src\librustc\traits\project.rs:1457: Failed to unify obligation `Obligation(predicate=ProjectionTy { substs: [fn(_) {std::mem::drop::<_>}, (<() as Trait<'a>>::Item,)], item_def_id: DefId(2/0:1000 ~ core[d10a]::ops[0]::function[0]::FnOnce[0]::Output[0]) },depth=0)` with poly_projection `Binder(ProjectionPredicate(ProjectionTy { substs: [fn(_) {std::mem::drop::<_>}, ((),)], item_def_id:DefId(2/0:1000 ~ core[d10a]::ops[0]::function[0]::FnOnce[0]::Output[0]) }, ()))`: Sorts(ExpectedFound { expected: (), found: <() as Trait<'a>>::Item })
  --> src\main.rs:14:5
   |
14 |     foo((), drop)
   |     ^^^

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:570:9
stack backtrace:
   0: std::sys_common::alloc::realloc_fallback
   1: std::panicking::take_hook
   2: std::panicking::take_hook
   3: rustc::ty::structural_impls::<impl rustc::ty::context::Lift for rustc::ty::adjustment::AutoBorrow>::lift_to_tcx
   4: std::panicking::rust_panic_with_hook
   5: <rustc::ty::CrateInherentImpls as core::fmt::Debug>::fmt
   6: rustc::ty::structural_impls::<impl rustc::ty::context::Lift for rustc::mir::interpret::GlobalId>::lift_to_tcx
   7: rustc::util::bug::bug_fmt
   8: rustc::ty::trait_def::TraitDef::ancestors
   9: rustc::ty::trait_def::TraitDef::ancestors
  10: rustc::ty::trait_def::TraitDef::ancestors
  11: rustc::util::bug::bug_fmt
  12: rustc::util::bug::bug_fmt
  13: rustc::traits::project::normalize_projection_type
  14: rustc::traits::project::normalize_projection_type
  15: rustc::traits::project::normalize_projection_type
  16: rustc::traits::project::poly_project_and_unify_type
  17: rustc::infer::InferCtxt::commit_from
  18: rustc::ty::structural_impls::<impl rustc::ty::context::Lift for rustc::mir::interpret::GlobalId>::lift_to_tcx
  19: <rustc::traits::fulfill::FulfillmentContext as rustc::traits::engine::TraitEngine>::select_where_possible
  20: rustc_typeck::check::FnCtxt::field_ty
  21: rustc_typeck::check::FnCtxt::self_type_matches_expected_vid
  22: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  23: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  24: rustc_typeck::check::FnCtxt::check_struct_path
  25: rustc_typeck::check::FnCtxt::check_struct_path
  26: rustc_typeck::check::FnCtxt::check_block_no_value
  27: rustc_typeck::check::FnCtxt::check_struct_path
  28: rustc_typeck::check::FnCtxt::check_struct_path
  29: rustc_typeck::check::FnCtxt::impl_self_ty
  30: <rustc_typeck::check::GatherLocalsVisitor as rustc::hir::intravisit::Visitor>::visit_pat
  31: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  32: <rustc_typeck::check::CheckItemTypesVisitor as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  33: <rustc_typeck::variance::constraints::ConstraintContext as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_impl_item
  34: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  35: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  36: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  37: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  38: <rustc_typeck::check::CheckItemTypesVisitor as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
  39: <rustc_typeck::variance::constraints::ConstraintContext as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_impl_item
  40: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  41: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  42: <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt
  43: rustc_typeck::check_crate
  44: rustc_interface::passes::BoxedResolver::to_expansion_result
  45: rustc_driver::set_sigpipe_handler
  46: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  47: <env_logger::fmt::WriteStyle as core::default::Default>::default
  48: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  49: rustc_driver::set_sigpipe_handler
  50: rustc_driver::set_sigpipe_handler
  51: rustc_interface::interface::Compiler::output_file
  52: rustc_driver::set_sigpipe_handler
  53: <env_logger::fmt::WriteStyle as core::default::Default>::default
  54: rustc_driver::set_sigpipe_handler
  55: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  56: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  57: rustc_driver::set_sigpipe_handler
  58: _rust_maybe_catch_panic
  59: rustc_driver::set_sigpipe_handler
  60: <std::error::<impl core::convert::From<alloc::string::String> for alloc::boxed::Box<dyn +std::error::Error+core::marker::Send+core::marker::Sync>>::from::StringError as core::fmt::Display>::fmt
  61: std::sys::windows::thread::Thread::new
  62: BaseThreadInitThunk
  63: RtlUserThreadStart
query stack during panic:
#0 [typeck_tables_of] processing `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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.35.0-nightly (70f130954 2019-04-16) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

Metadata

Metadata

Assignees

Labels

A-type-systemArea: Type systemC-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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions