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 with uninhabited and dynamically sized types #82954

Closed
svenknobloch opened this issue Mar 9, 2021 · 7 comments
Closed

ICE with uninhabited and dynamically sized types #82954

svenknobloch opened this issue Mar 9, 2021 · 7 comments
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@svenknobloch
Copy link

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.

@svenknobloch svenknobloch 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 Mar 9, 2021
@SNCPlay42
Copy link
Contributor

This compiles successfully on 1.32 (godbolt). It appears to require -C debuginfo=2 to reproduce.

@rustbot label regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 9, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

Slightly smaller:

use std::marker::PhantomData;

pub enum Empty {}

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

@hameerabbasi
Copy link
Contributor

Bisected:

found 5 bors merge commits in the specified range
  commit[0] 2018-12-20UTC: Auto merge of #56845 - GuillaumeGomez:const-docs, r=oli-obk
  commit[1] 2018-12-20UTC: Auto merge of #54125 - varkor:less-conservative-uninhabitedness-check, r=nikomatsakis
  commit[2] 2018-12-21UTC: Auto merge of #55798 - GuillaumeGomez:version-display-associated-const, r=QuietMisdreavus
  commit[3] 2018-12-21UTC: Auto merge of #56813 - oli-obk:main_🧶, r=pnkfelix
  commit[4] 2018-12-21UTC: Auto merge of #56779 - adrian-budau:master, r=alexcrichton
ERROR: no commits between 09d6ab90e556bf692ff3f8790d97b3ca4fee94b0 and e40548bc43f2a0375a466c98e174e71561dc98d2 within last 167 days

@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 10, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

Bisected:

found 5 bors merge commits in the specified range
  commit[0] 2018-12-20UTC: Auto merge of #56845 - GuillaumeGomez:const-docs, r=oli-obk
  commit[1] 2018-12-20UTC: Auto merge of #54125 - varkor:less-conservative-uninhabitedness-check, r=nikomatsakis
  commit[2] 2018-12-21UTC: Auto merge of #55798 - GuillaumeGomez:version-display-associated-const, r=QuietMisdreavus
  commit[3] 2018-12-21UTC: Auto merge of #56813 - oli-obk:main_🧶, r=pnkfelix
  commit[4] 2018-12-21UTC: Auto merge of #56779 - adrian-budau:master, r=alexcrichton
ERROR: no commits between 09d6ab90e556bf692ff3f8790d97b3ca4fee94b0 and e40548bc43f2a0375a466c98e174e71561dc98d2 within last 167 days

#54125 looks like it's the relevant PR, but it's not actually a bug, it just extends the checks to more items. I don't think this is really a regression, the bug was always there (only the ICE is a regression).

fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 12, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 12, 2021
@tmiasko
Copy link
Contributor

tmiasko commented Mar 20, 2021

A struct layout is uninhabited only if it sized and has any uninhabited fields (since #50622). This creates discrepancy with type-level view of things.

if sized && fields.iter().any(|f| f.abi.is_uninhabited()) {
abi = Abi::Uninhabited;
}

@Alexendoo
Copy link
Member

Fixed by #90854

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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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

9 participants