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: invalid CoerceUnsized impl_source: Err(FulfillmentError) #135470

Open
c-git opened this issue Jan 14, 2025 · 7 comments
Open

ICE: invalid CoerceUnsized impl_source: Err(FulfillmentError) #135470

c-git opened this issue Jan 14, 2025 · 7 comments
Labels
A-monomorphization Area: Monomorphization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@c-git
Copy link

c-git commented Jan 14, 2025

If you need me to try to remove more of the dependencies please let me know but I got tired while producing the MRE. I managed to remove all the macros and shuttle dependencies but reached a local minimum and would have try to start unwrapping tonic next. If it's needed let me know but wasn't sure if it was worth the effort. The code can also be found in this repo. Because I didn't finish removing all the dependencies I've also included the Cargo.toml

Cargo.toml

[package]
name = "ice_mre_invalid_coerce_unsized"
version = "0.1.0"
edition = "2021"

[dependencies]
async-trait = "0.1.85"
http = "1.2"
opendal = "0.51"
serde = "1.0.217"
serde_json = "1.0.135"
tokio = { version = "1.43", default-features = false, features = ["macros", "rt-multi-thread"] }
tonic = "0.12.3"
tower = "0.5.2"

Code

use async_trait::async_trait;
use serde::Deserialize;
use std::future::Future;
use tonic::{server::NamedService, transport::Server};

#[tokio::main]
async fn main() {
    let svc = RuntimeServer::new(runner);
    Server::builder().add_service(svc);
}

async fn runner() {
    // Doesn't happen if I trivially replace either of these lines like with a todo!() instead of the assigned value
    let x: Wrapper = serde_json::from_slice("".as_bytes()).unwrap();
    let operator: opendal::Operator = x.inner.unwrap();

    // Didn't test
    // operator.delete_stream().await.unwrap();
    // operator.delete_try_stream().await.unwrap();

    // Only happens with any one of the follow async but not the other functions (barring the two mentioned as not tested above)
    operator.check().await.unwrap();
    operator.write("", vec![0; 2]).await.unwrap();
    operator.writer("").await.unwrap();
    operator.write_with("", "").await.unwrap();
    operator
        .delete_try_iter([Ok("")].into_iter())
        .await
        .unwrap();
    operator.deleter().await.unwrap();
    operator.list("").await.unwrap();
    operator.remove_all("").await.unwrap();
    operator.list_with("").await.unwrap();
    operator.lister("").await.unwrap();
    operator.lister_with("").await.unwrap();
}

pub struct RuntimeServer<T: 'static + Clone> {
    runner: T,
}

#[derive(Default, Deserialize)]
struct Wrapper {
    #[serde(skip)]
    inner: Option<opendal::Operator>,
}

pub type BoxFuture<T, E> =
    std::pin::Pin<Box<dyn self::Future<Output = Result<T, E>> + Send + 'static>>;

#[async_trait]
pub trait Runner: Send + Sync + Clone {}

#[async_trait]
impl<T> Runner for RuntimeServer<T> where T: Runner + Send + 'static {}

#[async_trait]
impl<F, O> Runner for F
where
    F: FnOnce() -> O + Send + Sync + Clone,
    O: Future<Output = ()> + Send,
{
}

impl<T: Runner> Clone for RuntimeServer<T> {
    fn clone(&self) -> Self {
        todo!()
    }
}

impl<T: Runner> NamedService for RuntimeServer<T> {
    const NAME: &'static str = "";
}
impl<T: Runner> RuntimeServer<T> {
    pub fn new(_inner: T) -> Self {
        todo!()
    }
}

