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

drop-tracking: ICE when using default struct update syntax #98476

Closed
Tracked by #97331
jyn514 opened this issue Jun 25, 2022 · 8 comments · Fixed by #98754
Closed
Tracked by #97331

drop-tracking: ICE when using default struct update syntax #98476

jyn514 opened this issue Jun 25, 2022 · 8 comments · Fixed by #98754
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Jun 25, 2022

cc #97331, @eholk. Minimized from https://crater-reports.s3.amazonaws.com/pr-97334/try%23615edd3ad1cf6871c977dc900317cb6c2070fd6b/gh/AsuMagic.markov-irc/log.txt in the crater run for #97334.

Code

fn main() {
    let _ = foo();
}

async fn from_config(_: Config) {}

async fn foo() {
    from_config(Config {
        nickname: None,
        ..Default::default()
    })
    .await;
}

#[derive(Default)]
struct Config {
    nickname: Option<Box<u8>>,
}

Meta

rustc --version: 615edd3ad1cf6871c977dc900317cb6c2070fd6b

Error output

error: internal compiler error: compiler/rustc_mir_transform/src/generator.rs:753:13: Broken MIR: generator contains type Config in MIR, but typeck only knows about {ResumeTy, impl Future<Output = ()>, ()} and []
  --> src/main.rs:7:16
   |
