rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.4k stars 12.73k forks source link

ICE in const_evaluatable_checked #76595

Closed DutchGhost closed 4 years ago

DutchGhost commented 4 years ago

I got a little excited with https://github.com/rust-lang/rust/pull/76559 merged, soooo I gave it a try, and I found this rather funny ICE. Notice how I call test::<2>(), without a type parameter, while the function expects a type parameter.

Code

#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]

struct Bool<const B: bool>;

trait True {}

impl True for Bool<true> {}

fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
    todo!()
}

fn main() {
    test::<2>();
}

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (a1947b3f9 2020-09-10)

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:1263:17: Layout::compute: unexpected type `^0`
Backtrace

``` thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:945:9 stack backtrace: 0: std::panicking::begin_panic 1: rustc_errors::HandlerInner::bug 2: rustc_errors::Handler::bug 3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}} 4: rustc_middle::ty::context::tls::with_opt::{{closure}} 5: rustc_middle::ty::context::tls::with_opt 6: rustc_middle::util::bug::opt_span_bug_fmt 7: rustc_middle::util::bug::bug_fmt 8: rustc_middle::ty::layout::LayoutCx::layout_raw_uncached 9: rustc_middle::ty::layout::layout_raw 10: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::layout_raw>::compute 11: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 12: rustc_data_structures::stack::ensure_sufficient_stack 13: rustc_query_system::query::plumbing::get_query_impl 14: as rustc_target::abi::LayoutOf>::layout_of 15: rustc_mir::interpret::intrinsics::eval_nullary_intrinsic 16: rustc_mir::const_eval::eval_queries::const_eval_validated_provider 17: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::const_eval_validated>::compute 18: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 19: rustc_data_structures::stack::ensure_sufficient_stack 20: rustc_query_system::query::plumbing::get_query_impl 21: rustc_middle::mir::interpret::queries::::const_eval_global_id 22: rustc_mir::interpret::eval_context::InterpCx::const_eval 23: rustc_mir::interpret::intrinsics::>::emulate_intrinsic 24: ::call_intrinsic 25: rustc_mir::interpret::terminator::>::eval_fn_call 26: rustc_mir::interpret::step::>::run 27: rustc_mir::const_eval::eval_queries::const_eval_raw_provider 28: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::const_eval_raw>::compute 29: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 30: rustc_data_structures::stack::ensure_sufficient_stack 31: rustc_query_system::query::plumbing::get_query_impl 32: rustc_mir::const_eval::machine::>::try_eval_const_fn_call 33: ::find_mir_or_eval_fn 34: rustc_mir::interpret::terminator::>::eval_fn_call 35: rustc_mir::interpret::step::>::run 36: rustc_mir::const_eval::eval_queries::const_eval_raw_provider 37: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::const_eval_raw>::compute 38: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 39: rustc_data_structures::stack::ensure_sufficient_stack 40: rustc_query_system::query::plumbing::get_query_impl 41: rustc_mir::const_eval::eval_queries::const_eval_validated_provider 42: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::const_eval_validated>::compute 43: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 44: rustc_data_structures::stack::ensure_sufficient_stack 45: rustc_query_system::query::plumbing::get_query_impl 46: rustc_middle::mir::interpret::queries::::const_eval_global_id 47: rustc_middle::mir::interpret::queries::::const_eval_resolve 48: rustc_infer::infer::InferCtxt::const_eval_resolve 49: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable 50: rustc_data_structures::obligation_forest::ObligationForest::process_obligations 51: ::select_where_possible 52: rustc_typeck::check::FnCtxt::resolve_vars_with_obligations 53: rustc_typeck::check::FnCtxt::structurally_resolved_type 54: rustc_typeck::check::callee::::check_call 55: rustc_typeck::check::expr::::check_expr_kind 56: rustc_typeck::check::expr::::check_expr_with_expectation 57: rustc_typeck::check::FnCtxt::check_stmt 58: rustc_typeck::check::FnCtxt::check_block_with_expected 59: rustc_typeck::check::expr::::check_expr_kind 60: rustc_typeck::check::expr::::check_expr_with_expectation 61: rustc_typeck::check::expr::::check_return_expr 62: rustc_typeck::check::check_fn 63: rustc_infer::infer::InferCtxtBuilder::enter 64: rustc_typeck::check::typeck 65: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::typeck>::compute 66: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 67: rustc_data_structures::stack::ensure_sufficient_stack 68: rustc_query_system::query::plumbing::get_query_impl 69: rustc_query_system::query::plumbing::ensure_query_impl 70: rustc_typeck::check::typeck_item_bodies 71: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::typeck_item_bodies>::compute 72: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 73: rustc_data_structures::stack::ensure_sufficient_stack 74: rustc_query_system::query::plumbing::get_query_impl 75: rustc_typeck::check_crate 76: rustc_interface::passes::analysis 77: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::analysis>::compute 78: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 79: rustc_data_structures::stack::ensure_sufficient_stack 80: rustc_query_system::query::plumbing::get_query_impl 81: rustc_interface::queries::::enter 82: rustc_span::with_source_map 83: rustc_interface::interface::create_compiler_and_run 84: scoped_tls::ScopedKey::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.48.0-nightly (a1947b3f9 2020-09-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 `^0` #1 [const_eval_validated] const-evaluating + checking `std::intrinsics::size_of` #2 [const_eval_raw] const-evaluating `std::mem::size_of` #3 [const_eval_raw] const-evaluating `test::{{constant}}#0` #4 [const_eval_validated] const-evaluating + checking `test::{{constant}}#0` #5 [typeck] type-checking `main` #6 [typeck_item_bodies] type-checking all item bodies #7 [analysis] running analysis passes on this crate end of query stack ```

lcnr commented 4 years ago

yeah, that ICE is interesting :thinking: and why is it only triggered with const-evaluatable_checked?

@rustbot claim