rust-lang / rust

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

ICE: `Unevaluated 'ty::Const' in MIR body` #133639

Open matthiaskrgr opened 2 hours ago

matthiaskrgr commented 2 hours ago

Code

#![feature(with_negative_coherence)]
#![feature(min_specialization)]
#![feature(generic_const_exprs)]

#![crate_type = "lib"]
use std::str::FromStr;

struct a<const b: bool>;

trait c {}

impl<const d: u32> FromStr for e<d>
where
    a<{ d <= 2 }>: c,
{
    type Err = ();
    fn from_str(f: &str) -> Result<Self, Self::Err> {
        unimplemented!()
    }
}
struct e<const d: u32>;

impl<const d: u32> FromStr for e<d>
where
    a<{ d <= 2 }>: c,
{
    type Err = ();
    fn from_str(f: &str) -> Result<Self, Self::Err> {
        unimplemented!()
    }
}

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (0c4f3a45b 2024-11-29)
binary: rustc
commit-hash: 0c4f3a45b86c77b0a89ff06703aa6097af35d924
commit-date: 2024-11-29
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Error output

warning: type `a` should have an upper camel case name
 --> code.rs:8:8
  |
8 | struct a<const b: bool>;
  |        ^ help: convert the identifier to upper camel case: `A`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: trait `c` should have an upper camel case name
  --> code.rs:10:7
   |
10 | trait c {}
   |       ^ help: convert the identifier to upper camel case (notice the capitalization): `C`

warning: type `e` should have an upper camel case name
  --> code.rs:21:8
   |
21 | struct e<const d: u32>;
   |        ^ help: convert the identifier to upper camel case: `E`

warning: unused variable: `f`
  --> code.rs:17:17
   |
17 |     fn from_str(f: &str) -> Result<Self, Self::Err> {
   |                 ^ help: if this is intentional, prefix it with an underscore: `_f`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `f`
  --> code.rs:28:17
   |
28 |     fn from_str(f: &str) -> Result<Self, Self::Err> {
   |                 ^ help: if this is intentional, prefix it with an underscore: `_f`

warning: const parameter `b` should have an upper case name
 --> code.rs:8:16
  |
8 | struct a<const b: bool>;
  |                ^ help: convert the identifier to upper case: `B`
  |
  = note: `#[warn(non_upper_case_globals)]` on by default

warning: const parameter `d` should have an upper case name
  --> code.rs:12:12
   |
12 | impl<const d: u32> FromStr for e<d>
   |            ^ help: convert the identifier to upper case: `D`

warning: const parameter `d` should have an upper case name
  --> code.rs:21:16
   |
21 | struct e<const d: u32>;
   |                ^ help: convert the identifier to upper case: `D`

warning: const parameter `d` should have an upper case name
  --> code.rs:23:12
   |
23 | impl<const d: u32> FromStr for e<d>
   |            ^ help: convert the identifier to upper case: `D`

warning: 10 warnings emitted
Backtrace

``` note: no errors encountered even though delayed bugs were created note: those delayed bugs will now be shown as internal compiler errors error: internal compiler error: Unevaluated `ty::Const` in MIR body | = note: delayed at /rustc/a2545fd6fc66b4323f555223a860c451885d1d2b/compiler/rustc_middle/src/mir/consts.rs:334:40 0: ::emit_diagnostic 1: ::emit_diagnostic 2: ::emit_producing_guarantee 3: ::delayed_bug::<&str> 4: >::push_stack_frame_raw 5: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider 6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 7: rustc_query_system::query::plumbing::try_execute_query::, rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 8: rustc_query_impl::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace 9: rustc_const_eval::const_eval::valtrees::eval_to_valtree 10: )>>::call_once 11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 12: )>>::call_once 13: rustc_query_system::query::plumbing::try_execute_query::, rustc_middle::query::erase::Erased<[u8; 24]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 14: rustc_query_impl::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace 15: rustc_middle::query::plumbing::query_get_at::, rustc_middle::query::erase::Erased<[u8; 24]>>> 16: ::const_eval_global_id_for_typeck 17: ::const_eval_resolve_for_typeck 18: rustc_trait_selection::traits::try_evaluate_const 19: ::evaluate_const 20: , rustc_middle::ty::context::TyCtxt>>::evaluate_goal_in_task::<&mut >::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 21: , rustc_middle::ty::context::TyCtxt>>::with_new_goal::<>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 22: >::evaluate_goal_raw 23: >::try_evaluate_added_goals 24: , rustc_middle::ty::context::TyCtxt>>::evaluate_goal_in_task::<&mut >::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 25: , rustc_middle::ty::context::TyCtxt>>::with_new_goal::<>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 26: >::evaluate_goal_raw 27: >::try_evaluate_added_goals 28: >::evaluate_added_goals_and_make_canonical_response::{closure#0} 29: as rustc_next_trait_solver::solve::assembly::GoalKind>::probe_and_match_goal_against_assumption::< as rustc_next_trait_solver::solve::assembly::GoalKind>::probe_and_consider_implied_clause<[(rustc_type_ir::solve::GoalSource, rustc_type_ir::solve::Goal); 0]>::{closure#0}> 30: >::compute_trait_goal 31: , rustc_middle::ty::context::TyCtxt>>::evaluate_goal_in_task::<&mut >::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 32: , rustc_middle::ty::context::TyCtxt>>::with_new_goal::<>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 33: >::evaluate_goal_raw 34: >::enter_root::, ::evaluate_root_goal::{closure#0}> 35: as rustc_infer::traits::engine::TraitEngine>::select_where_possible 36: as rustc_infer::traits::engine::TraitEngine>::select_all_or_error 37: rustc_trait_selection::traits::coherence::impl_intersection_has_negative_obligation 38: rustc_trait_selection::traits::coherence::overlap 39: ::insert 40: ::insert 41: rustc_trait_selection::traits::specialize::specialization_graph_provider 42: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 43: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 44: rustc_query_impl::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace 45: ::ancestors 46: rustc_hir_analysis::impl_wf_check::min_specialization::check_min_specialization 47: rustc_hir_analysis::check::wfcheck::check_well_formed 48: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 49: rustc_query_system::query::plumbing::try_execute_query::, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 50: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 51: rustc_hir_analysis::check::wfcheck::check_mod_type_wf 52: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 53: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 54: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace 55: rustc_hir_analysis::check_crate 56: rustc_interface::passes::run_required_analyses 57: rustc_interface::passes::analysis 58: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 59: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 60: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 61: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} 62: std::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>> 63: <::spawn_unchecked_, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 64: std::sys::pal::unix::thread::Thread::new::thread_start 65: 66: 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: please make sure that you have updated to the latest nightly note: please attach the file at `/home/matthias/vcs/github/CRED/rustc-ice-2024-11-29T16_25_14-3443642.txt` to your bug report query stack during panic: end of query stack ```

matthiaskrgr commented 2 hours ago

cc @BoxyUwU this compiled without error before #132927 and ICEs since 🤔