Skip to content

Commit 56d7af2

Browse files
committed
Avoid some query invocations, they are unnecessary and cause performance regressions
1 parent 237361b commit 56d7af2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::ItemKind;
1212
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1313
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
14+
use rustc_middle::mir::interpret::GlobalId;
1415
use rustc_middle::query::Providers;
1516
use rustc_middle::ty::print::with_no_trimmed_paths;
1617
use rustc_middle::ty::trait_def::TraitSpecializationKind;
@@ -294,8 +295,13 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
294295
tcx.ensure().eval_static_initializer(def_id);
295296
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
296297
}
297-
hir::ItemKind::Const(ty, ..) => {
298-
tcx.ensure().const_eval_poly(def_id.into());
298+
hir::ItemKind::Const(ty, ast_generics, _) => {
299+
if ast_generics.params.is_empty() {
300+
let instance = ty::Instance::new(def_id.into(), ty::GenericArgs::empty());
301+
let cid = GlobalId { instance, promoted: None };
302+
let param_env = ty::ParamEnv::reveal_all();
303+
tcx.ensure().eval_to_const_value_raw(param_env.and(cid));
304+
}
299305
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
300306
}
301307
hir::ItemKind::Struct(_, ast_generics) => {

0 commit comments

Comments
 (0)