7  |   async fn foo() {
   |  ________________^
8  | |     from_config(Config {
9  | |         nickname: None,
10 | |         ..Default::default()
11 | |     })
12 | |     .await;
13 | | }
   | |_^
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/compiler/rustc_errors/src/lib.rs:1274:9
stack backtrace:
   0:     0x7fd66bab8f4d - std::backtrace_rs::backtrace::libunwind::trace::h48663e6e02482f77
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fd66bab8f4d - std::backtrace_rs::backtrace::trace_unsynchronized::hd59d5365552a1436
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fd66bab8f4d - std::sys_common::backtrace::_print_fmt::ha78e5f373355cd4a
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fd66bab8f4d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1b6548c67a95d5a1
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fd66bb14aac - core::fmt::write::hca7ee89651358f58
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/core/src/fmt/mod.rs:1196:17
   5:     0x7fd66baaa6e1 - std::io::Write::write_fmt::h4bbc99e2a7952e78
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/io/mod.rs:1654:15
   6:     0x7fd66babbc35 - std::sys_common::backtrace::_print::h26a0e5520b381b04
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fd66babbc35 - std::sys_common::backtrace::print::h743a45291d5f39cc
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fd66babbc35 - std::panicking::default_hook::{{closure}}::hf1e2b39dfd75cbc2
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/panicking.rs:295:22
   9:     0x7fd66babb956 - std::panicking::default_hook::h347898a158e52020
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/panicking.rs:314:9
  10:     0x7fd66c282d11 - rustc_driver[2c8e23c1704d1846]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fd66babc30a - std::panicking::rust_panic_with_hook::h3cc7233c1fa5669e
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/panicking.rs:702:17
  12:     0x7fd66c44acf1 - std[23f59d9749713536]::panicking::begin_panic::<rustc_errors[4317dacdbe7ee454]::ExplicitBug>::{closure#0}
  13:     0x7fd66c447296 - std[23f59d9749713536]::sys_common::backtrace::__rust_end_short_backtrace::<std[23f59d9749713536]::panicking::begin_panic<rustc_errors[4317dacdbe7ee454]::ExplicitBug>::{closure#0}, !>
  14:     0x7fd66c45d946 - std[23f59d9749713536]::panicking::begin_panic::<rustc_errors[4317dacdbe7ee454]::ExplicitBug>
  15:     0x7fd66c446546 - std[23f59d9749713536]::panic::panic_any::<rustc_errors[4317dacdbe7ee454]::ExplicitBug>
  16:     0x7fd66c4445a1 - <rustc_errors[4317dacdbe7ee454]::HandlerInner>::span_bug::<rustc_span[e0494e7a78d29b23]::span_encoding::Span, &alloc[444af299f81eecf5]::string::String>
  17:     0x7fd66c4439b0 - <rustc_errors[4317dacdbe7ee454]::Handler>::span_bug::<rustc_span[e0494e7a78d29b23]::span_encoding::Span, &alloc[444af299f81eecf5]::string::String>
  18:     0x7fd66c493fb8 - rustc_middle[8b88f8a0f89f93bb]::ty::context::tls::with_opt::<rustc_middle[8b88f8a0f89f93bb]::util::bug::opt_span_bug_fmt<rustc_span[e0494e7a78d29b23]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7fd66c493b86 - rustc_middle[8b88f8a0f89f93bb]::util::bug::opt_span_bug_fmt::<rustc_span[e0494e7a78d29b23]::span_encoding::Span>
  20:     0x7fd66c493b44 - rustc_middle[8b88f8a0f89f93bb]::util::bug::span_bug_fmt::<rustc_span[e0494e7a78d29b23]::span_encoding::Span>
  21:     0x7fd66d6982aa - <rustc_mir_transform[63cdf027e05c8c75]::generator::StateTransform as rustc_middle[8b88f8a0f89f93bb]::mir::MirPass>::run_pass
  22:     0x7fd66d6894d0 - rustc_mir_transform[63cdf027e05c8c75]::pass_manager::run_passes
  23:     0x7fd66d6ddeed - rustc_mir_transform[63cdf027e05c8c75]::optimized_mir
  24:     0x7fd66e7e44a7 - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt, rustc_span[e0494e7a78d29b23]::def_id::DefId, &rustc_middle[8b88f8a0f89f93bb]::mir::Body>
  25:     0x7fd66dd93b9d - rustc_query_system[8f6ed9285397c37a]::query::plumbing::try_execute_query::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt, rustc_query_system[8f6ed9285397c37a]::query::caches::DefaultCache<rustc_span[e0494e7a78d29b23]::def_id::DefId, &rustc_middle[8b88f8a0f89f93bb]::mir::Body>>
  26:     0x7fd66cc3c837 - rustc_query_system[8f6ed9285397c37a]::query::plumbing::force_query::<rustc_query_impl[362fa764a08dc22]::queries::optimized_mir, rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  27:     0x7fd66ccec7b4 - rustc_query_impl[362fa764a08dc22]::query_callbacks::optimized_mir::force_from_dep_node
  28:     0x7fd66e1c4dc1 - <rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt as rustc_query_system[8f6ed9285397c37a]::dep_graph::DepContext>::try_force_from_dep_node
  29:     0x7fd66dd0725e - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  30:     0x7fd66dd0722c - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  31:     0x7fd66dd0722c - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  32:     0x7fd66ddd1318 - rustc_query_system[8f6ed9285397c37a]::query::plumbing::get_query::<rustc_query_impl[362fa764a08dc22]::queries::layout_of, rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  33:     0x7fd66dd60fd0 - <rustc_query_impl[362fa764a08dc22]::Queries as rustc_middle[8b88f8a0f89f93bb]::ty::query::QueryEngine>::layout_of
  34:     0x7fd66d6cac58 - <rustc_mir_transform[63cdf027e05c8c75]::const_prop_lint::ConstProp as rustc_mir_transform[63cdf027e05c8c75]::pass_manager::MirLint>::run_lint
  35:     0x7fd66d6894d0 - rustc_mir_transform[63cdf027e05c8c75]::pass_manager::run_passes
  36:     0x7fd66d6dcaf8 - rustc_mir_transform[63cdf027e05c8c75]::mir_drops_elaborated_and_const_checked
  37:     0x7fd66e7cc85c - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt, rustc_middle[8b88f8a0f89f93bb]::ty::WithOptConstParam<rustc_span[e0494e7a78d29b23]::def_id::LocalDefId>, &rustc_data_structures[10bde15a730ca175]::steal::Steal<rustc_middle[8b88f8a0f89f93bb]::mir::Body>>
  38:     0x7fd66dd70688 - rustc_query_system[8f6ed9285397c37a]::query::plumbing::try_execute_query::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt, rustc_query_system[8f6ed9285397c37a]::query::caches::DefaultCache<rustc_middle[8b88f8a0f89f93bb]::ty::WithOptConstParam<rustc_span[e0494e7a78d29b23]::def_id::LocalDefId>, &rustc_data_structures[10bde15a730ca175]::steal::Steal<rustc_middle[8b88f8a0f89f93bb]::mir::Body>>>
  39:     0x7fd66dd5e8b8 - <rustc_query_impl[362fa764a08dc22]::Queries as rustc_middle[8b88f8a0f89f93bb]::ty::query::QueryEngine>::mir_drops_elaborated_and_const_checked
  40:     0x7fd66d6ddd5c - rustc_mir_transform[63cdf027e05c8c75]::optimized_mir
  41:     0x7fd66e7e44a7 - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt, rustc_span[e0494e7a78d29b23]::def_id::DefId, &rustc_middle[8b88f8a0f89f93bb]::mir::Body>
  42:     0x7fd66dd93b9d - rustc_query_system[8f6ed9285397c37a]::query::plumbing::try_execute_query::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt, rustc_query_system[8f6ed9285397c37a]::query::caches::DefaultCache<rustc_span[e0494e7a78d29b23]::def_id::DefId, &rustc_middle[8b88f8a0f89f93bb]::mir::Body>>
  43:     0x7fd66dd5eb5e - <rustc_query_impl[362fa764a08dc22]::Queries as rustc_middle[8b88f8a0f89f93bb]::ty::query::QueryEngine>::optimized_mir
  44:     0x7fd66e1f0d85 - <rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt>::instance_mir
  45:     0x7fd66d659e05 - rustc_monomorphize[7d37f3bf7209d2f1]::collector::collect_neighbours
  46:     0x7fd66d656762 - rustc_monomorphize[7d37f3bf7209d2f1]::collector::collect_items_rec
  47:     0x7fd66e4a9fbb - <rustc_session[cbae6b27f1b96b52]::session::Session>::time::<(), rustc_monomorphize[7d37f3bf7209d2f1]::collector::collect_crate_mono_items::{closure#1}>
  48:     0x7fd66e49efeb - rustc_monomorphize[7d37f3bf7209d2f1]::collector::collect_crate_mono_items
  49:     0x7fd66e4a5c36 - rustc_monomorphize[7d37f3bf7209d2f1]::partitioning::collect_and_partition_mono_items
  50:     0x7fd66cb525d8 - <rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind as rustc_query_system[8f6ed9285397c37a]::dep_graph::DepKind>::with_deps::<<rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::with_task_impl<rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt, (), (&std[23f59d9749713536]::collections::hash::set::HashSet<rustc_span[e0494e7a78d29b23]::def_id::DefId, core[d4370e29f295d5d]::hash::BuildHasherDefault<rustc_hash[e6f0752b427bcd09]::FxHasher>>, &[rustc_middle[8b88f8a0f89f93bb]::mir::mono::CodegenUnit])>::{closure#0}, (&std[23f59d9749713536]::collections::hash::set::HashSet<rustc_span[e0494e7a78d29b23]::def_id::DefId, core[d4370e29f295d5d]::hash::BuildHasherDefault<rustc_hash[e6f0752b427bcd09]::FxHasher>>, &[rustc_middle[8b88f8a0f89f93bb]::mir::mono::CodegenUnit])>
  51:     0x7fd66cbcfa81 - <rustc_query_system[8f6ed9285397c37a]::dep_graph::graph::DepGraph<rustc_middle[8b88f8a0f89f93bb]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8b88f8a0f89f93bb]::ty::context::TyCtxt, (), (&std[23f59d9749713536]::collections::hash::set::HashSet<rustc_span[e0494e7a78d29b23]::def_id::DefId, core[d4370e29f295d5d]::hash::BuildHasherDefault<rustc_hash[e6f0752b427bcd09]::FxHasher>>, &[rustc_middle[8b88f8a0f89f93bb]::mir::mono::CodegenUnit])>
  52:     0x7fd66e8b6a47 - rustc_query_system[8f6ed9285397c37a]::query::plumbing::try_execute_query::<rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt, rustc_query_system[8f6ed9285397c37a]::query::caches::DefaultCache<(), (&std[23f59d9749713536]::collections::hash::set::HashSet<rustc_span[e0494e7a78d29b23]::def_id::DefId, core[d4370e29f295d5d]::hash::BuildHasherDefault<rustc_hash[e6f0752b427bcd09]::FxHasher>>, &[rustc_middle[8b88f8a0f89f93bb]::mir::mono::CodegenUnit])>>
  53:     0x7fd66e8ef4b0 - rustc_query_system[8f6ed9285397c37a]::query::plumbing::get_query::<rustc_query_impl[362fa764a08dc22]::queries::collect_and_partition_mono_items, rustc_query_impl[362fa764a08dc22]::plumbing::QueryCtxt>
  54:     0x7fd66e84f042 - <rustc_query_impl[362fa764a08dc22]::Queries as rustc_middle[8b88f8a0f89f93bb]::ty::query::QueryEngine>::collect_and_partition_mono_items
  55:     0x7fd66e37a1f5 - <rustc_codegen_llvm[614e335b7ddb2b7c]::LlvmCodegenBackend as rustc_codegen_ssa[87ec517d1ac920df]::traits::backend::CodegenBackend>::codegen_crate
  56:     0x7fd66e340f77 - <rustc_session[cbae6b27f1b96b52]::session::Session>::time::<alloc[444af299f81eecf5]::boxed::Box<dyn core[d4370e29f295d5d]::any::Any>, rustc_interface[b04e2cdf424baf9e]::passes::start_codegen::{closure#0}>
  57:     0x7fd66e33d38c - <rustc_interface[b04e2cdf424baf9e]::passes::QueryContext>::enter::<<rustc_interface[b04e2cdf424baf9e]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[d4370e29f295d5d]::result::Result<alloc[444af299f81eecf5]::boxed::Box<dyn core[d4370e29f295d5d]::any::Any>, rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>
  58:     0x7fd66e36146f - <rustc_interface[b04e2cdf424baf9e]::queries::Queries>::ongoing_codegen
  59:     0x7fd66e309deb - <rustc_interface[b04e2cdf424baf9e]::interface::Compiler>::enter::<rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}::{closure#2}, core[d4370e29f295d5d]::result::Result<core[d4370e29f295d5d]::option::Option<rustc_interface[b04e2cdf424baf9e]::queries::Linker>, rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>
  60:     0x7fd66e3325af - rustc_span[e0494e7a78d29b23]::with_source_map::<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_interface[b04e2cdf424baf9e]::interface::create_compiler_and_run<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}>::{closure#1}>
  61:     0x7fd66e31dd94 - rustc_interface[b04e2cdf424baf9e]::interface::create_compiler_and_run::<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}>
  62:     0x7fd66e3082b2 - <scoped_tls[941ee80d8231eb23]::ScopedKey<rustc_span[e0494e7a78d29b23]::SessionGlobals>>::set::<rustc_interface[b04e2cdf424baf9e]::interface::run_compiler<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}>::{closure#0}, core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>
  63:     0x7fd66e31f37f - std[23f59d9749713536]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b04e2cdf424baf9e]::util::run_in_thread_pool_with_globals<rustc_interface[b04e2cdf424baf9e]::interface::run_compiler<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}>::{closure#0}, core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>::{closure#0}, core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>
  64:     0x7fd66e31f4b9 - <<std[23f59d9749713536]::thread::Builder>::spawn_unchecked_<rustc_interface[b04e2cdf424baf9e]::util::run_in_thread_pool_with_globals<rustc_interface[b04e2cdf424baf9e]::interface::run_compiler<core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>, rustc_driver[2c8e23c1704d1846]::run_compiler::{closure#1}>::{closure#0}, core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>::{closure#0}, core[d4370e29f295d5d]::result::Result<(), rustc_errors[4317dacdbe7ee454]::ErrorGuaranteed>>::{closure#1} as core[d4370e29f295d5d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  65:     0x7fd66bac6223 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hae8ffeec5cb662e2
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/alloc/src/boxed.rs:1872:9
  66:     0x7fd66bac6223 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1b179c7aca9d8b98
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/alloc/src/boxed.rs:1872:9
  67:     0x7fd66bac6223 - std::sys::unix::thread::Thread::new::thread_start::h3faf721b71afff7d
                               at /rustc/615edd3ad1cf6871c977dc900317cb6c2070fd6b/library/std/src/sys/unix/thread.rs:108:17
  68:     0x7fd66b9e1609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  69:     0x7fd66b8fa133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  70:                0x0 - <unknown>

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.63.0-nightly (615edd3ad 2022-05-23) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `foo::{closure#0}`
#1 [layout_of] computing layout of `impl core::future::future::Future<Output = ()>`
#2 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#3 [optimized_mir] optimizing MIR for `main`
#4 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@jyn514 jyn514 added 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. C-bug Category: This is a bug. A-async-await Area: Async & Await labels Jun 25, 2022
@jyn514
Copy link
Member Author

jyn514 commented Jun 25, 2022

nickname: Option<Box<u8>>,

Strangely, this has to be a type with an allocator - using Option<usize> doesn't ICE.

@jyn514
Copy link
Member Author

jyn514 commented Jun 25, 2022

UI test (also slightly reduced - turns out the relevant part here is having a custom Drop):

// build-pass
// edition:2018
// compile-flags: -Zdrop-tracking=y

fn main() {
    let _ = foo();
}

async fn from_config(x: Config) {
    async {}.await;
    drop(x);
}

async fn foo() {
    from_config(Config {
        nickname: NonCopy,
        ..Default::default()
    })
    .await;
}

#[derive(Default)]
struct NonCopy;
impl Drop for NonCopy {
    fn drop(&mut self) {}
}

#[derive(Default)]
struct Config {
    nickname: NonCopy,
}

@compiler-errors
Copy link
Member

This has to do with the fact that the temporary which serves as the base expr of the struct, namely ..Default::default(), is not treated as if it lives across the await, even though it does.

This ICEs similarly if we have something like fn_call(Config { nickname, other_field }.other_field).await. Even though we move other_field into the fn_call, MIR still thinks we have a live Config that needs dropped (which is true), even though drop tracking doesn't think that anything lives across the await point.

matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 25, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 25, 2022
@jyn514
Copy link
Member Author

jyn514 commented Jun 25, 2022

@compiler-errors I'm not sure I follow - why do we have a live Config across the yield point?

@compiler-errors
Copy link
Member

Well, we have a partially live Config. See here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ccaba36493c792a7e35c4d7dd898cf84

We need to keep the Config from which the a field was moved out because it still has a b field which needs to be dropped, but since it's a temp, it needs to be dropped at the end of the statement, i.e. a cross the await point.

@jyn514
Copy link
Member Author

jyn514 commented Jun 26, 2022

Thanks! That makes sense to me.

Here's a reproduction with just generators (no futures) and using multiple fields instead of ..Default::default():

// build-pass
// edition:2018
// compile-flags: -Zdrop-tracking=y

#![feature(generators)]

fn main() {
    let _ = foo();
}

fn foo() {
    || {
        yield drop(Config {
            nickname: NonCopy,
            b: NonCopy2,
        }.nickname);
    };
}

#[derive(Default)]
struct NonCopy;
impl Drop for NonCopy {
    fn drop(&mut self) {}
}

#[derive(Default)]
struct NonCopy2;
impl Drop for NonCopy2 {
    fn drop(&mut self) {}
}

#[derive(Default)]
struct Config {
    nickname: NonCopy,
    b: NonCopy2,
}

@eholk
Copy link
Contributor

eholk commented Jul 4, 2022

@rustbot label +AsyncAwait-Triaged

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jul 4, 2022
jyn514 added a commit to jyn514/rust that referenced this issue Jul 10, 2022
…impl is used across an await

Previously, drop-tracking would incorrectly assume the struct would be dropped immediately, which
was not true: when the field had a type with a manual `Drop` impl, the drop becomes observable and
has to be dropped after the await instead.

For reasons I don't understand, this also fixes another error crater popped up related to type parameters.

 rust-lang#98476
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 12, 2022
…-errors

Fix drop-tracking ICE when a struct containing a field with a significant drop is used across an await

Previously, drop-tracking would incorrectly assume the struct would be dropped immediately, which was not true.

Fixes rust-lang#98476. Also fixes rust-lang#98477, I think because the parent HIR node for type variables is the whole function instead of the expression where the variable is used.

r? `@eholk`
@bors bors closed this as completed in 8a392a5 Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. 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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants