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: Fields cannot be extern types, unless they are at offset 0 #91827

Closed
tmiasko opened this issue Dec 12, 2021 · 2 comments · Fixed by #91910
Closed

ICE: Fields cannot be extern types, unless they are at offset 0 #91827

tmiasko opened this issue Dec 12, 2021 · 2 comments · Fixed by #91910
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@tmiasko
Copy link
Contributor

tmiasko commented Dec 12, 2021

Code

#![feature(extern_types)]

extern "C" {
    type Content;
}

pub struct List {
    len: usize,
    _opaque: Content,
}

pub fn main() {
    let _len = match Option::<&List>::None {
        Some(a) => a.len,
        None => 0,
    };
}

Meta

rustc 1.59.0-nightly (928783de6 2021-12-11)

Error output

error: internal compiler error: /rustc/928783de663bd855a96f14b2d38c1061603587c6/compiler/rustc_const_eval/src/interpret/eval_context.rs:627:33: Fields cannot be extern types, unless they are at offset 0
  --> a.rs:13:22
   |
13 |     let _len = match Option::<&List>::None {
   |                      ^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/928783de663bd855a96f14b2d38c1061603587c6/compiler/rustc_errors/src/lib.rs:1116:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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.59.0-nightly (928783de6 2021-12-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error
@tmiasko tmiasko 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 Dec 12, 2021
@tmiasko
Copy link
Contributor Author

tmiasko commented Dec 12, 2021

A slightly different reproducer that doesn't rely on constant propagation pass, and so should be more robust:

#![feature(extern_types)]

extern "C" {
    type Content;
}

pub struct List {
    len: usize,
    _opaque: Content,
}

pub const Z: usize = {
    let a = [0usize; 4];
    unsafe { &*(&a as *const _ as *const List) }.len
};

@rustbot label +A-const-eval +F-extern_types

@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2021

Error: Malformed triagebot.toml in master branch.
missing field trigger_labels for key autolabel at line 156 column 1

Please let @rust-lang/release know if you're having trouble with this bot.

@camelid camelid added F-extern_types `#![feature(extern_types)]` requires-nightly This issue requires a nightly compiler in some way. A-const-eval Area: Constant evaluation (MIR interpretation) labels Dec 13, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 13, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 17, 2021
miri: lift restriction on extern types being the only field in a struct

Fixes rust-lang#91827.

r? `@RalfJung`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 17, 2021
miri: lift restriction on extern types being the only field in a struct

Fixes rust-lang#91827.

r? ``@RalfJung``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 17, 2021
miri: lift restriction on extern types being the only field in a struct

Fixes rust-lang#91827.

r? ```@RalfJung```
@bors bors closed this as completed in 64ce698 Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants