Skip to content

ICE with uninhabited and dynamically sized types #82954

Closed
@svenknobloch

Description

@svenknobloch

Code

Playground

use std::marker::PhantomData;

pub enum Empty {}

struct Test<A, B: ?Sized> {
    phantom: PhantomData<(A, B)>,
}

fn main() {
    let x: Test<Empty, [usize]>;
}

Error output

   Compiling playground v0.0.1 (/playground)
warning: unused variable: `x`
  --> src/main.rs:10:9
   |
10 |     let x: Test<Empty, [usize]>;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at 'assertion failed: layout.abi.is_uninhabited()', compiler/rustc_middle/src/ty/layout.rs:205:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.50.0 (cb75ad5db 2021-02-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [layout_raw] computing layout of `(Empty, [usize])`
end of query stack
warning: 1 warning emitted

error: could not compile `playground`

To learn more, run the command again with --verbose.

The error seems to only occur when using an uninhabited type with a dynamically sized one in a tuple.
Inhabited types with dynamically sized and uninhabited types with sized types both work.

A simple workaround for now is to box the DST in the PhantomData.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions