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: AlignOf MIR operator called for unsized typefor struct without features #126939

Closed
Naserume opened this issue Jun 25, 2024 · 1 comment · Fixed by #129970
Closed

ICE: AlignOf MIR operator called for unsized typefor struct without features #126939

Naserume opened this issue Jun 25, 2024 · 1 comment · Fixed by #129970
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Naserume
Copy link

Code

struct MySlice<T: Copy>(bool, T);
type MySliceBool = MySlice<[bool]>;

use std::mem;

struct P2<T> {
    a: T,
    b: MySliceBool,
}

macro_rules! check {
    ($t:ty, $align:expr) => ({
        assert_eq!(mem::align_of::<$t>(), $align);
    });
}

pub fn main() {
    check!(P2<u8>, 1);
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error[E0277]: the trait bound `[bool]: Copy` is not satisfied
 --> ./F4E30.rs:8:8
  |
8 |     b: MySliceBool,
  |        ^^^^^^^^^^^ the trait `Copy` is not implemented for `[bool]`
  |
  = help: the trait `Copy` is implemented for `[T; N]`
note: required by a bound in `MySlice`
 --> ./F4E30.rs:1:19
  |
1 | struct MySlice<T: Copy>(bool, T);
  |                   ^^^^ required by this bound in `MySlice`

error: internal compiler error: compiler/rustc_const_eval/src/interpret/step.rs:241:21: AlignOf MIR operator called for unsized type P2<u8>
   --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:466:5
    |
466 |     intrinsics::min_align_of::<T>()
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/step.rs:241:21:
Box<dyn Any>
stack backtrace:
   0:        0x1016e6b43 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71f7af0ddafc64d
   1:        0x10173225b - core::fmt::write::h30d0e266faff29b6
   2:        0x1016dcace - std::io::Write::write_fmt::he666ca78eb4b8406
   3:        0x1016e6931 - std::sys::backtrace::print::h22721f9ab9a2749a
   4:        0x1016e9709 - std::panicking::default_hook::{{closure}}::h145e29ed875d8021
   5:        0x1016e948a - std::panicking::default_hook::h5d437c7e6bf0e3b5
   6:        0x10a98147c - std[8efa578c02603ef9]::panicking::update_hook::<alloc[135510a28be92df]::boxed::Box<rustc_driver_impl[63f2171535a6fe49]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x1016ea326 - std::panicking::rust_panic_with_hook::h6889093a56e48d04
   8:        0x10a9f0337 - std[8efa578c02603ef9]::panicking::begin_panic::<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>::{closure#0}
   9:        0x10a9dc949 - std[8efa578c02603ef9]::sys::backtrace::__rust_end_short_backtrace::<std[8efa578c02603ef9]::panicking::begin_panic<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>::{closure#0}, !>
  10:        0x10f3e2f09 - std[8efa578c02603ef9]::panicking::begin_panic::<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>
  11:        0x10aa02276 - <rustc_errors[8995f93e9c4bcc9a]::diagnostic::BugAbort as rustc_errors[8995f93e9c4bcc9a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x10a817adc - <rustc_errors[8995f93e9c4bcc9a]::DiagCtxtHandle>::span_bug::<rustc_span[aed5394308446158]::span_encoding::Span, alloc[135510a28be92df]::string::String>
  13:        0x10a847cce - rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt::<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}
  14:        0x10a847d07 - rustc_middle[4384e439927f71dd]::ty::context::tls::with_opt::<rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x10a833f05 - rustc_middle[4384e439927f71dd]::ty::context::tls::with_context_opt::<rustc_middle[4384e439927f71dd]::ty::context::tls::with_opt<rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x10f3d11b2 - rustc_middle[4384e439927f71dd]::util::bug::span_bug_fmt::<rustc_span[aed5394308446158]::span_encoding::Span>
  17:        0x10a8e74ce - <rustc_const_eval[e6f1030e4695f1ae]::interpret::eval_context::InterpCx<rustc_const_eval[e6f1030e4695f1ae]::const_eval::machine::CompileTimeMachine>>::statement
  18:        0x10a9022c5 - rustc_const_eval[e6f1030e4695f1ae]::const_eval::eval_queries::eval_to_allocation_raw_provider
  19:        0x10c0204fc - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>
  20:        0x10bfd61fe - <rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<(rustc_middle[4384e439927f71dd]::ty::context::TyCtxt, rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>)>>::call_once
  21:        0x10be11bbd - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  22:        0x10c04aaac - rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  23:        0x10a830f92 - rustc_middle[4384e439927f71dd]::query::plumbing::query_get_at::<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>>
  24:        0x10a8febb0 - rustc_const_eval[e6f1030e4695f1ae]::const_eval::eval_queries::eval_to_const_value_raw_provider
  25:        0x10c020e9c - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>
  26:        0x10bfdb5ee - <rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<(rustc_middle[4384e439927f71dd]::ty::context::TyCtxt, rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>)>>::call_once
  27:        0x10be11bbd - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  28:        0x10c04b35c - rustc_query_impl[a24e9023943e74ab]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  29:        0x10b6b3ea6 - rustc_middle[4384e439927f71dd]::query::plumbing::query_get_at::<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::mir::interpret::GlobalId>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 24usize]>>>
  30:        0x10b6b7fae - <rustc_middle[4384e439927f71dd]::ty::context::TyCtxt>::const_eval_global_id
  31:        0x10b6b78fd - <rustc_middle[4384e439927f71dd]::ty::context::TyCtxt>::const_eval_resolve
  32:        0x10b90558d - <rustc_const_eval[e6f1030e4695f1ae]::interpret::eval_context::InterpCx<rustc_const_eval[e6f1030e4695f1ae]::const_eval::dummy_machine::DummyMachine>>::eval_mir_constant::{closure#0}
  33:        0x10b9d7be5 - <rustc_mir_transform[6fada3a7f62d9c6e]::known_panics_lint::ConstPropagator>::eval_constant
  34:        0x10b9d8c35 - <rustc_mir_transform[6fada3a7f62d9c6e]::known_panics_lint::ConstPropagator as rustc_middle[4384e439927f71dd]::mir::visit::Visitor>::visit_assign
  35:        0x10b9de682 - <rustc_mir_transform[6fada3a7f62d9c6e]::known_panics_lint::ConstPropagator as rustc_middle[4384e439927f71dd]::mir::visit::Visitor>::visit_basic_block_data
  36:        0x10b9d869d - <rustc_mir_transform[6fada3a7f62d9c6e]::known_panics_lint::ConstPropagator as rustc_middle[4384e439927f71dd]::mir::visit::Visitor>::visit_body
  37:        0x10b9d500a - <rustc_mir_transform[6fada3a7f62d9c6e]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[6fada3a7f62d9c6e]::pass_manager::MirLint>::run_lint
  38:        0x10b976f44 - rustc_mir_transform[6fada3a7f62d9c6e]::pass_manager::run_passes_inner
  39:        0x10ba29e04 - rustc_mir_transform[6fada3a7f62d9c6e]::run_analysis_to_runtime_passes
  40:        0x10ba29957 - rustc_mir_transform[6fada3a7f62d9c6e]::mir_drops_elaborated_and_const_checked
  41:        0x10c0226ec - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 8usize]>>
  42:        0x10be9939e - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::VecCache<rustc_hir[ae2456c39d7f6170]::hir_id::OwnerId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  43:        0x10c0338eb - rustc_query_impl[a24e9023943e74ab]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  44:        0x10b2daf1a - rustc_interface[73216d77aad0c3a5]::passes::run_required_analyses
  45:        0x10b2dccb3 - rustc_interface[73216d77aad0c3a5]::passes::analysis
  46:        0x10c022dec - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  47:        0x10be0249e - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::SingleCache<rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  48:        0x10c02d307 - rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  49:        0x10a9258d7 - <rustc_interface[73216d77aad0c3a5]::queries::QueryResult<&rustc_middle[4384e439927f71dd]::ty::context::GlobalCtxt>>::enter::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  50:        0x10a97fc94 - rustc_interface[73216d77aad0c3a5]::interface::run_compiler::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}
  51:        0x10a96ec91 - std[8efa578c02603ef9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>
  52:        0x10a98a3a6 - <<std[8efa578c02603ef9]::thread::Builder>::spawn_unchecked_<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:        0x1016f352b - std::sys::pal::unix::thread::Thread::new::thread_start::h68d49fa26efc1659
  54:     0x7ff801f5318b - __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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/Documents/240624-57102.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `main::promoted[1]`
#1 [eval_to_const_value_raw] simplifying constant for the type system `main::promoted[1]`  |  = note: this failure-note originates in the macro `assert_eq` which comes from the expansion of the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)

end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.

@Naserume Naserume 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 Jun 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 25, 2024
@Naserume Naserume changed the title ICE: AlignOf MIR operator called for unsized typefor struct ICE: AlignOf MIR operator called for unsized typefor struct without features Jun 25, 2024
@GrigorenkoPV
Copy link
Contributor

searched nightlies: from nightly-2022-02-19 to nightly-2024-06-25
regressed nightly: nightly-2024-02-15
searched commit range: a84bb95...ee9c7c9
regressed commit: ee9c7c9 (#120847)

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jul 5, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 7, 2024
@bors bors closed this as completed in e2dc1a1 Sep 17, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Sep 17, 2024
layout computation: gracefully handle unsized types in unexpected locations

This PR reworks the layout computation to eagerly return an error when encountering an unsized field where a sized field was expected, rather than delaying a bug and attempting to recover a layout. This is required, because with trivially false where clauses like `[T]: Sized`, any field can possible be an unsized type, without causing a compile error.

Since this PR removes the `delayed_bug` method from the `LayoutCalculator` trait, it essentially becomes the same as the `HasDataLayout` trait, so I've also refactored the `LayoutCalculator` to be a simple wrapper struct around a type that implements `HasDataLayout`.

The majority of the diff is whitespace changes, so viewing with whitespace ignored is advised.

implements rust-lang/rust#123169 (comment)

r? `@compiler-errors` or compiler

fixes rust-lang/rust#123134
fixes rust-lang/rust#124182
fixes rust-lang/rust#126939
fixes rust-lang/rust#127737
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Sep 25, 2024
layout computation: gracefully handle unsized types in unexpected locations

This PR reworks the layout computation to eagerly return an error when encountering an unsized field where a sized field was expected, rather than delaying a bug and attempting to recover a layout. This is required, because with trivially false where clauses like `[T]: Sized`, any field can possible be an unsized type, without causing a compile error.

Since this PR removes the `delayed_bug` method from the `LayoutCalculator` trait, it essentially becomes the same as the `HasDataLayout` trait, so I've also refactored the `LayoutCalculator` to be a simple wrapper struct around a type that implements `HasDataLayout`.

The majority of the diff is whitespace changes, so viewing with whitespace ignored is advised.

implements rust-lang/rust#123169 (comment)

r? `@compiler-errors` or compiler

fixes rust-lang/rust#123134
fixes rust-lang/rust#124182
fixes rust-lang/rust#126939
fixes rust-lang/rust#127737
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants