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: offset of not-statically-aligned field (...) cannot be computed statically in rustc_middle/src/ty/layout.rs #125805

Open
cushionbadak opened this issue May 31, 2024 · 5 comments
Labels
C-bug Category: This is a bug. F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(hand-reduced)

#![feature(builtin_syntax)]

trait MyTrait<'a> {}

struct S { f: MyTrait, }

fn t3() {
    builtin # offset_of(S, f);
}

fn main() {}
(original)

// Tests that we still detect defining usages when
// lifetimes are used in an associated opaque type
//@ check-pass

#![feature(impl_trait_in_assoc_type)]

trait UnwrapItemsExt<'a> {
    type Iter;
    fn unwrap_items(self) -> Self::Iter;
}

struct MyStruct {}

trait MyTrait<'a> {}

impl<'a> MyTrait<'a> for MyStruct {}

impl<'a, I> UnwrapItemsExt<'a> for I {
    type Iter = impl MyTrait<'a>;

    fn unwrap_items(self) -> Self::Iter {
        MyStruct {}
    }
}

fn main() {}


#![feature(builtin_syntax)]

// For the exposed macro we already test these errors in the other files,
// but this test helps to make sure the builtin construct also errors.
// This has the same examples as offset-of-arg-count.rs

fn main() {
    builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of
}
fn t1() {
    builtin # offset_of(NotEnoughArgumentsWithAComma, ); //~ ERROR expected expression
}
fn t2() {
    builtin # offset_of(S, f, too many arguments); //~ ERROR expected `)`, found `too`
}
fn t3() {
    builtin # offset_of(S, f); // compiles fine
}
fn t4() {
    builtin # offset_of(S, f.); //~ ERROR unexpected token
}
fn t5() {
    builtin # offset_of(S, f.,); //~ ERROR unexpected token
}
fn t6() {
    builtin # offset_of(S, f..); //~ ERROR offset_of expects dot-separated field and variant names
}
fn t7() {
    builtin # offset_of(S, f..,); //~ ERROR offset_of expects dot-separated field and variant names
}

struct S { f: MyTrait, }

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc

error[E0106]: missing lifetime specifier
 --> r_mod_FA6845.rs:5:15
  |
5 | struct S { f: MyTrait, }
  |               ^^^^^^^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
5 | struct S<'a> { f: MyTrait<'a>, }
  |         ++++             ++++

warning: trait objects without an explicit `dyn` are deprecated
 --> r_mod_FA6845.rs:5:15
  |
5 | struct S { f: MyTrait, }
  |               ^^^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
  |
5 | struct S { f: dyn MyTrait, }
  |               +++
Backtrace

thread 'rustc' panicked at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_target/src/abi/mod.rs:272:13:
offset of unsized field (type dyn [Binder(Trait(MyTrait<'_>), [])] + '{erased}) cannot be computed statically
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_target::abi::TyAndLayout<rustc_middle::ty::Ty>>::offset_of_subfield::<rustc_mir_transform::known_panics_lint::ConstPropagator, core::iter::adapters::copied::Copied<core::slice::iter::Iter<(rustc_target::abi::VariantIdx, rustc_target::abi::FieldIdx)>>>
   3: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_assign
   4: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_basic_block_data
   5: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_body
   6: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
   7: rustc_mir_transform::pass_manager::run_passes_inner
   8: rustc_mir_transform::run_analysis_to_runtime_passes
   9: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  10: rustc_interface::passes::run_required_analyses
  11: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  12: <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}>
  13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
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 `/Volumes/T7/workspace/240530_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-31T08_16_43-23629.txt` to your bug report

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `t3`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

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

Note

@cushionbadak cushionbadak 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 May 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 31, 2024
@compiler-errors
Copy link
Member

Please don't fuzz for builtin_syntax, that feature is never expected to work for users. This feature can be reproduced with the offset_of macro:

use core::mem::offset_of;

trait MyTrait<'a> {}

struct S { f: MyTrait, }

fn t3() {
    offset_of!(S, f);
}

fn main() {}

@compiler-errors compiler-errors added the F-offset_of `#![feature(offset_of)]` label May 31, 2024
@cushionbadak
Copy link
Author

Okay, I'll be careful from now on.

@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@cushionbadak
Copy link
Author

cushionbadak commented Jun 12, 2024

After some investigation, I found that the ICE triggering code I report does not show ICE if every builtin_syntax is converted into offset_of! macro. I guess this issue can be closed.


By the way, the reduced builtin_syntax ICE-triggering code causes ICE from 2024-03-22.

Regression in rust-lang-ci@fa215ae
The PR introducing the regression in this rollup is #122749: make type_flags(ReError) & HAS_ERROR

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30
regressed nightly: nightly-2024-03-22
searched commit range: 1388d7a...0ad927c
regressed commit: 6a6cd65

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 -- 125805.rs

@cushionbadak
Copy link
Author

ICE update

Code

trait X<'a> {}

use std::mem::offset_of;

struct T {
    y: X,
}

fn other() {
    offset_of!(T, y);
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (6b0f4b5ec 2024-06-24)
binary: rustc
commit-hash: 6b0f4b5ec3aa707ecaa78230722117324a4ce23c
commit-date: 2024-06-24
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

Command: rustc

error[E0106]: missing lifetime specifier
 --> E0F03.rs:6:8
  |
6 |     y: X,
  |        ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
5 ~ struct T<'a> {
6 ~     y: X<'a>,
  |

warning: trait objects without an explicit `dyn` are deprecated
 --> E0F03.rs:6:8
  |
6 |     y: X,
  |        ^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
  |
6 |     y: dyn X,
  |        +++
Backtrace

error: internal compiler error: /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/compiler/rustc_middle/src/ty/layout.rs:1344:21: offset of not-statically-aligned field (type dyn [Binder { value: Trait(X<'_>), bound_vars: [] }] + '{erased}) cannot be computed statically

thread 'rustc' panicked at /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/compiler/rustc_middle/src/ty/layout.rs:1344:21:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::context::TyCtxt>::offset_of_subfield::<core::iter::adapters::copied::Copied<core::slice::iter::Iter<(rustc_target::abi::VariantIdx, rustc_target::abi::FieldIdx)>>>
   7: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_assign
   8: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_basic_block_data
   9: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_body
  10: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
  11: rustc_mir_transform::pass_manager::run_passes_inner
  12: rustc_mir_transform::run_analysis_to_runtime_passes
  13: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  14: rustc_interface::passes::run_required_analyses
  15: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  16: <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}>
  17: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 `/Volumes/T7/workspace/placeholder_rustexec/0625/rustc-ice-2024-06-25T10_05_21-45421.txt` to your bug report

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `other`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 1 warning emitted

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

Note

@cushionbadak cushionbadak changed the title ICE: offset of unsized field (type dyn [Binder(Trait(MyTrait<'_>), [])] + '{erased}) cannot be computed statically with feature(builtin_syntax) ICE: offset of not-statically-aligned field (...) cannot be computed statically in rustc_middle/src/ty/layout.rs Jun 25, 2024
@adwinwhite
Copy link
Contributor

Cannot reproduce on nightly 2024-8-12. Maybe already fixed.

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. F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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