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

TAIT: "open drop from non-ADT" #113594

Closed
kpreid opened this issue Jul 11, 2023 · 3 comments · Fixed by #115759
Closed

TAIT: "open drop from non-ADT" #113594

kpreid opened this issue Jul 11, 2023 · 3 comments · Fixed by #115759
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-monomorphization Issue: An error at monomorphization time. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Jul 11, 2023

Note: this only reproduces with cargo build (or rust-analyzer builds), not cargo check.

Code

#![feature(type_alias_impl_trait)]

pub struct Foo {
    /// This type must have nontrivial drop glue
    field: String,
}

pub type Tait = impl Sized;

pub fn ice_cold(beverage: Tait) {
    // Must destructure at least one field of `Foo`
    let Foo { field } = beverage;
    _ = field;
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (8ca44ef9c 2023-07-10)
binary: rustc
commit-hash: 8ca44ef9caa4049d584fbbce218c219cdca33a2f
commit-date: 2023-07-10
host: x86_64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

error: internal compiler error: /rustc/8ca44ef9caa4049d584fbbce218c219cdca33a2f/compiler/rustc_mir_dataflow/src/elaborate_drops.rs:882:18: open drop from non-ADT `Tait`
  --> all-is-cubes/src/lib.rs:13:1
   |
13 | }
   | ^
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/8ca44ef9caa4049d584fbbce218c219cdca33a2f/compiler/rustc_errors/src/lib.rs:995:33
stack backtrace:
   0:        0x1051c8823 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h46846cd25c27bb61
   1:        0x1052283eb - core::fmt::write::h8648cc21db836a22
   2:        0x1051bcfee - std::io::Write::write_fmt::h160d847e0b1e27d8
   3:        0x1051c861a - std::sys_common::backtrace::print::hd8610d3c2137a0c7
   4:        0x1051cb925 - std::panicking::default_hook::{{closure}}::hcdf8e8a2236a8a17
   5:        0x1051cb6cf - std::panicking::default_hook::h16b4d863c7e88d79
   6:        0x1113be2de - rustc_driver_impl[b1ad63243822c31d]::install_ice_hook::{closure#0}
   7:        0x1051cc0be - std::panicking::rust_panic_with_hook::hfa873bf608bcb536
   8:        0x11232a6a7 - std[8a8250c921f3e24c]::panicking::begin_panic::<rustc_errors[5cb010bceef86e73]::ExplicitBug>::{closure#0}
   9:        0x11231ff19 - std[8a8250c921f3e24c]::sys_common::backtrace::__rust_end_short_backtrace::<std[8a8250c921f3e24c]::panicking::begin_panic<rustc_errors[5cb010bceef86e73]::ExplicitBug>::{closure#0}, !>
  10:        0x11585b8e9 - std[8a8250c921f3e24c]::panicking::begin_panic::<rustc_errors[5cb010bceef86e73]::ExplicitBug>
  11:        0x1123aa316 - <rustc_errors[5cb010bceef86e73]::HandlerInner>::span_bug::<rustc_span[8808993aab5b8002]::span_encoding::Span, alloc[b9ce9f367082534]::string::String>
  12:        0x1123aa01b - <rustc_errors[5cb010bceef86e73]::Handler>::span_bug::<rustc_span[8808993aab5b8002]::span_encoding::Span, alloc[b9ce9f367082534]::string::String>
  13:        0x11229aad9 - rustc_middle[fe685cc1f47f288d]::util::bug::opt_span_bug_fmt::<rustc_span[8808993aab5b8002]::span_encoding::Span>::{closure#0}
  14:        0x11229ab17 - rustc_middle[fe685cc1f47f288d]::ty::context::tls::with_opt::<rustc_middle[fe685cc1f47f288d]::util::bug::opt_span_bug_fmt<rustc_span[8808993aab5b8002]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x112294f0f - rustc_middle[fe685cc1f47f288d]::ty::context::tls::with_context_opt::<rustc_middle[fe685cc1f47f288d]::ty::context::tls::with_opt<rustc_middle[fe685cc1f47f288d]::util::bug::opt_span_bug_fmt<rustc_span[8808993aab5b8002]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x11585b99f - rustc_middle[fe685cc1f47f288d]::util::bug::span_bug_fmt::<rustc_span[8808993aab5b8002]::span_encoding::Span>
  17:        0x1123468e8 - <rustc_mir_dataflow[81a8b0cec5d58857]::elaborate_drops::DropCtxt<rustc_mir_transform[9430bfac33e5f97a]::elaborate_drops::Elaborator>>::elaborate_drop
  18:        0x1123fd6f0 - <rustc_mir_transform[9430bfac33e5f97a]::elaborate_drops::ElaborateDrops as rustc_middle[fe685cc1f47f288d]::mir::MirPass>::run_pass
  19:        0x112283586 - rustc_mir_transform[9430bfac33e5f97a]::pass_manager::run_passes_inner
  20:        0x1122ef856 - rustc_mir_transform[9430bfac33e5f97a]::run_analysis_to_runtime_passes
  21:        0x1122ef388 - rustc_mir_transform[9430bfac33e5f97a]::mir_drops_elaborated_and_const_checked
  22:        0x11279206f - rustc_query_impl[69bc60a40b6cadc3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[69bc60a40b6cadc3]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fe685cc1f47f288d]::query::erase::Erased<[u8; 8usize]>>
  23:        0x11293c3fc - <rustc_query_impl[69bc60a40b6cadc3]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2} as core[73a651594a9ef86f]::ops::function::FnOnce<(rustc_middle[fe685cc1f47f288d]::ty::context::TyCtxt, rustc_span[8808993aab5b8002]::def_id::LocalDefId)>>::call_once
  24:        0x112754443 - rustc_query_system[9bc60c1c102f4eb6]::query::plumbing::try_execute_query::<rustc_query_impl[69bc60a40b6cadc3]::DynamicConfig<rustc_query_system[9bc60c1c102f4eb6]::query::caches::VecCache<rustc_span[8808993aab5b8002]::def_id::LocalDefId, rustc_middle[fe685cc1f47f288d]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[69bc60a40b6cadc3]::plumbing::QueryCtxt, true>
  25:        0x11291b30c - rustc_query_impl[69bc60a40b6cadc3]::query_impl::mir_drops_elaborated_and_const_checked::get_query_incr::__rust_end_short_backtrace
  26:        0x111bb22c5 - <rustc_session[4ad9f1f8d356ed64]::session::Session>::time::<(), rustc_interface[64cb6972a1b5747c]::passes::analysis::{closure#2}>
  27:        0x111c217ce - rustc_interface[64cb6972a1b5747c]::passes::analysis
  28:        0x11279254d - rustc_query_impl[69bc60a40b6cadc3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[69bc60a40b6cadc3]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fe685cc1f47f288d]::query::erase::Erased<[u8; 1usize]>>
  29:        0x1128ef5b9 - <rustc_query_impl[69bc60a40b6cadc3]::query_impl::analysis::dynamic_query::{closure#2} as core[73a651594a9ef86f]::ops::function::FnOnce<(rustc_middle[fe685cc1f47f288d]::ty::context::TyCtxt, ())>>::call_once
  30:        0x1126e5afd - rustc_query_system[9bc60c1c102f4eb6]::query::plumbing::try_execute_query::<rustc_query_impl[69bc60a40b6cadc3]::DynamicConfig<rustc_query_system[9bc60c1c102f4eb6]::query::caches::SingleCache<rustc_middle[fe685cc1f47f288d]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[69bc60a40b6cadc3]::plumbing::QueryCtxt, true>
  31:        0x1128aa3ad - rustc_query_impl[69bc60a40b6cadc3]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  32:        0x111410654 - <rustc_middle[fe685cc1f47f288d]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>
  33:        0x1113c993c - <rustc_interface[64cb6972a1b5747c]::interface::Compiler>::enter::<rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}::{closure#2}, core[73a651594a9ef86f]::result::Result<core[73a651594a9ef86f]::option::Option<rustc_interface[64cb6972a1b5747c]::queries::Linker>, rustc_span[8808993aab5b8002]::ErrorGuaranteed>>
  34:        0x111406d4b - rustc_span[8808993aab5b8002]::set_source_map::<core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>, rustc_interface[64cb6972a1b5747c]::interface::run_compiler<core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>, rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  35:        0x1113f53d4 - <scoped_tls[2b2dba828880094e]::ScopedKey<rustc_span[8808993aab5b8002]::SessionGlobals>>::set::<rustc_interface[64cb6972a1b5747c]::interface::run_compiler<core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>, rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}>::{closure#0}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>
  36:        0x111413157 - std[8a8250c921f3e24c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[64cb6972a1b5747c]::util::run_in_thread_pool_with_globals<rustc_interface[64cb6972a1b5747c]::interface::run_compiler<core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>, rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}>::{closure#0}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>
  37:        0x111413ce9 - <<std[8a8250c921f3e24c]::thread::Builder>::spawn_unchecked_<rustc_interface[64cb6972a1b5747c]::util::run_in_thread_pool_with_globals<rustc_interface[64cb6972a1b5747c]::interface::run_compiler<core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>, rustc_driver_impl[b1ad63243822c31d]::run_compiler::{closure#1}>::{closure#0}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[73a651594a9ef86f]::result::Result<(), rustc_span[8808993aab5b8002]::ErrorGuaranteed>>::{closure#1} as core[73a651594a9ef86f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:        0x1051d5aa9 - std::sys::unix::thread::Thread::new::thread_start::h5f50da5e904389eb
  39:     0x7ff80e7634e1 - __pthread_start

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.73.0-nightly (8ca44ef9c 2023-07-10) running on x86_64-apple-darwin

note: compiler flags: --crate-type lib -C opt-level=2 -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C debug-assertions=on -C incremental=[REDACTED]

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

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `ice_cold`
#1 [analysis] running analysis passes on this crate
end of query stack

@kpreid kpreid 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 Jul 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 11, 2023
@kpreid
Copy link
Contributor Author

kpreid commented Jul 11, 2023

@rustbot label +A-impl-trait +F-type_alias_impl_trait

@rustbot rustbot added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Jul 11, 2023
@kpreid kpreid changed the title "open drop from non-ADT" in TAIT usage TAIT: "open drop from non-ADT" Jul 11, 2023
@jyn514 jyn514 added I-monomorphization Issue: An error at monomorphization time. requires-nightly This issue requires a nightly compiler in some way. labels Jul 12, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 12, 2023
@oli-obk oli-obk self-assigned this Aug 30, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 11, 2023
Reveal opaque types before drop elaboration

fixes rust-lang#113594

r? `@cjgillot`

cc `@JakobDegen`

This pass was introduced in rust-lang#110714

I moved it before drop elaboration (which only cares about the hidden types of things, not the opaque TAIT or RPIT type) and set it to run unconditionally (instead of depending on the optimization level and whether the inliner is active)
@lcnr
Copy link
Contributor

lcnr commented Sep 25, 2023

another relevant test from #116141:

#![feature(type_alias_impl_trait)]

fn foo<T>(x: T) {
    type Opaque<T> = impl Sized;
    let foo: Opaque<T> = (x,);
    let (a,): (T,) = foo;
}

fn main() {
    foo::<u32>(1);
}

@kpreid
Copy link
Contributor Author

kpreid commented Sep 30, 2023

I can confirm that on rustc 1.74.0-nightly (8ce4540 2023-09-29), the original code I minimized from no longer ICEs, and passes its tests.

RalfJung pushed a commit to RalfJung/miri that referenced this issue Sep 30, 2023
Reveal opaque types before drop elaboration

fixes rust-lang/rust#113594

r? `@cjgillot`

cc `@JakobDegen`

This pass was introduced in rust-lang/rust#110714

I moved it before drop elaboration (which only cares about the hidden types of things, not the opaque TAIT or RPIT type) and set it to run unconditionally (instead of depending on the optimization level and whether the inliner is active)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-monomorphization Issue: An error at monomorphization time. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

Successfully merging a pull request may close this issue.

6 participants