Skip to content

ICE: OutputTypeParameterMismatch error under -Clink-dead-code #86703

Closed
@Manishearth

Description

@Manishearth

Code

Must be compiled with -C link-dead-code

Minimized test
use std::rc::Rc;
use std::borrow::{Cow, ToOwned};
use std::{mem, ptr};


pub unsafe trait Yokeable<'a>: 'static {
    type Output: 'a;
}

pub struct Yoke<Y: for<'a> Yokeable<'a>, C> {
    // must be the first field for drop order
    // this will have a 'static lifetime parameter, that parameter is a lie
    yokeable: Y,
    cart: C,
}


impl<Y: for<'a> Yokeable<'a>> Yoke<Y, Rc<[u8]>> {
    pub fn project<'this, P>(
        &'this self,
        f: for<'a> fn(&'this <Y as Yokeable<'a>>::Output, &'a ()) -> <P as Yokeable<'a>>::Output,
    ) -> Yoke<P, Rc<[u8]>>
    where
        P: for<'a> Yokeable<'a>,
    {
        unimplemented!()
    }
}

pub fn slice(y: Yoke<&'static str, Rc<[u8]>>) -> Yoke<&'static [u8], Rc<[u8]>> {
    y.project(move |yk, _| yk.as_bytes())
}


unsafe impl<'a, T: 'static + ToOwned + ?Sized> Yokeable<'a> for Cow<'static, T>
where
    <T as ToOwned>::Owned: Sized,
{
    type Output = Cow<'a, T>;

}

unsafe impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T {
    type Output = &'a T;
}
Nonminimized original failure

For the nonminimized example, the tests under https://github.com/Manishearth/icu4x/blob/yoke-ice/utils/yoke/src/yoke.rs#L474-L551 fail when run under -Clink-dead-code

Steps:

Adding code that makes use of the functions defined in these tests does not change anything, e.g. the function in the first test is not being called, but if you add code that calls it like below, the ICE still happens. I'm not sure as to what role -Clink-dead-code has here.

let rc: Rc<[u8]> = Rc::from("hello".as_bytes());
let yoke: Yoke<&'static str, Rc<[u8]>> = Yoke::attach_to_cart_badly(rc, |rc| std::str::from_utf8(&rc).unwrap());

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (e8cb1a4a5 2021-06-27)
binary: rustc
commit-hash: e8cb1a4a567ce88e459ffd431207eff2e0f0ffa5
commit-date: 2021-06-27
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

---- src/yoke.rs - yoke::Yoke<Y, C>::project (line 500) stdout ----
error: internal compiler error: compiler/rustc_trait_selection/src/traits/codegen.rs:78:17: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@src/yoke.rs:16:17: 16:38] as std::ops::FnMut<(&<main::_doctest_main_src_yoke_rs_500_0::Bar as yoke::Yokeable<'_>>::Output, &())>>, [Region(BrAnon(0))]), Binder(<[closure@src/yoke.rs:16:17: 16:38] as std::ops::FnMut<(&main::_doctest_main_src_yoke_rs_500_0::Bar, &())>>, []), Sorts(ExpectedFound { expected: main::_doctest_main_src_yoke_rs_500_0::Bar, found: <main::_doctest_main_src_yoke_rs_500_0::Bar as yoke::Yokeable<'_>>::Output }))` selecting `Binder(<[closure@src/yoke.rs:16:17: 16:38] as std::ops::FnMut<(&main::_doctest_main_src_yoke_rs_500_0::Bar, &())>>, [])` during codegen

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1007:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.55.0-nightly (e8cb1a4a5 2021-06-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C embed-bitcode=no -C link-dead-code --crate-type bin

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::ops::FnMut` fulfills its obligations
#1 [resolve_instance] resolving instance `<[closure@src/yoke.rs:16:17: 16:38] as std::ops::FnMut<(&main::_doctest_main_src_yoke_rs_500_0::Bar, &())>>::call_mut`
end of query stack
error: aborting due to previous error


Backtrace

stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_infer::infer::InferCtxtBuilder::enter
   8: rustc_trait_selection::traits::codegen::codegen_fulfill_obligation
   9: rustc_query_system::query::plumbing::get_query_impl
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::codegen_fulfill_obligation
  11: rustc_ty_utils::instance::inner_resolve_instance
  12: rustc_ty_utils::instance::resolve_instance
  13: rustc_query_system::query::plumbing::get_query_impl
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::resolve_instance
  15: rustc_middle::ty::instance::Instance::resolve_opt_const_arg
  16: rustc_middle::ty::instance::Instance::resolve
  17: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
  18: rustc_mir::monomorphize::collector::collect_neighbours
  19: rustc_mir::monomorphize::collector::collect_items_rec
  20: rustc_mir::monomorphize::collector::collect_items_rec
  21: rustc_session::utils::<impl rustc_session::session::Session>::time
  22: rustc_mir::monomorphize::collector::collect_crate_mono_items
  23: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  24: rustc_query_system::query::plumbing::get_query_impl
  25: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  26: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  27: rustc_interface::passes::QueryContext::enter
  28: rustc_interface::queries::Queries::ongoing_codegen
  29: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  30: rustc_span::with_source_map
  31: rustc_interface::interface::create_compiler_and_run
  32: scoped_tls::ScopedKey<T>::set

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions