diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-02-22 09:35:33 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-19 17:30:08 +0000 |
| commit | 3ec5042cf944cfb242408e45166e7da79eaf0692 (patch) | |
| tree | 0b76c4007ed0a80b17921e6a462fd9cc56303a78 /compiler/rustc_hir_analysis/src/lib.rs | |
| parent | 200e3f7995e231535fdea3be9cb9a3f098b4c856 (diff) | |
| download | rust-3ec5042cf944cfb242408e45166e7da79eaf0692.tar.gz rust-3ec5042cf944cfb242408e45166e7da79eaf0692.zip | |
Avoid computing generic params or a param env for free const items
Diffstat (limited to 'compiler/rustc_hir_analysis/src/lib.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 19ab2045cc5..ffebaaa24b6 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -102,8 +102,9 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_middle::middle; +use rustc_middle::mir::interpret::GlobalId; use rustc_middle::query::Providers; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util; use rustc_session::parse::feature_err; use rustc_span::{symbol::sym, Span}; @@ -187,7 +188,12 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { let def_kind = tcx.def_kind(item_def_id); match def_kind { DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id), - DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()), + DefKind::Const if tcx.generics_of(item_def_id).params.is_empty() => { + let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty()); + let cid = GlobalId { instance, promoted: None }; + let param_env = ty::ParamEnv::reveal_all(); + tcx.ensure().eval_to_const_value_raw(param_env.and(cid)); + } _ => (), } }); |