impl<T, B> tower::Service<http::Request<B>> for RuntimeServer<T>
where
    T: Runner,
    B: tonic::codegen::Body + Send + 'static,
    B::Error: std::error::Error + Sync + Send + 'static,
{
    type Response = http::Response<tonic::body::BoxBody>;
    type Error = std::convert::Infallible;
    type Future = BoxFuture<Self::Response, Self::Error>;
    fn poll_ready(
        &mut self,
        _cx: &mut std::task::Context<'_>,
    ) -> std::task::Poll<Result<(), Self::Error>> {
        todo!()
    }

    fn call(&mut self, req: http::Request<B>) -> Self::Future {
        match req.uri().path() {
            "" => {
                #[allow(non_camel_case_types, dead_code)]
                struct LoadSvc<T: Runner>(pub T);
                impl<T: Runner> tonic::server::UnaryService<()> for LoadSvc<T> {
                    type Response = ();
                    type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
                    fn call(&mut self, _request: tonic::Request<()>) -> Self::Future {
                        todo!()
                    }
                }
                let inner = self.runner.clone();
                let fut = async move {
                    let method = LoadSvc(inner);
                    let codec = tonic::codec::ProstCodec::default();
                    let mut grpc = tonic::server::Grpc::new(codec);
                    let res = grpc.unary(method, req).await;
                    Ok(res)
                };
                Box::pin(fut)
            }
            _ => todo!(),
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5

Error output

   Compiling ice_mre_invalid_coerce_unsized v0.1.0 (/home/one/ice_mre_invalid_CoerceUnsized)
error: internal compiler error: compiler/rustc_monomorphize/src/lib.rs:46:13: invalid `CoerceUnsized` impl_source: Err(FulfillmentError)

thread 'rustc' panicked at compiler/rustc_monomorphize/src/lib.rs:46:13:
Box<dyn Any>
stack backtrace:
   0:     0x75582558682a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::ha4a311b32f6b4ad8
   1:     0x755825c277e2 - core::fmt::write::h1866771663f62b81
   2:     0x755826a81d51 - std::io::Write::write_fmt::hb549e7444823135e
   3:     0x755825586682 - std::sys::backtrace::BacktraceLock::print::hddd3a9918ce29aa7
   4:     0x755825588b5a - std::panicking::default_hook::{{closure}}::h791f75256b902d7d
   5:     0x7558255889c0 - std::panicking::default_hook::h82cc572fcb0d8cd7
   6:     0x755824614f55 - std[1b49f43dde054edc]::panicking::update_hook::<alloc[f0e0d4128a1437e6]::boxed::Box<rustc_driver_impl[c421ed190efad9be]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x755825589238 - std::panicking::rust_panic_with_hook::he21644cc2707f2c4
   8:     0x75582464fa01 - std[1b49f43dde054edc]::panicking::begin_panic::<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>::{closure#0}
   9:     0x7558246429c6 - std[1b49f43dde054edc]::sys::backtrace::__rust_end_short_backtrace::<std[1b49f43dde054edc]::panicking::begin_panic<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>::{closure#0}, !>
  10:     0x75582463df99 - std[1b49f43dde054edc]::panicking::begin_panic::<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>
  11:     0x755824659971 - <rustc_errors[fd0d1ab268a7514d]::diagnostic::BugAbort as rustc_errors[fd0d1ab268a7514d]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x755824cc8913 - rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt::<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}
  13:     0x755824cafe8a - rustc_middle[60437f3b60b3af56]::ty::context::tls::with_opt::<rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x755824cafd1b - rustc_middle[60437f3b60b3af56]::ty::context::tls::with_context_opt::<rustc_middle[60437f3b60b3af56]::ty::context::tls::with_opt<rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7558231e4110 - rustc_middle[60437f3b60b3af56]::util::bug::bug_fmt
  16:     0x755827655c2d - rustc_monomorphize[64293748b2428815]::collector::find_vtable_types_for_unsizing.cold
  17:     0x755823466669 - rustc_monomorphize[64293748b2428815]::collector::items_of_instance
  18:     0x7558262d92b2 - rustc_query_impl[d10191050d412fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10191050d412fc]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 32usize]>>
  19:     0x7558262d73b4 - rustc_query_system[c1574a252f7419c]::query::plumbing::try_execute_query::<rustc_query_impl[d10191050d412fc]::DynamicConfig<rustc_query_system[c1574a252f7419c]::query::caches::DefaultCache<(rustc_middle[60437f3b60b3af56]::ty::instance::Instance, rustc_middle[60437f3b60b3af56]::mir::mono::CollectionMode), rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[d10191050d412fc]::plumbing::QueryCtxt, true>
  20:     0x7558262d5d18 - rustc_query_impl[d10191050d412fc]::query_impl::items_of_instance::get_query_incr::__rust_end_short_backtrace
  21:     0x7558262d3572 - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec::{closure#0}
  22:     0x755826e33048 - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  23:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  24:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  25:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  26:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  27:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  28:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  29:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  30:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  31:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  32:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  33:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  34:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  35:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  36:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  37:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  38:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  39:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  40:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  41:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  42:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  43:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  44:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  45:     0x755826e3399e - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  46:     0x755826648de9 - rustc_monomorphize[64293748b2428815]::partitioning::collect_and_partition_mono_items
  47:     0x755826648416 - rustc_query_impl[d10191050d412fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 24usize]>>
  48:     0x7558266483e3 - <rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[9e3ec3a99e20741e]::ops::function::FnOnce<(rustc_middle[60437f3b60b3af56]::ty::context::TyCtxt, ())>>::call_once
  49:     0x755826b255c0 - rustc_query_system[c1574a252f7419c]::query::plumbing::try_execute_query::<rustc_query_impl[d10191050d412fc]::DynamicConfig<rustc_query_system[c1574a252f7419c]::query::caches::SingleCache<rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[d10191050d412fc]::plumbing::QueryCtxt, true>
  50:     0x755826b24f09 - rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  51:     0x755826b7c547 - <rustc_codegen_llvm[87a67cd1a6f247bf]::LlvmCodegenBackend as rustc_codegen_ssa[47ed54211a626f01]::traits::backend::CodegenBackend>::codegen_crate
  52:     0x755826b8e327 - <rustc_interface[aa3cb6198a62650b]::queries::Linker>::codegen_and_build_linker
  53:     0x755826a652c8 - rustc_interface[aa3cb6198a62650b]::interface::run_compiler::<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}
  54:     0x755826aa01e0 - std[1b49f43dde054edc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_with_globals<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_pool_with_globals<rustc_interface[aa3cb6198a62650b]::interface::run_compiler<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>
  55:     0x755826a9fefd - <<std[1b49f43dde054edc]::thread::Builder>::spawn_unchecked_<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_with_globals<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_pool_with_globals<rustc_interface[aa3cb6198a62650b]::interface::run_compiler<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#1} as core[9e3ec3a99e20741e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  56:     0x755826a9f6b9 - std::sys::pal::unix::thread::Thread::new::thread_start::h14f1eb868ff90fc9
  57:     0x755820c94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  58:     0x755820d26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  59:                0x0 - <unknown>

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.84.0 (9fc6b4312 2025-01-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [items_of_instance] collecting items used by `<impl at src/main.rs:80:1: 84:57>::call`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `ice_mre_invalid_coerce_unsized` (bin "ice_mre_invalid_coerce_unsized")

Caused by:
  process didn't exit successfully: `/home/one/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name ice_mre_invalid_coerce_unsized --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=bc9219222c47fdd2 -C extra-filename=-bc9219222c47fdd2 --out-dir /home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps -C incremental=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/incremental -L dependency=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps --extern async_trait=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libasync_trait-2e38ce1bf36df4a8.so --extern http=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libhttp-3a8f7e5e71542b5c.rlib --extern opendal=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libopendal-c01db150d8f9c96b.rlib --extern serde=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libserde-0a7940d4cb86f183.rlib --extern serde_json=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libserde_json-e7d76399483ec258.rlib --extern tokio=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtokio-8b2b5462a056c1d5.rlib --extern tonic=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtonic-ab3d5e4d75427b48.rlib --extern tower=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtower-0e519a02860ed7e5.rlib -L native=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/build/ring-c42c0ae835c8384f/out` (exit status: 101)
Backtrace

   Compiling ice_mre_invalid_coerce_unsized v0.1.0 (/home/one/ice_mre_invalid_CoerceUnsized)
error: internal compiler error: compiler/rustc_monomorphize/src/lib.rs:46:13: invalid `CoerceUnsized` impl_source: Err(FulfillmentError)

thread 'rustc' panicked at compiler/rustc_monomorphize/src/lib.rs:46:13:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_monomorphize::collector::find_vtable_types_for_unsizing.cold
   7: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
   8: rustc_monomorphize::collector::collect_items_rec::{closure#0}
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_monomorphize::collector::collect_items_rec
  14: rustc_monomorphize::collector::collect_items_rec
  15: rustc_monomorphize::collector::collect_items_rec
  16: rustc_monomorphize::collector::collect_items_rec
  17: rustc_monomorphize::collector::collect_items_rec
  18: rustc_monomorphize::collector::collect_items_rec
  19: rustc_monomorphize::collector::collect_items_rec
  20: rustc_monomorphize::collector::collect_items_rec
  21: rustc_monomorphize::collector::collect_items_rec
  22: rustc_monomorphize::collector::collect_items_rec
  23: rustc_monomorphize::collector::collect_items_rec
  24: rustc_monomorphize::collector::collect_items_rec
  25: rustc_monomorphize::collector::collect_items_rec
  26: rustc_monomorphize::collector::collect_items_rec
  27: rustc_monomorphize::collector::collect_items_rec
  28: rustc_monomorphize::collector::collect_items_rec
  29: rustc_monomorphize::collector::collect_items_rec
  30: rustc_monomorphize::collector::collect_items_rec
  31: rustc_monomorphize::collector::collect_items_rec
  32: rustc_monomorphize::collector::collect_items_rec
  33: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  34: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  35: <rustc_interface::queries::Linker>::codegen_and_build_linker
  36: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.84.0 (9fc6b4312 2025-01-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [items_of_instance] collecting items used by `<impl at src/main.rs:80:1: 84:57>::call`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `ice_mre_invalid_coerce_unsized` (bin "ice_mre_invalid_coerce_unsized")

Caused by:
  process didn't exit successfully: `/home/one/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name ice_mre_invalid_coerce_unsized --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=bc9219222c47fdd2 -C extra-filename=-bc9219222c47fdd2 --out-dir /home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps -C incremental=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/incremental -L dependency=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps --extern async_trait=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libasync_trait-2e38ce1bf36df4a8.so --extern http=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libhttp-3a8f7e5e71542b5c.rlib --extern opendal=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libopendal-c01db150d8f9c96b.rlib --extern serde=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libserde-0a7940d4cb86f183.rlib --extern serde_json=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libserde_json-e7d76399483ec258.rlib --extern tokio=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtokio-8b2b5462a056c1d5.rlib --extern tonic=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtonic-ab3d5e4d75427b48.rlib --extern tower=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/deps/libtower-0e519a02860ed7e5.rlib -L native=/home/one/ice_mre_invalid_CoerceUnsized/target/debug/build/ring-c42c0ae835c8384f/out` (exit status: 101)

@c-git c-git 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 Jan 14, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 14, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Jan 14, 2025

Working on minimizing this.

@jieyouxu jieyouxu added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example A-monomorphization Area: Monomorphization E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Jan 14, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Jan 15, 2025

Old partial reduction (150 lines)
use std::future::IntoFuture;
use std::sync::Arc;
use std::{future::Future, pin::Pin};

trait Access {
    type Lister;

    fn list(&self) -> impl Future<Output = Self::Lister> + Send {
        async { todo!() }
    }
}

trait AccessDyn: Send + Sync {}

impl Access for Arc<dyn AccessDyn> {
    type Lister = ();
}

struct OperatorFuture<F> {
    _f: fn() -> F,
}

impl<F: Future> OperatorFuture<F> {
    fn new(_: fn(Arc<dyn AccessDyn>) -> F) -> Self {
        todo!()
    }
}

impl<F> IntoFuture for OperatorFuture<F>
where
    F: Future<Output = ()>,
{
    type Output = ();
    type IntoFuture = F;

    fn into_future(self) -> Self::IntoFuture {
        todo!()
    }
}

pub async fn runner() {
    OperatorFuture::new(|v| async move {
        v.list().await;
    })
    .await;
}

struct BoxCloneService(
    #[allow(dead_code)] Box<dyn Service<Future = Pin<Box<dyn Future<Output = ()>>>>>,
);

fn main() {
    let body = async {
        let svc = RuntimeServer(runner);
        let inner = svc.map_future(|f| -> Pin<Box<dyn Future<Output = ()>>> { Box::pin(f) });
        BoxCloneService(Box::new(inner));
    };

    let mut p = Box::pin(body);
    let _ = p.as_mut().poll(make());
}

fn make<T>() -> T {
    todo!()
}

struct RuntimeServer<T: 'static>(T);

type BoxFuture<T> = std::pin::Pin<Box<dyn Future<Output = T> + Send>>;

trait Runner: Send + Sync + Clone {}

impl<F, O> Runner for F
where
    F: FnOnce() -> O + Send + Sync + Clone,
    O: Future + Send,
{
}

struct LoadSvc<T>(T);
impl<T: Runner> UnaryService for LoadSvc<T> {
    type Future = BoxFuture<()>;
}

impl<T> Service for RuntimeServer<T>
where
    T: Runner,
{
    type Future = BoxFuture<()>;

    fn call(&mut self) -> Self::Future {
        let inner = self.0.clone();
        let fut = async {
            unary(LoadSvc(inner)).await;
        };
        Box::pin(fut)
    }
}

trait Service {
    type Future: Future<Output = ()>;

    fn call(&mut self) -> Self::Future {
        todo!()
    }

    fn map_future<F>(self, _: F) -> MapFuture<Self, F>
    where
        Self: Sized,
    {
        todo!()
    }
}

trait UnaryService {
    type Future: Future;
    fn call(&mut self) -> Self::Future {
        todo!()
    }
}

impl<T> UnaryService for T
where
    T: Service,
{
    type Future = T::Future;
}

fn unary<S>(mut service: S) -> impl Future
where
    S: UnaryService,
{
    service.call()
}

struct MapFuture<S, F> {
    inner: S,
    f: F,
}

impl<S, F, Fut> Service for MapFuture<S, F>
where
    S: Service,
    F: FnMut(S::Future) -> Fut,
    Fut: Future<Output = ()>,
{
    type Future = Fut;

    fn call(&mut self) -> Self::Future {
        (self.f)(self.inner.call())
    }
}

smaller reduction (50 lines):

use std::future::Future;
use std::marker::PhantomData;

struct Arc<T: ?Sized = dyn Send>(PhantomData<T>);

trait Access {
    type Lister;

    fn list() -> impl Future<Output = Self::Lister> {
        async { todo!() }
    }
}

impl Access for Arc {
    type Lister = ();
}

fn main() {
    let svc = async {
        async { Arc::list() }.await;
    };
    &svc as &dyn Service;
}

struct LoadSvc<T>(T);
impl<T: Send> UnaryService for LoadSvc<T> {}

impl<T> Service for T
where
    T: Send,
{
    fn call(&self) {
        LoadSvc::<T>::call2();
    }
}

trait Service {
    fn call(&self);
}

trait UnaryService {
    fn call2() {}
}

trait Unimplemented {}
impl<T> UnaryService for T where T: Unimplemented {}

maybe a duplicate of #119095?

@c-git
Copy link
Author

c-git commented Jan 15, 2025

Nice you were able to remove all the dependencies. Thanks.

@cyrgani
Copy link
Contributor

cyrgani commented Jan 15, 2025

The best reduction I can make for this (and I don't think it can be shortened much more):

use std::future::Future;
trait Access {
    type Lister;

    fn list() -> impl Future<Output = Self::Lister> {
        async { todo!() }
    }
}

trait Foo {}
impl Access for dyn Foo {
    type Lister = ();
}

fn main() {
    let svc = async {
        async { <dyn Foo>::list() }.await;
    };
    &svc as &dyn Service;
}

trait UnaryService {
    fn call2() {}
}
trait Unimplemented {}
impl<T: Unimplemented> UnaryService for T {}
struct Wrap<T>(T);
impl<T: Send> UnaryService for Wrap<T> {}

trait Service {
    fn call(&self);
}
impl<T: Send> Service for T {
    fn call(&self) {
        Wrap::<T>::call2();
    }
}

@rustbot label -E-needs-mcve S-has-mcve

@rustbot rustbot added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jan 15, 2025
@ranger-ross
Copy link
Contributor

ranger-ross commented Jan 18, 2025

bisects to nightly-2024-03-22

get_commits_between returning commits, len: 11
  commit[0] 2024-03-20: Auto merge of #122761 - jwong101:fix/vec-insert, r=workingjubilee,Nilstrieb
  commit[1] 2024-03-21: Auto merge of #122772 - nikic:update-llvm-22, r=cuviper
  commit[2] 2024-03-21: Auto merge of #122803 - jhpratt:rollup-nmgs79k, r=jhpratt
  commit[3] 2024-03-21: Auto merge of #121587 - ShoyuVanilla:fix-issue-121267, r=TaKO8Ki
  commit[4] 2024-03-21: Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obk
  commit[5] 2024-03-21: Auto merge of #122568 - RalfJung:mentioned-items, r=oli-obk
  commit[6] 2024-03-21: Auto merge of #122718 - workingjubilee:eyeliner-for-contrast, r=lcnr
  commit[7] 2024-03-21: Auto merge of #122822 - matthiaskrgr:rollup-rjgmnbe, r=matthiaskrgr
  commit[8] 2024-03-21: Auto merge of #122596 - rcxdude:master, r=petrochenkov
  commit[9] 2024-03-21: Auto merge of #122830 - matthiaskrgr:rollup-uk2by3f, r=matthiaskrgr
  commit[10] 2024-03-21: Auto merge of #122785 - the8472:const-select-specialized-impl, r=Amanieu

Given the backtrace it seems quiet likely to be #122568 cc: @RalfJung

@rustbot label -E-needs-bisection +S-has-bisection

@rustbot rustbot added S-has-bisection Status: a bisection has been found for this issue and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Jan 18, 2025
@ranger-ross
Copy link
Contributor

ranger-ross commented Jan 18, 2025

I noticed the errors are different between the originally posted code and the reduced code in this comment

The error for the reduced code is

error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:581:21: failed to resolve instance for <Wrap<{async block@src/main.rs:18:15: 18:20}> as UnaryService>::call2
  --> src/main.rs:32:9
   |
32 |         Wrap::<T>::call2();
   |         ^^^^^^^^^^^^^^^^^^
Backtrace
thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:581:21:
Box<dyn Any>
stack backtrace:
   0:     0x7fbbb7d8682a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::ha4a311b32f6b4ad8
   1:     0x7fbbb84277e2 - core::fmt::write::h1866771663f62b81
   2:     0x7fbbb9281d51 - std::io::Write::write_fmt::hb549e7444823135e
   3:     0x7fbbb7d86682 - std::sys::backtrace::BacktraceLock::print::hddd3a9918ce29aa7
   4:     0x7fbbb7d88b5a - std::panicking::default_hook::{{closure}}::h791f75256b902d7d
   5:     0x7fbbb7d889c0 - std::panicking::default_hook::h82cc572fcb0d8cd7
   6:     0x7fbbb6e14f55 - std[1b49f43dde054edc]::panicking::update_hook::<alloc[f0e0d4128a1437e6]::boxed::Box<rustc_driver_impl[c421ed190efad9be]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7fbbb7d89238 - std::panicking::rust_panic_with_hook::he21644cc2707f2c4
   8:     0x7fbbb6e4fa01 - std[1b49f43dde054edc]::panicking::begin_panic::<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>::{closure#0}
   9:     0x7fbbb6e429c6 - std[1b49f43dde054edc]::sys::backtrace::__rust_end_short_backtrace::<std[1b49f43dde054edc]::panicking::begin_panic<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>::{closure#0}, !>
  10:     0x7fbbb6e3df99 - std[1b49f43dde054edc]::panicking::begin_panic::<rustc_errors[fd0d1ab268a7514d]::ExplicitBug>
  11:     0x7fbbb6e59971 - <rustc_errors[fd0d1ab268a7514d]::diagnostic::BugAbort as rustc_errors[fd0d1ab268a7514d]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7fbbb743433c - <rustc_errors[fd0d1ab268a7514d]::DiagCtxtHandle>::span_bug::<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span, alloc[f0e0d4128a1437e6]::string::String>
  13:     0x7fbbb74c8927 - rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt::<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}
  14:     0x7fbbb74afe8a - rustc_middle[60437f3b60b3af56]::ty::context::tls::with_opt::<rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7fbbb74afd1b - rustc_middle[60437f3b60b3af56]::ty::context::tls::with_context_opt::<rustc_middle[60437f3b60b3af56]::ty::context::tls::with_opt<rustc_middle[60437f3b60b3af56]::util::bug::opt_span_bug_fmt<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7fbbb74c8857 - rustc_middle[60437f3b60b3af56]::util::bug::span_bug_fmt::<rustc_span[200b27ea0e9a3b9b]::span_encoding::Span>
  17:     0x7fbbb8a53258 - <rustc_middle[60437f3b60b3af56]::ty::instance::Instance>::expect_resolve
  18:     0x7fbbb5c6fd4d - rustc_monomorphize[64293748b2428815]::collector::items_of_instance
  19:     0x7fbbb8ad92b2 - rustc_query_impl[d10191050d412fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10191050d412fc]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 32usize]>>
  20:     0x7fbbb8ad73b4 - rustc_query_system[c1574a252f7419c]::query::plumbing::try_execute_query::<rustc_query_impl[d10191050d412fc]::DynamicConfig<rustc_query_system[c1574a252f7419c]::query::caches::DefaultCache<(rustc_middle[60437f3b60b3af56]::ty::instance::Instance, rustc_middle[60437f3b60b3af56]::mir::mono::CollectionMode), rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[d10191050d412fc]::plumbing::QueryCtxt, true>
  21:     0x7fbbb8ad5d18 - rustc_query_impl[d10191050d412fc]::query_impl::items_of_instance::get_query_incr::__rust_end_short_backtrace
  22:     0x7fbbb8ad3572 - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec::{closure#0}
  23:     0x7fbbb9633048 - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  24:     0x7fbbb9633e17 - rustc_monomorphize[64293748b2428815]::collector::collect_items_rec
  25:     0x7fbbb8e48de9 - rustc_monomorphize[64293748b2428815]::partitioning::collect_and_partition_mono_items
  26:     0x7fbbb8e48416 - rustc_query_impl[d10191050d412fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 24usize]>>
  27:     0x7fbbb8e483e3 - <rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[9e3ec3a99e20741e]::ops::function::FnOnce<(rustc_middle[60437f3b60b3af56]::ty::context::TyCtxt, ())>>::call_once
  28:     0x7fbbb93255c0 - rustc_query_system[c1574a252f7419c]::query::plumbing::try_execute_query::<rustc_query_impl[d10191050d412fc]::DynamicConfig<rustc_query_system[c1574a252f7419c]::query::caches::SingleCache<rustc_middle[60437f3b60b3af56]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[d10191050d412fc]::plumbing::QueryCtxt, true>
  29:     0x7fbbb9324f09 - rustc_query_impl[d10191050d412fc]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  30:     0x7fbbb937c547 - <rustc_codegen_llvm[87a67cd1a6f247bf]::LlvmCodegenBackend as rustc_codegen_ssa[47ed54211a626f01]::traits::backend::CodegenBackend>::codegen_crate
  31:     0x7fbbb938e327 - <rustc_interface[aa3cb6198a62650b]::queries::Linker>::codegen_and_build_linker
  32:     0x7fbbb92652c8 - rustc_interface[aa3cb6198a62650b]::interface::run_compiler::<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}
  33:     0x7fbbb92a01e0 - std[1b49f43dde054edc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_with_globals<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_pool_with_globals<rustc_interface[aa3cb6198a62650b]::interface::run_compiler<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>
  34:     0x7fbbb929fefd - <<std[1b49f43dde054edc]::thread::Builder>::spawn_unchecked_<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_with_globals<rustc_interface[aa3cb6198a62650b]::util::run_in_thread_pool_with_globals<rustc_interface[aa3cb6198a62650b]::interface::run_compiler<core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>, rustc_driver_impl[c421ed190efad9be]::run_compiler::{closure#0}>::{closure#1}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9e3ec3a99e20741e]::result::Result<(), rustc_span[200b27ea0e9a3b9b]::ErrorGuaranteed>>::{closure#1} as core[9e3ec3a99e20741e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7fbbb929f6b9 - std::sys::pal::unix::thread::Thread::new::thread_start::h14f1eb868ff90fc9
  36:     0x7fbbb367d148 - start_thread
  37:     0x7fbbb37010cc - __GI___clone3
  38:                0x0 - <unknown>

@RalfJung
Copy link
Member

That PR just monomorphizes more things. So possibly the ICE already existed before but was just not exposed?

Cc @compiler-errors @lcnr somehow we are seeing a panic in Instance::expect_resolve during mono item collection.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 24, 2025
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-monomorphization Area: Monomorphization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants