Skip to content

ICE: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field comes after unsized field #84108

Closed
@chengniansun

Description

@chengniansun

The bug should be different from #61335, as the stack traces are different.

Code

static NONE: (AsRef<OsStr>, u8);

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (a836d9b64 2021-04-10)
binary: rustc
commit-hash: a836d9b6413d9d593be6c09463ff8c4c70e56599
commit-date: 2021-04-10
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Error output

error: free static item without body
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | static NONE: (AsRef<OsStr>, u8);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                                |
  |                                help: provide a definition for the static: `= <expr>;`

error[E0412]: cannot find type `OsStr` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:21
  |
1 | static NONE: (AsRef<OsStr>, u8);
  |                     ^^^^^ not found in this scope
  |
help: consider importing this struct
  |
1 | use std::ffi::OsStr;
  |

warning: trait objects without an explicit `dyn` are deprecated
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:15
  |
1 | static NONE: (AsRef<OsStr>, u8);
  |               ^^^^^^^^^^^^ help: use `dyn`: `dyn AsRef<OsStr>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | static NONE: (AsRef<OsStr>, u8);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field #2 of `(dyn AsRef<[type error]>, u8)` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', /rustc/a836d9b6413d9d593be6c09463ff8c4c70e56599/library/std/src/panic.rs:59:5
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.53.0-nightly (a836d9b64 2021-04-10) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [layout_raw] computing layout of `(dyn std::convert::AsRef<[type error]>, u8)`
#1 [check_mod_item_types] checking item types in top-level module
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.
Backtrace

error: free static item without body
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | static NONE: (AsRef<OsStr>, u8);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                                |
  |                                help: provide a definition for the static: `= <expr>;`

error[E0412]: cannot find type `OsStr` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:21
  |
1 | static NONE: (AsRef<OsStr>, u8);
  |                     ^^^^^ not found in this scope
  |
help: consider importing this struct
  |
1 | use std::ffi::OsStr;
  |

warning: trait objects without an explicit `dyn` are deprecated
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:15
  |
1 | static NONE: (AsRef<OsStr>, u8);
  |               ^^^^^^^^^^^^ help: use `dyn`: `dyn AsRef<OsStr>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | static NONE: (AsRef<OsStr>, u8);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field #2 of `(dyn AsRef<[type error]>, u8)` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', /rustc/a836d9b6413d9d593be6c09463ff8c4c70e56599/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::univariant_uninterned
   8: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::layout_raw_uncached
   9: rustc_middle::ty::layout::layout_raw
  10: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::layout_raw>::compute
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  12: rustc_data_structures::stack::ensure_sufficient_stack
  13: rustc_query_system::query::plumbing::force_query_with_job
  14: rustc_query_system::query::plumbing::get_query_impl
  15: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_raw
  16: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  17: rustc_typeck::check::check::check_static_inhabited
  18: rustc_typeck::check::check::check_item_type
  19: rustc_middle::hir::map::Map::visit_item_likes_in_module
  20: rustc_typeck::check::check::check_mod_item_types
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  22: rustc_query_system::query::plumbing::force_query_with_job
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  25: rustc_session::utils::<impl rustc_session::session::Session>::time
  26: rustc_typeck::check_crate
  27: rustc_interface::passes::analysis
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::force_query_with_job
  31: rustc_query_system::query::plumbing::get_query_impl
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  33: rustc_interface::passes::QueryContext::enter
  34: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  35: rustc_span::with_source_map
  36: rustc_interface::interface::create_compiler_and_run
  37: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.53.0-nightly (a836d9b64 2021-04-10) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [layout_raw] computing layout of `(dyn std::convert::AsRef<[type error]>, u8)`
#1 [check_mod_item_types] checking item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 11, 2021
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Apr 11, 2021
hameerabbasi

hameerabbasi commented on Apr 12, 2021

@hameerabbasi
Contributor

Bisected:

********************************************************************************
Regression in nightly-2020-10-27
********************************************************************************

fetching https://static.rust-lang.org/dist/2020-10-26/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2020-10-26: 40 B / 40 B [===============] 100.00 % 814.97 KB/s converted 2020-10-26 to 4760b8fb886a3702ae11bfa7868d495b2675b5ed
fetching https://static.rust-lang.org/dist/2020-10-27/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2020-10-27: 40 B / 40 B [=================] 100.00 % 1.02 MB/s converted 2020-10-27 to fd542592f08ca0d1f7255600115c2eafdf6b5da7
looking for regression commit between 2020-10-26 and 2020-10-27
opening existing repository at "rust.git"
refreshing repository
fetching (via local git) commits from 4760b8fb886a3702ae11bfa7868d495b2675b5ed to fd542592f08ca0d1f7255600115c2eafdf6b5da7
opening existing repository at "rust.git"
refreshing repository
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 11 bors merge commits in the specified range
  commit[0] 2020-10-25UTC: Auto merge of #78179 - RalfJung:miri-comments, r=oli-obk
  commit[1] 2020-10-25UTC: Auto merge of #78015 - ssomers:btree_merge_mergers, r=Mark-Simulacrum
  commit[2] 2020-10-26UTC: Auto merge of #77283 - estebank:if-let-sugg, r=Mark-Simulacrum
  commit[3] 2020-10-26UTC: Auto merge of #78387 - Dylan-DPC:rollup-ch0st6z, r=Dylan-DPC
  commit[4] 2020-10-26UTC: Auto merge of #75728 - nagisa:improve_align_offset_2, r=Mark-Simulacrum
  commit[5] 2020-10-26UTC: Auto merge of #78324 - RalfJung:uninhabited-statics, r=oli-obk
  commit[6] 2020-10-26UTC: Auto merge of #78196 - pietroalbini:shipped-files, r=Mark-Simulacrum
  commit[7] 2020-10-26UTC: Auto merge of #78395 - RalfJung:miri, r=RalfJung
  commit[8] 2020-10-26UTC: Auto merge of #77975 - bjorn3:cg_clif_subtree3, r=Mark-Simulacrum
  commit[9] 2020-10-26UTC: Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk
  commit[10] 2020-10-26UTC: Auto merge of #77187 - TimDiekmann:box-alloc, r=Amanieu
