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: transmute: assertion failed: min <= max' #117812

Closed
matthiaskrgr opened this issue Nov 11, 2023 · 6 comments
Closed

ICE: transmute: assertion failed: min <= max' #117812

matthiaskrgr opened this issue Nov 11, 2023 · 6 comments
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

mod assert {
    use std::mem::{Assume, BikeshedIntrinsicFrom};
    pub struct Context;

    pub fn is_maybe_transmutable<Src, Dst>()
    where
        Dst: BikeshedIntrinsicFrom<Src, Context>,
    {
    }
}

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

    #[repr(C)]
    pub union Uninit {
        a: (),
        b: V0u8,
    }

    #[repr(C)]
    #[repr(C)]
    struct ExplicitlyPadded(V0u8, Uninit, V0u8);

    assert::is_maybe_transmutable::<(), ExplicitlyPadded>();
}
original code

original:

// check-pass
//! The presence of an `align(X)` annotation must be accounted for.

#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code, r#true, non_camel_case_types)]

mod assert {
    use std::mem::{Assume, BikeshedIntrinsicFrom};
    pub struct Context;

    pub fn is_maybe_transmutable<Src, Dst>()
    where
        Dst: BikeshedIntrinsicFrom<Src, Context, {
            Assume {
                alignment: true,
                lifetimes: true,
                safety: true,
                validity: true,
            }
        }>
    {}
}

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

    #[repr(C)]
    pub union Uninit {
        a: (),
        b: V0u8,
    }

    #[repr(C, align(2))] struct align_2(V0u8);

    #[repr(C)] struct ImplicitlyPadded(align_2, V0u8);
    #[repr(C)] struct ExplicitlyPadded(V0u8, Uninit, V0u8);

    // An implementation that (incorrectly) does not place a padding byte after
    // `align_2` will, incorrectly, reject the following transmutations.
    assert::is_maybe_transmutable::<ImplicitlyPadded, ExplicitlyPadded>();
    assert::is_maybe_transmutable::<Box<Alias>>();
}

Version information

rustc 1.75.0-nightly (1db4b1249 2023-11-11)
binary: rustc
commit-hash: 1db4b12494f698754b925f55061eb9e6b3241423
commit-date: 2023-11-11
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: unused import: `Assume`
 --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:2:20
  |
2 |     use std::mem::{Assume, BikeshedIntrinsicFrom};
  |                    ^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:30:2
   |
30 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs`

error[E0517]: attribute should be applied to a struct or union
  --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:13:12
   |
13 |       #[repr(packed, align(0x100))]
   |              ^^^^^^
14 |       #[repr(u8)]
15 | /     enum V0u8 {
16 | |         V = 0,
17 | |     }
   | |_____- not a struct or union

error[E0658]: use of unstable library feature 'transmutability'
 --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:2:20
  |
2 |     use std::mem::{Assume, BikeshedIntrinsicFrom};
  |                    ^^^^^^
  |
  = note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
  = help: add `#![feature(transmutability)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'transmutability'
 --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:2:28
  |
2 |     use std::mem::{Assume, BikeshedIntrinsicFrom};
  |                            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
  = help: add `#![feature(transmutability)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'transmutability'
 --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:7:14
  |
7 |         Dst: BikeshedIntrinsicFrom<Src, Context>,
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
  = help: add `#![feature(transmutability)]` to the crate attributes to enable

error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
  --> /tmp/icemaker_global_tempdir.vhOXnwiqD1fn/rustc_testrunner_tmpdir_reporting.dwaAls4BhtVg/mvce.rs:22:9
   |
22 |         b: V0u8,
   |         ^^^^^^^
   |
   = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
help: wrap the field type in `ManuallyDrop<...>`
   |
22 |         b: std::mem::ManuallyDrop<V0u8>,
   |            +++++++++++++++++++++++    +

