Skip to content

ICE: upvar_tys called before capture types are inferred in rustc_type_ir/src/ty_kind/closure.rs #125881

Closed

Description

@cushionbadak

Code

(hand reduced & simplified)

#![crate_type = "lib"]
#![feature(transmutability)]
#![feature(unboxed_closures)]

const fn test() -> impl std::mem::BikeshedIntrinsicFrom() {
    || {}
}
original code

#![feature(transmutability)]

pub fn is_maybe_transmutable<Dst>()
where
    Dst: std::mem::BikeshedIntrinsicFrom<(), ()>,
{
}

fn should_pad_explicitly_aligned_field() {
    #[repr(packed, align(0x100))]
    #[repr(u8)]
    enum V0u8 {
        V,
    }

    is_maybe_transmutable::<V0u8>();
}

fn main() {}


#![feature(const_trait_impl)]

const fn test() -> impl ~const std::mem::BikeshedIntrinsicFrom() {
    const move || {
        let sl: &[u8] = b"foo";

        match sl {
            [first, remainder @ ..] => {
                assert_eq!(first, &b'f');
            }
            [] => panic!(),
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (f67a1acc0 2024-06-01)
binary: rustc
commit-hash: f67a1acc04c7ecbf05751b17592dd8d245b75256
commit-date: 2024-06-01
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc -Zcrate-attr="feature(effects)"

error[E0220]: associated type `Output` not found for `BikeshedIntrinsicFrom`
 --> r_sty_1331FC.rs:5:35
  |
5 | const fn test() -> impl std::mem::BikeshedIntrinsicFrom() {
  |                                   ^^^^^^^^^^^^^^^^^^^^^^^ associated type `Output` not found
Backtrace

thread 'rustc' panicked at /rustc/f67a1acc04c7ecbf05751b17592dd8d245b75256/compiler/rustc_type_ir/src/ty_kind/closure.rs:168:29:
upvar_tys called before capture types are inferred
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_ty_utils::layout::layout_of_uncached
   3: rustc_ty_utils::layout::layout_of
      [... omitted 2 frames ...]
   4: <rustc_transmute::maybe_transmutable::MaybeTransmutableQuery<rustc_middle::ty::Ty, rustc_middle::ty::context::TyCtxt>>::answer::{closure#0}
   5: <rustc_transmute::maybe_transmutable::MaybeTransmutableQuery<rustc_middle::ty::Ty, rustc_middle::ty::context::TyCtxt>>::answer
   6: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::get_safe_transmute_error_and_reason
   7: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_selection_error
   8: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
   9: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::try_structurally_resolve_type
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::coerce
  13: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::coerce_inner::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_return::{closure#1}>
  14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
  15: rustc_hir_typeck::check::check_fn
  16: rustc_hir_typeck::typeck
      [... omitted 2 frames ...]
  17: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  18: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
      [... omitted 2 frames ...]
  19: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  20: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 2 frames ...]
  21: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  22: rustc_hir_analysis::check::check::check_item_type
  23: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 2 frames ...]
  24: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
  25: <rustc_middle::hir::ModuleItems>::par_items::<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#0}>
  26: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 2 frames ...]
  27: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#1}>
  28: rustc_hir_analysis::check_crate
  29: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  30: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  31: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  32: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/jisukbyun/workspace/240601_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-02T07_07_30-17637.txt` to your bug report

note: compiler flags: -Z crate-attr=feature(effects)

query stack during panic:
panicked at /rustc/f67a1acc04c7ecbf05751b17592dd8d245b75256/compiler/rustc_type_ir/src/ty_kind.rs:856:17:
thread panicked while processing panic. aborting.
[1]    17637 abort      rustc r_sty_1331FC.rs -Zcrate-attr="feature(effects)"

Note

  • ICE location: rustc_type_ir/src/ty_kind/closure.rs L168
    pub fn upvar_tys(self) -> I::Tys {
    match self.tupled_upvars_ty().kind() {
    ty::Error(_) => Default::default(),
    ty::Tuple(tys) => tys,
    ty::Infer(_) => panic!("upvar_tys called before capture types are inferred"),
    ty => panic!("Unexpected representation of upvar types tuple {:?}", ty),
    }
    }
  • As shown in the backtrace, it panicked while printing the query stack.

Activity

  1. added
    C-bug
    I-ICE
    T-compiler
    on Jun 2, 2024
  2. added
    needs-triage
    on Jun 2, 2024
  3. added
    requires-nightly
    F-unboxed_closures
    F-effects
    F-transmutability
    and removed
    needs-triage
    on Jun 2, 2024
  4. lqd commented on Jun 2, 2024

    @lqd
    Member

    Since you seem to be fuzzing and opening a lot of issues (thanks!), please also add F-labels for every feature used in your repro so that triagers have less work to do to make the issue discoverable.

    Thanks in advance

  5. added
    A-closures
    on Jun 2, 2024
  6. cushionbadak commented on Jun 2, 2024

    @cushionbadak
    Author

    Thanks for your advice, but I'm unsure how to modify label on my issue. I can't see a gear icon next to the label lists when creating or viewing an issue.
    Perhaps label editing is available only to members of the Rust project, I guess.

  7. lqd commented on Jun 2, 2024

    @lqd
    Member

    Ah there’s a bot for that for everybody. I don’t have a link to the docs at the ready but you can use the bot for almost all labels, like @rustbot label -A-closures +A-closures

  8. removed
    A-closures
    on Jun 2, 2024
  9. lqd commented on Jun 2, 2024

    @lqd
    Member

    The A- ones are a bit more internal to find from just a repro, but the F- features one are straightforward

    @rustbot label +A-closures

  10. rustbot commented on Jun 2, 2024

    @rustbot
  11. added
    A-closures
    on Jun 2, 2024
  12. cushionbadak commented on Jun 2, 2024

    @cushionbadak
    Author

    Oh, I can use rustbot! I always wondered whether rustbot is available to everyone or not. Thanks!

  13. added
    S-bug-has-test
    on Jun 9, 2024
  14. cushionbadak commented on Jun 12, 2024

    @cushionbadak
    Author

    Regression in rust-lang-ci@d48eec5
    The PR introducing the regression in this rollup is #123367: Safe Transmute: Compute transmutability from `rustc_target:…

    searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30
    regressed nightly: nightly-2024-04-09
    searched commit range: 9d5cdf7...ab5bda1
    regressed commit: ab5bda1

    bisected with cargo-bisect-rustc v0.6.8

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125881.rs -Zcrate-attr=feature(effects)
  15. jswrenn commented on Oct 17, 2024

    @jswrenn
    Member

    This was fixed in #131112.

  16. added
    F-const_trait_impl
    on Nov 15, 2024
  17. fmease commented on Nov 15, 2024

    @fmease
    Member

    Closing as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresC-bugF-const_trait_implF-effectsF-transmutabilityF-unboxed_closuresI-ICES-bug-has-testT-compilerrequires-nightly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions