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 using associated type from higher ranked trait #70120

Closed
lord opened this issue Mar 18, 2020 · 4 comments · Fixed by #85499
Closed

ICE using associated type from higher ranked trait #70120

lord opened this issue Mar 18, 2020 · 4 comments · Fixed by #85499
Labels
A-associated-items Area: Associated items (types, constants & functions) A-codegen Area: Code generation A-trait-system Area: Trait system 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-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lord
Copy link

lord commented Mar 18, 2020

Apologies if this is already reported somewhere; couldn't find it during a quick search.

Getting an internal compiler error for this code (playground):

pub trait MyTrait<'a> {
    type Output: 'a;
    fn gimme_value(&self) -> Self::Output;
}

pub struct MyStruct;

impl<'a> MyTrait<'a> for MyStruct {
    type Output = &'a usize;
    fn gimme_value(&self) -> Self::Output {
        unimplemented!()
    }
}

fn meow<T, F>(t: T, f: F)
where
    T: for<'any> MyTrait<'any>,
    F: for<'any2> Fn(<T as MyTrait<'any2>>::Output),
{
    let v = t.gimme_value();
    f(v);
}

fn main() {
    let struc = MyStruct;
    meow(struc, |foo| {
        println!("{:?}", foo);
    })
}

The error reads:

error: internal compiler error: src/librustc_infer/traits/codegen/mod.rs:61: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(<MyStruct as MyTrait<'_>>::Output,)>>), Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>), Sorts(ExpectedFound { expected: &usize, found: <MyStruct as MyTrait<'_>>::Output }))` selecting `Binder(<[closure@src/main.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>)` during codegen

Tested in 1.42.0, 1.43.0-beta.1, and 1.44.0-nightly (2020-03-17 7ceebd98c6a15ae30e77)

@Alexendoo Alexendoo added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2020
@Alexendoo
Copy link
Member

error: internal compiler error: src\librustc\traits\codegen\mod.rs:57: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@.\70120.rs:26:17: 28:6] as std::ops::Fn<(<MyStruct as MyTrait<'_>>::Output,)>>), Binder(<[closure@.\70120.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>), Sorts(ExpectedFound { expected: &usize, found: <MyStruct as MyTrait<'_>>::Output }))` selecting `Binder(<[closure@.\70120.rs:26:17: 28:6] as std::ops::Fn<(&usize,)>>)` during codegen

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:873:9
   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_errors::snippet::Style as core::fmt::Debug>::fmt
   8: rustc_errors::HandlerInner::treat_err_as_bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::bug_fmt
  11: <rustc::ty::trait_def::TraitImpls as rustc_data_structures::stable_hasher::HashStable<rustc::ich::hcx::StableHashingContext>>::hash_stable
  12: <rustc::ty::trait_def::TraitImpls as rustc_data_structures::stable_hasher::HashStable<rustc::ich::hcx::StableHashingContext>>::hash_stable
  13: rustc::util::bug::bug_fmt
  14: rustc::util::bug::bug_fmt
  15: rustc::ty::context::TyCtxt::caller_location_ty
  16: rustc::traits::codegen::codegen_fulfill_obligation
  17: <rustc::ty::query::Query as rustc_data_structures::stable_hasher::HashStable<rustc::ich::hcx::StableHashingContext>>::hash_stable
  18: rustc::middle::weak_lang_items::<impl rustc::ty::context::TyCtxt>::is_weak_lang_item
  19: rustc::dep_graph::graph::DepGraph::assert_ignored
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::try_print_query_stack
  21: rustc::ty::instance::Instance::resolve
  22: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_terminator_kind
  23: rustc_mir::monomorphize::collector::collect_crate_mono_items
  24: rustc_mir::monomorphize::collector::collect_crate_mono_items
  25: <rustc_mir::util::elaborate_drops::Unwind as core::fmt::Debug>::fmt
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: rustc_mir::monomorphize::partitioning::compute_codegen_unit_name
  28: <rustc_codegen_llvm::llvm_::archive_ro::ArchiveRO as core::ops::drop::Drop>::drop
  29: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  30: <rustc_codegen_llvm::debuginfo::metadata::MemberDescription as core::fmt::Debug>::fmt
  31: <rustc_codegen_llvm::builder::Builder as rustc_codegen_ssa::traits::builder::BuilderMethods>::unchecked_umul
  32: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  33: <<serde::de::impls::range::Field as serde::de::Deserialize>::deserialize::FieldVisitor as serde::de::Visitor>::expecting
  34: rustc_interface::passes::BoxedResolver::to_resolver_outputs
  35: rustc_interface::queries::Queries::ongoing_codegen
  36: rustc_driver::pretty::print_after_hir_lowering
  37: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  38: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  39: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  40: _rust_maybe_catch_panic
  41: rustc_driver::pretty::print_after_hir_lowering
  42: 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..Sync$u2b$core..marker..Send$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  43: std::sys::windows::thread::Thread::new
  44: BaseThreadInitThunk
  45: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.42.0 (b8cedc004 2020-03-09) running on x86_64-pc-windows-msvc

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::ops::Fn` fulfills its obligations
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error

@Centril Centril added A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system labels Mar 19, 2020
@Centril Centril changed the title Internal compiler error when using associated type from higher ranked trait ICE using associated type from higher ranked trait Mar 19, 2020
@Centril Centril added A-codegen Area: Code generation I-nominated labels Mar 19, 2020
@spastorino spastorino added the P-high High priority label Mar 19, 2020
@pnkfelix
Copy link
Member

I think this falls under bucket issue #62529

@pnkfelix
Copy link
Member

Discussed in T-compiler meeting. Dupe of #62529. Downgrading to P-medium.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated P-high High priority labels Mar 19, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 27, 2020
@valpackett
Copy link
Contributor

Encountered this while working on a callback taking a capnproto builder:

Simplified code
// the proto is just: struct Whoops { boing @0 :Bool; }

pub mod schemas_capnp {
    include!(concat!(env!("OUT_DIR"), "/schemas_capnp.rs"));
}

fn fancy_serialize<
    Own: for<'a> capnp::traits::Owned<'a>,
    F: Fn(&mut <Own as capnp::traits::Owned<'_>>::Builder),
>(
    cb: F,
) -> Vec<u8> {
    let mut builder = capnp::message::Builder::new_default();
    {
        let mut root = builder.init_root();
        cb(&mut root);
    }
    capnp::serialize::write_message_to_words(&builder)
}

fn main() {
    fancy_serialize::<schemas_capnp::whoops::Owned, _>(|root| root.set_boing(true));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-codegen Area: Code generation A-trait-system Area: Trait system 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-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants