// crate a
#![feature(type_alias_impl_trait)]
use std::future::Future;
pub trait Service<Request> {
type Future: Future<Output = ()>;
fn call(&mut self, req: Request) -> Self::Future;
}
// NOTE: the pub(crate) here is critical
pub(crate) fn new() -> () {}
pub struct A;
impl Service<()> for A {
type Future = impl Future<Output = ()>;
fn call(&mut self, _: ()) -> Self::Future {
async { new() }
}
}
// crate b
use a::Service;
use std::future::Future;
use std::pin::Pin;
use std::task::Context;
fn broken(mut a: a::A, cx: &mut Context<'_>) {
let mut fut = a.call(());
let _ = unsafe { Pin::new_unchecked(&mut fut) }.poll(cx);
}
pub async fn main(cx: &mut Context<'_>) {
broken(a::A, cx);
}
$ rustc --version --verbose
rustc 1.43.0-nightly (96bb8b31c 2020-03-05)
binary: rustc
commit-hash: 96bb8b31c81dc2394317f2f083c3acf8087efea1
commit-date: 2020-03-05
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
error: internal compiler error: src/librustc_mir/monomorphize/collector.rs:745: cannot create local mono-item for DefId(15:8 ~ a[ffa2]::new[0])
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:875:9
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1053
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1428
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:204
9: std::panicking::default_hook
at src/libstd/panicking.rs:224
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:474
12: std::panicking::begin_panic
13: rustc_errors::HandlerInner::bug
14: rustc_errors::Handler::bug
15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
16: rustc::ty::context::tls::with_opt::{{closure}}
17: rustc::ty::context::tls::with_opt
18: rustc::util::bug::opt_span_bug_fmt
19: rustc::util::bug::bug_fmt
20: rustc_mir::monomorphize::collector::should_monomorphize_locally
21: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_terminator_kind
22: rustc_mir::monomorphize::collector::collect_items_rec
23: rustc_mir::monomorphize::collector::collect_items_rec
24: rustc_mir::monomorphize::collector::collect_items_rec
25: rustc_session::utils::<impl rustc_session::session::Session>::time
26: rustc_mir::monomorphize::collector::collect_crate_mono_items
27: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
28: rustc::dep_graph::graph::DepGraph::with_task_impl
29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
30: rustc::ty::query::plumbing::force_from_dep_node
31: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
32: rustc::dep_graph::graph::DepGraph::try_mark_green
33: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
35: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
36: rustc::dep_graph::graph::DepGraph::with_ignore
37: rustc_metadata::rmeta::encoder::encode_metadata
38: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::encode_metadata
39: rustc::ty::context::TyCtxt::encode_metadata
40: rustc_interface::passes::start_codegen
41: rustc::ty::context::tls::enter_global
42: rustc_interface::queries::Queries::ongoing_codegen
43: rustc_interface::interface::run_compiler_in_existing_thread_pool
44: rustc_ast::attr::with_globals
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.43.0-nightly (96bb8b31c 2020-03-05) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental -C target-cpu=native --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: aborting due to previous error
error: could not compile `b`.
This is probably a smaller reproduction of #57430.
If anyone has a quick and dirty idea for how to force an impl Trait type to resolve, I think I could finish minifying the above pretty easily.
@jonas-schievink Updated reproducing code to remove need for futures_executor.
I'm _fairly_ certain this is related to the visibility of types that appear in an impl Trait type. Specifically, in the code above, if pub(crate) fn new() in a is changed to pub, it compiles fine.
@rustbot ping icebreakers-cleanup-crew
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
[instructions] for tackling these sorts of bugs. Maybe take a look?
Thanks! <3
cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @KarlK90 @LeSeulArtichaut @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke
triage: P-high until we assess severity (the bug written depends on a feature flag) we want to know if that's really needed for the issue to reproduce.
fwiw, my _guess_ is that the feature flag is not necessary, and that the relevant type = impl Trait can be replaced by an async fn.
So, for cleanup crew ICE-breakers who might take a look at this:
(a) we should try to get a backtrace with line numbers
(b) we should see if this is a regression and track down the cause (maybe jump back a few months and see if the corresponding nightly from that time works?)
(c) it'd be interesting to see if we can remove the type = impl Trait from the impl and thus reproduce on something that builds on stable. As @jonhoo noted, an inherent async fn on A could trigger it, or perhaps something like:
// crate a
use std::future::Future;
// NOTE: the pub(crate) here is critical
pub(crate) fn new() -> () {}
pub struct A;
impl A {
fn call(&mut self, _: ()) -> impl Future<Output = ()> {
async { new() }
}
}
Downgrading priority for now until we can reproduce without the gate.
@nikomatsakis Interestingly enough, an inherent method like that does not reproduce the issue, so it appears the existential type in associated type position is also needed.