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 when combining unsized locals and async #61335

syosi opened this issue May 30, 2019 · 6 comments

ICE when combining unsized locals and async #61335

syosi opened this issue May 30, 2019 · 6 comments


Copy link

@syosi syosi commented May 30, 2019

It seemed clear to me that having an unsized local across a yield point cannot work.
Indeed, you get an ICE with (playground):


use std::future::poll_with_tls_context;
use std::pin::Pin;
use std::fmt::Display;

async fn foo2() {}

async fn foo(x: Box<dyn Display>) {
    let x = *x;
    println!("hello {}", &x);

fn main() {
    let mut a = foo(Box::new(5));
    let b = unsafe {
        Pin::new_unchecked(&mut a)
    match poll_with_tls_context(b) {
        _ => ()
Copy link

@Centril Centril commented May 30, 2019


   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc/ty/ univariant: field #3 of `[static generator@src/ 15:2 x:std::boxed::Box<dyn std::fmt::Display> for<'r, 's> {std::boxed::Box<(dyn std::fmt::Display + 'r)>, (dyn std::fmt::Display + 's), std::future::GenFuture<[static generator@src/ 9:19 {}]>, ()}]` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/
   5: std::panicking::default_hook
             at src/libstd/
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/
   8: std::panicking::begin_panic
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached::{{closure}}
  17: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
  18: <&mut I as core::iter::traits::iterator::Iterator>::next
  19: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  20: rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt>::layout_raw_uncached
  21: rustc::ty::layout::layout_raw
  22: rustc::ty::query::__query_compute::layout_raw
  23: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::layout_raw>::compute
  24: rustc::dep_graph::graph::DepGraph::with_task_impl
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  26: <rustc::ty::layout::LayoutCx<rustc::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  27: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
  28: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  29: rustc_mir::transform::run_passes::{{closure}}
  30: rustc_mir::transform::run_passes
  31: rustc_mir::transform::optimized_mir
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::monomorphize::collector::collect_items_rec
  36: rustc_mir::monomorphize::collector::collect_items_rec
  37: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  38: rustc::util::common::time
  39: rustc_mir::monomorphize::collector::collect_crate_mono_items
  40: rustc::util::common::time
  41: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  42: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc_codegen_ssa::base::codegen_crate
  47: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  48: rustc::util::common::time
  49: rustc_interface::passes::start_codegen
  50: rustc::ty::context::tls::enter_global
  51: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  52: rustc_interface::passes::create_global_ctxt::{{closure}}
  53: rustc_interface::passes::BoxedGlobalCtxt::enter
  54: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  55: rustc_interface::interface::run_compiler_in_existing_thread_pool
  56: std::thread::local::LocalKey<T>::with
  57: scoped_tls::ScopedKey<T>::set
  58: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [layout_raw] computing layout of `[static generator@src/ 15:2 x:std::boxed::Box<dyn std::fmt::Display> for<'r, 's> {std::boxed::Box<(dyn std::fmt::Display + 'r)>, (dyn std::fmt::Display + 's), std::future::GenFuture<[static generator@src/ 9:19 {}]>, ()}]`
#1 [optimized_mir] processing `foo`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
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:

note: rustc 1.37.0-nightly (37d001e4d 2019-05-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

Copy link

@Centril Centril commented May 30, 2019



async fn f() {}

async fn g(x: Box<dyn core::fmt::Display>) {
    let _x = *x;

fn main() {
    let _a = g(Box::new(5));

cc @tmandry @Zoxc @cramertj

Copy link

@Centril Centril commented May 30, 2019

Notably, swapping the order of the let _x = *x; to be after the f().await; does not cause an ICE or error.

Copy link

@cramertj cramertj commented May 30, 2019

@Centril sure, that's what I would expect. unsized locals can't be allowed across an await point. Still, it should be an error rather than an ICE ;)

Copy link

@nikomatsakis nikomatsakis commented Jun 4, 2019

Marking as "deferred" -- as unsized locals are not a stable feature, shouldn't be a blocker.

Copy link

@pnkfelix pnkfelix commented Jun 6, 2019

triage: P-medium, via same logic employed above to mark as deferred. Removing nomination label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants