Skip to content

ICE when checking the size of a non-zero sized type in a generic const expression #90582

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

Closed
PatchMixolydic opened this issue Nov 4, 2021 · 1 comment
Labels
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.

Comments

@PatchMixolydic
Copy link
Contributor

Code

Playground

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use std::mem::size_of;

struct Predicate<const COND: bool>;
trait True {}
impl True for Predicate<true> {}

unsafe trait ZeroSized {}

unsafe impl<T> ZeroSized for T
where
    Predicate<{ size_of::<T>() == 0 }>: True,
{}

fn assert_zero_sized<T: ZeroSized>(_: T) {}

fn main() {
    assert_zero_sized(vec![1, 2, 3]);
}

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (baba6687d 2021-11-03)
binary: rustc
commit-hash: baba6687df3e83fdb15cc6ec239b4a1c75a30505
commit-date: 2021-11-03
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:2186:17: `is_trivially_sized` applied to unexpected type: ^0

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1147: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.58.0-nightly (18bc4bee9 2021-11-02) 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_of] computing layout of `*const ^0`
#1 [layout_of] computing layout of `core::ptr::unique::Unique<^0>`
end of query stack
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:2186:17: `is_trivially_sized` applied to unexpected type: ^0

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1147:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::ty::TyS>::is_sized
   8: rustc_middle::ty::layout::layout_of
   9: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  10: <alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>> as alloc::vec::spec_from_iter::SpecFromIter<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}::{closure#0}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  11: <alloc::vec::Vec<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>> as alloc::vec::spec_from_iter::SpecFromIter<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  12: rustc_middle::ty::layout::layout_of
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  14: <alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>> as alloc::vec::spec_from_iter::SpecFromIter<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}::{closure#0}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  15: <alloc::vec::Vec<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>> as alloc::vec::spec_from_iter::SpecFromIter<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  16: rustc_middle::ty::layout::layout_of
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  18: <alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>> as alloc::vec::spec_from_iter::SpecFromIter<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::FieldDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}::{closure#0}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  19: <alloc::vec::Vec<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>> as alloc::vec::spec_from_iter::SpecFromIter<alloc::vec::Vec<rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS>>, core::iter::adapters::ResultShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>>::layout_of_uncached::{closure#5}>, rustc_middle::ty::layout::LayoutError>>>::from_iter
  20: rustc_middle::ty::layout::layout_of
  21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::layout_of
  22: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter> as rustc_middle::ty::layout::LayoutOf>::layout_of
  23: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::run
  24: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
  25: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::eval_to_allocation_raw, rustc_query_impl::plumbing::QueryCtxt>
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_allocation_raw
  27: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
  28: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, core::result::Result<rustc_middle::mir::interpret::value::ConstValue, rustc_middle::mir::interpret::error::ErrorHandled>>>
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_const_value_raw
  30: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  31: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  32: <rustc_infer::infer::InferCtxt>::const_eval_resolve
  33: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations::{closure#0}
  34: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations
  35: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor, rustc_data_structures::obligation_forest::Outcome<rustc_trait_selection::traits::fulfill::PendingPredicateObligation, rustc_infer::traits::FulfillmentErrorCode>>
  36: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_with_constness_where_possible
  37: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  38: <rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  39: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  40: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  41: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  42: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  43: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  44: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  45: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  46: rustc_typeck::check::check::check_fn
  47: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  48: rustc_typeck::check::typeck
  49: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  50: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  51: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
  52: rustc_typeck::check::typeck_item_bodies
  53: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  54: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  55: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
  56: rustc_typeck::check_crate
  57: rustc_interface::passes::analysis
  58: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  59: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  60: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  61: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  62: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
  63: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
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.58.0-nightly (18bc4bee9 2021-11-02) 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_of] computing layout of `*const ^0`
#1 [layout_of] computing layout of `core::ptr::unique::Unique<^0>`
#2 [layout_of] computing layout of `alloc::raw_vec::RawVec<^0>`
#3 [layout_of] computing layout of `alloc::vec::Vec<^0>`
#4 [eval_to_allocation_raw] const-evaluating + checking `<impl at src/main.rs:12:1: 15:3>::{constant#0}`
#5 [eval_to_const_value_raw] simplifying constant for the type system `<impl at src/main.rs:12:1: 15:3>::{constant#0}`
#6 [typeck] type-checking `main`
#7 [typeck_item_bodies] type-checking all item bodies
#8 [analysis] running analysis passes on this crate
end of query stack

@PatchMixolydic PatchMixolydic 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 Nov 4, 2021
@PatchMixolydic
Copy link
Contributor Author

Duplicate of #88468

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. 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.
Projects
None yet
Development

No branches or pull requests

1 participant