Skip to content

Commit 519d892

Browse files
committed
Auto merge of rust-lang#121387 - oli-obk:eager_const_failures_regression, r=lcnr
Avoid some unnecessary query invocations. Specifically this inlines `const_eval_poly` and avoids computing the generic params, the param env, normalizing the param env and erasing lifetimes on everything. should fix the perf regression from rust-lang#121087
2 parents b13a71a + 3ec5042 commit 519d892

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ use rustc_errors::ErrorGuaranteed;
101101
use rustc_hir as hir;
102102
use rustc_hir::def::DefKind;
103103
use rustc_middle::middle;
104+
use rustc_middle::mir::interpret::GlobalId;
104105
use rustc_middle::query::Providers;
105-
use rustc_middle::ty::{Ty, TyCtxt};
106+
use rustc_middle::ty::{self, Ty, TyCtxt};
106107
use rustc_middle::util;
107108
use rustc_session::parse::feature_err;
108109
use rustc_span::{symbol::sym, Span};
@@ -186,7 +187,12 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
186187
let def_kind = tcx.def_kind(item_def_id);
187188
match def_kind {
188189
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
189-
DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()),
190+
DefKind::Const if tcx.generics_of(item_def_id).params.is_empty() => {
191+
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
192+
let cid = GlobalId { instance, promoted: None };
193+
let param_env = ty::ParamEnv::reveal_all();
194+
tcx.ensure().eval_to_const_value_raw(param_env.and(cid));
195+
}
190196
_ => (),
191197
}
192198
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Test that nonsense bounds prevent consts from being evaluated at all.
2+
//@ check-pass
3+
4+
#![feature(generic_const_items)]
5+
#![allow(incomplete_features)]
6+
trait Trait {
7+
const ASSOC: u32;
8+
}
9+
10+
// rustfmt eats the where bound
11+
#[rustfmt::skip]
12+
const ASSOC: u32 = <&'static ()>::ASSOC where for<'a> &'a (): Trait;
13+
14+
fn main() {}

0 commit comments

Comments
 (0)