thread 'rustc' panicked at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/cmp.rs:876:9:
assertion failed: min <= max
stack backtrace:
   0:     0x7f838782e62c - std::backtrace_rs::backtrace::libunwind::trace::h60c98351b446b6fc
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f838782e62c - std::backtrace_rs::backtrace::trace_unsynchronized::h5f7f811450b9c6bf
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f838782e62c - std::sys_common::backtrace::_print_fmt::h0d5170c59727098e
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f838782e62c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h75fbf13e2e3eab42
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f8387881630 - core::fmt::rt::Argument::fmt::hf5a01755b8c97b0f
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/fmt/rt.rs:142:9
   5:     0x7f8387881630 - core::fmt::write::h21ffd88623dd8e8a
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f83878224bf - std::io::Write::write_fmt::h192daa860eac75cb
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/io/mod.rs:1762:15
   7:     0x7f838782e414 - std::sys_common::backtrace::_print::h38432716ce8bcbbd
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f838782e414 - std::sys_common::backtrace::print::h1f49e3e8b68963a0
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f83878310a7 - std::panicking::default_hook::{{closure}}::h1ab1b9b9fcc59e11
  10:     0x7f8387830e0f - std::panicking::default_hook::h052ad26defc2b2d9
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:292:9
  11:     0x7f83844ef410 - std[d0bee0584bbc47af]::panicking::update_hook::<alloc[dbc0aa70caf49578]::boxed::Box<rustc_driver_impl[cdb930f4dd583f9b]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f83878317e8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h80a3a3c1c2830f76
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2021:9
  13:     0x7f83878317e8 - std::panicking::rust_panic_with_hook::hd1cd0e2bf5e3508a
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:783:13
  14:     0x7f8387831509 - std::panicking::begin_panic_handler::{{closure}}::h97ceddfe3dd8d703
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:649:13
  15:     0x7f838782eaf6 - std::sys_common::backtrace::__rust_end_short_backtrace::ha30381b9e82dea56
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f83878312a2 - rust_begin_unwind
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/panicking.rs:645:5
  17:     0x7f838787dd15 - core::panicking::panic_fmt::hfb14b7c9192d3596
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/panicking.rs:72:14
  18:     0x7f838787ddb3 - core::panicking::panic::h55b0e3fc25d6ee3f
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/core/src/panicking.rs:127:5
  19:     0x7f838506875e - <rustc_transmute[8d90f26179819fee]::layout::tree::Tree<rustc_transmute[8d90f26179819fee]::layout::rustc::Def, rustc_transmute[8d90f26179819fee]::layout::rustc::Ref>>::from_repr_c_variant
  20:     0x7f8385067bb1 - <rustc_transmute[8d90f26179819fee]::layout::tree::Tree<rustc_transmute[8d90f26179819fee]::layout::rustc::Def, rustc_transmute[8d90f26179819fee]::layout::rustc::Ref>>::from_ty
  21:     0x7f8385068473 - <rustc_transmute[8d90f26179819fee]::layout::tree::Tree<rustc_transmute[8d90f26179819fee]::layout::rustc::Def, rustc_transmute[8d90f26179819fee]::layout::rustc::Ref>>::from_repr_c_variant
  22:     0x7f8385067dc2 - <rustc_transmute[8d90f26179819fee]::layout::tree::Tree<rustc_transmute[8d90f26179819fee]::layout::rustc::Def, rustc_transmute[8d90f26179819fee]::layout::rustc::Ref>>::from_ty
  23:     0x7f838506b077 - <rustc_transmute[8d90f26179819fee]::rustc::TransmuteTypeEnv>::is_transmutable
  24:     0x7f83861685b4 - <rustc_trait_selection[6c7867fa258f0fc9]::traits::select::SelectionContext>::confirm_candidate
  25:     0x7f838623ad91 - <rustc_trait_selection[6c7867fa258f0fc9]::traits::select::SelectionContext>::evaluate_candidate
  26:     0x7f8385fd4b7f - <rustc_trait_selection[6c7867fa258f0fc9]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
  27:     0x7f8385fcdaa2 - <rustc_trait_selection[6c7867fa258f0fc9]::traits::select::SelectionContext>::evaluation_probe::<<rustc_trait_selection[6c7867fa258f0fc9]::traits::select::SelectionContext>::evaluate_root_obligation::{closure#0}>
  28:     0x7f8385a0899d - rustc_traits[1b3ad6effbd60470]::evaluate_obligation::evaluate_obligation
  29:     0x7f8385a08360 - rustc_query_impl[26ab2eb5a4b73d01]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[26ab2eb5a4b73d01]::query_impl::evaluate_obligation::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 2usize]>>
  30:     0x7f8385a078d0 - rustc_query_system[b68b7660e1b83fb7]::query::plumbing::try_execute_query::<rustc_query_impl[26ab2eb5a4b73d01]::DynamicConfig<rustc_query_system[b68b7660e1b83fb7]::query::caches::DefaultCache<rustc_type_ir[eee2672c2f33704e]::canonical::Canonical<rustc_middle[8d21d7bf35089fff]::ty::context::TyCtxt, rustc_middle[8d21d7bf35089fff]::ty::ParamEnvAnd<rustc_middle[8d21d7bf35089fff]::ty::Predicate>>, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[26ab2eb5a4b73d01]::plumbing::QueryCtxt, false>
  31:     0x7f8385a07555 - rustc_query_impl[26ab2eb5a4b73d01]::query_impl::evaluate_obligation::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f83828e2015 - <rustc_trait_selection[6c7867fa258f0fc9]::traits::fulfill::FulfillProcessor as rustc_data_structures[1a3c63c55c78a367]::obligation_forest::ObligationProcessor>::process_obligation
  33:     0x7f838580f7d2 - <rustc_data_structures[1a3c63c55c78a367]::obligation_forest::ObligationForest<rustc_trait_selection[6c7867fa258f0fc9]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[6c7867fa258f0fc9]::traits::fulfill::FulfillProcessor>
  34:     0x7f83863895bd - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::check_argument_types
  35:     0x7f83860e7707 - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::check_call
  36:     0x7f83862f57e5 - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:     0x7f8385dcc1ed - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::check_block_with_expected
  38:     0x7f83862f5ef4 - <rustc_hir_typeck[48a7925dd0d8cef4]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:     0x7f8385ff5cef - rustc_hir_typeck[48a7925dd0d8cef4]::check::check_fn
  40:     0x7f8385b197a9 - rustc_hir_typeck[48a7925dd0d8cef4]::typeck
  41:     0x7f8385b18b93 - rustc_query_impl[26ab2eb5a4b73d01]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[26ab2eb5a4b73d01]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 8usize]>>
  42:     0x7f83858eb4c3 - rustc_query_system[b68b7660e1b83fb7]::query::plumbing::try_execute_query::<rustc_query_impl[26ab2eb5a4b73d01]::DynamicConfig<rustc_query_system[b68b7660e1b83fb7]::query::caches::VecCache<rustc_span[c2bda87e20783fc8]::def_id::LocalDefId, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[26ab2eb5a4b73d01]::plumbing::QueryCtxt, false>
  43:     0x7f83858eb150 - rustc_query_impl[26ab2eb5a4b73d01]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7f8385ddf3c0 - rustc_hir_analysis[5a62dd6b63ca128a]::check_crate
  45:     0x7f8385b58517 - rustc_interface[97b84efa53a847bb]::passes::analysis
  46:     0x7f8385b58177 - rustc_query_impl[26ab2eb5a4b73d01]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[26ab2eb5a4b73d01]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 1usize]>>
  47:     0x7f83867986e4 - rustc_query_system[b68b7660e1b83fb7]::query::plumbing::try_execute_query::<rustc_query_impl[26ab2eb5a4b73d01]::DynamicConfig<rustc_query_system[b68b7660e1b83fb7]::query::caches::SingleCache<rustc_middle[8d21d7bf35089fff]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[26ab2eb5a4b73d01]::plumbing::QueryCtxt, false>
  48:     0x7f83867984d5 - rustc_query_impl[26ab2eb5a4b73d01]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7f83867a10ff - rustc_interface[97b84efa53a847bb]::interface::run_compiler::<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}
  50:     0x7f83867a841a - std[d0bee0584bbc47af]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[97b84efa53a847bb]::util::run_in_thread_with_globals<rustc_interface[97b84efa53a847bb]::util::run_in_thread_pool_with_globals<rustc_interface[97b84efa53a847bb]::interface::run_compiler<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>
  51:     0x7f83867a8243 - <<std[d0bee0584bbc47af]::thread::Builder>::spawn_unchecked_<rustc_interface[97b84efa53a847bb]::util::run_in_thread_with_globals<rustc_interface[97b84efa53a847bb]::util::run_in_thread_pool_with_globals<rustc_interface[97b84efa53a847bb]::interface::run_compiler<core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>, rustc_driver_impl[cdb930f4dd583f9b]::run_compiler::{closure#1}>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e724bad1857b6bd7]::result::Result<(), rustc_span[c2bda87e20783fc8]::ErrorGuaranteed>>::{closure#1} as core[e724bad1857b6bd7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x7f838783b6a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf4cdd73175754799
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2007:9
  53:     0x7f838783b6a5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6955d1f30cee8d29
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/alloc/src/boxed.rs:2007:9
  54:     0x7f838783b6a5 - std::sys::unix::thread::Thread::new::thread_start::h58dae6c91eb60bce
                               at /rustc/1db4b12494f698754b925f55061eb9e6b3241423/library/std/src/sys/unix/thread.rs:108:17
  55:     0x7f83816aa9eb - <unknown>
  56:     0x7f838172e7cc - <unknown>
  57:                0x0 - <unknown>

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: rustc 1.75.0-nightly (1db4b1249 2023-11-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `should_pad_explicitly_aligned_field::ExplicitlyPadded: core::mem::transmutability::BikeshedIntrinsicFrom<(), assert::Context, core::mem::transmutability::Assume { alignment: false, lifetimes: false, safety: false, validity: false }>`
#1 [typeck] type-checking `should_pad_explicitly_aligned_field`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 6 previous errors; 1 warning emitted

Some errors have detailed explanations: E0517, E0601, E0658, E0740.
For more information about an error, try `rustc --explain E0517`.

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

smaller:

#![feature(transmutability)]

use std::mem::BikeshedIntrinsicFrom;
pub struct Context;

pub fn is_maybe_transmutable<Src, Dst>()
where
    Dst: BikeshedIntrinsicFrom<Src, Context>,
{
}

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

    #[repr(C)]
    struct ExplicitlyPadded(V0u8);

    is_maybe_transmutable::<(), ExplicitlyPadded>();
}

@matthiaskrgr
Copy link
Member Author

Regression in nightly-2022-11-25

found 7 bors merge commits in the specified range
commit[0] 2022-11-23: Auto merge of #104410 - WaffleLapkin:unregress, r=estebank
commit[1] 2022-11-24: Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
commit[2] 2022-11-24: Auto merge of #104610 - ouz-a:revert-overflow, r=compiler-errors
commit[3] 2022-11-24: Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
commit[4] 2022-11-24: Auto merge of #104809 - matthiaskrgr:rollup-8abjdwh, r=matthiaskrgr
commit[5] 2022-11-24: Auto merge of #104321 - Swatinem:async-gen, r=oli-obk
commit[6] 2022-11-24: Auto merge of #103693 - HKalbasi:master, r=oli-obk
ERROR: no CI builds available between 70f8737 and b3bc6bf within last 167 days

@sunmy2019
Copy link

Panic on invalid code. Bisected to #103693

Nightly version: 1.75.0-nightly
(2023-11-10 edf0b1d)

Shorter

#![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() {}

The key difference is that V0u8 now has a valid TyAndLayout when querying layout_of. Before this PR, it does not.
This change caused an assertion failure in rustc_transmute.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 18, 2023
@matthiaskrgr matthiaskrgr added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Mar 23, 2024
@matthiaskrgr
Copy link
Member Author

#117812 (comment) still ICEs 🥲

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 19, 2024
@workingjubilee
Copy link
Member

This no longer ICEs because we no longer accept this combination of attributes on an enum, which is covered by this testcase:

#[repr(packed)] //~ ERROR: attribute should be applied to a struct
enum EPacked { A, B }

@workingjubilee
Copy link
Member

The current version looks more like:

#![feature(transmutability)]
mod assert {
    use std::mem::{Assume, TransmuteFrom};
    pub struct Context;

    pub fn is_maybe_transmutable<Src, Dst>()
    where
        Dst: TransmuteFrom<
            Src,
            {
                Assume {
                    alignment: true,
                    validity: true,
                    lifetimes: true,
                    safety: true,
                }
            },
        >,
    {
    }
}

fn should_pad_explicitly_aligned_field() {
    #[repr(packed, u8)]
    #[derive(Copy, Clone)]
    enum V0u8 {
        V = 0,
    }

    #[repr(C)]
    pub union Uninit {
        a: (),
        b: V0u8,
    }

    #[repr(C)]
    #[repr(C)]
    struct ExplicitlyPadded(V0u8, Uninit, V0u8);

    assert::is_maybe_transmutable::<(), ExplicitlyPadded>();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.
Projects
None yet
Development

No branches or pull requests

5 participants