ERROR: no commits between 4760b8fb886a3702ae11bfa7868d495b2675b5ed and fd542592f08ca0d1f7255600115c2eafdf6b5da7 within last 167 days
camelid

camelid commented on Apr 12, 2021

@camelid
Member

Weirdly, the ICE only happens when you don't import OsStr. I.e., this ICEs:

static NONE: (dyn AsRef<OsStr>, u8) = ("hello", 42);

but this gives an appropriate unsized field error:

use std::ffi::OsStr;
static NONE: (dyn AsRef<OsStr>, u8) = ("hello", 42);
estebank

estebank commented on Apr 13, 2021

@estebank
Contributor

The error happens when a [type error] is involved, which makes the sizedness check for dyn AsRef not to be evaluated. A way to side-step the issue is to change

to be is !sized && !ty.references_error() {

self-assigned this
on Apr 14, 2021
apiraino

apiraino commented on Apr 14, 2021

@apiraino
Contributor

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

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Apr 14, 2021
added 2 commits that reference this issue on Apr 16, 2021
chengniansun

chengniansun commented on Jun 4, 2021

@chengniansun
Author

A potential duplicate.

Code

static FOO: (PartialEq<Item>, u32);

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (cc77ba46f 2021-06-03)
binary: rustc
commit-hash: cc77ba46fcb2d288aa01554b48cd586c5827c3dd
commit-date: 2021-06-03
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1

Error output

error: free static item without body
 --> mutant.rs:1:1
  |
1 | static FOO: (PartialEq<Item>, u32);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                                   |
  |                                   help: provide a definition for the static: `= <expr>;`

error[E0412]: cannot find type `Item` in this scope
 --> mutant.rs:1:24
  |
1 | static FOO: (PartialEq<Item>, u32);
  |                        ^^^^ not found in this scope

warning: trait objects without an explicit `dyn` are deprecated
 --> mutant.rs:1:14
  |
1 | static FOO: (PartialEq<Item>, u32);
  |              ^^^^^^^^^^^^^^^ help: use `dyn`: `dyn PartialEq<Item>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
  = note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>

error[E0601]: `main` function not found in crate `mutant`
 --> mutant.rs:1:1
  |
1 | static FOO: (PartialEq<Item>, u32);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `mutant.rs`

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field #2 of `(dyn PartialEq<[type error]>, u32)` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:1007: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.54.0-nightly (cc77ba46f 2021-06-03) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [layout_raw] computing layout of `(dyn std::cmp::PartialEq<[type error]>, u32)`
#1 [check_mod_item_types] checking item types in top-level module
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.
Backtrace

error: free static item without body
 --> mutant.rs:1:1
  |
1 | static FOO: (PartialEq<Item>, u32);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                                   |
  |                                   help: provide a definition for the static: `= <expr>;`

error[E0412]: cannot find type `Item` in this scope
 --> mutant.rs:1:24
  |
1 | static FOO: (PartialEq<Item>, u32);
  |                        ^^^^ not found in this scope

warning: trait objects without an explicit `dyn` are deprecated
 --> mutant.rs:1:14
  |
1 | static FOO: (PartialEq<Item>, u32);
  |              ^^^^^^^^^^^^^^^ help: use `dyn`: `dyn PartialEq<Item>`
  |
  = note: `#[warn(bare_trait_objects)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
  = note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>

error[E0601]: `main` function not found in crate `mutant`
 --> mutant.rs:1:1
  |
1 | static FOO: (PartialEq<Item>, u32);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `mutant.rs`

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field #2 of `(dyn PartialEq<[type error]>, u32)` comes after unsized field

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:1007:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::univariant_uninterned
   8: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::layout_raw_uncached
   9: rustc_middle::ty::layout::layout_raw
  10: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::layout_raw>::compute
  11: rustc_query_system::query::plumbing::get_query_impl
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_raw
  13: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  14: rustc_typeck::check::check::check_static_inhabited
  15: rustc_typeck::check::check::check_item_type
  16: rustc_middle::hir::map::Map::visit_item_likes_in_module
  17: rustc_typeck::check::check::check_mod_item_types
  18: rustc_query_system::query::plumbing::get_query_impl
  19: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  20: rustc_session::utils::<impl rustc_session::session::Session>::time
  21: rustc_typeck::check_crate
  22: rustc_interface::passes::analysis
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  25: rustc_interface::passes::QueryContext::enter
  26: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.54.0-nightly (cc77ba46f 2021-06-03) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [layout_raw] computing layout of `(dyn std::cmp::PartialEq<[type error]>, u32)`
#1 [check_mod_item_types] checking item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.

added a commit that references this issue on Jun 7, 2021

Rollup merge of rust-lang#84262 - camelid:sized-ice, r=estebank

ac6e239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @estebank@jonas-schievink@hameerabbasi@chengniansun@apiraino

    Issue actions

      ICE: compiler/rustc_middle/src/ty/layout.rs:370:17: univariant: field comes after unsized field · Issue #84108 · rust-lang/rust