Skip to content

Commit 7adc2bb

Browse files
committed
Fix some things that were changed
1 parent 3b9b5c0 commit 7adc2bb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
use rustc_errors::ErrorGuaranteed;
99
use rustc_hir::LangItem;
10-
use rustc_hir::def::DefKind;
1110
use rustc_infer::infer::TyCtxtInferExt;
1211
use rustc_middle::mir::*;
1312
use rustc_middle::ty::{self, AdtDef, Ty};
1413
use rustc_middle::{bug, mir};
14+
use rustc_span::sym;
1515
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1616
use tracing::instrument;
1717

@@ -371,7 +371,8 @@ where
371371
// FIXME(mgca): is this really the right behavior? should we return the qualifs of the anon const body instead?
372372
// (note also that original code ignored trait assoc items)
373373
if promoted.is_none()
374-
&& !matches!(cx.tcx.def_kind(def), DefKind::Const | DefKind::AssocConst)
374+
&& cx.tcx.trait_of_assoc(def).is_none()
375+
&& !cx.tcx.has_attr(def, sym::type_const)
375376
{
376377
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
377378

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ use rustc_abi::{CVariadicStatus, ExternAbi};
9494
use rustc_hir::def::DefKind;
9595
use rustc_hir::lints::DelayedLint;
9696
use rustc_hir::{self as hir};
97-
use rustc_middle::middle;
97+
use rustc_middle::mir::interpret::GlobalId;
9898
use rustc_middle::query::Providers;
9999
use rustc_middle::ty::{Const, Ty, TyCtxt};
100+
use rustc_middle::{middle, ty};
100101
use rustc_session::parse::feature_err;
101-
use rustc_span::{ErrorGuaranteed, Span};
102+
use rustc_span::{ErrorGuaranteed, Span, sym};
102103
use rustc_trait_selection::traits;
103104

104105
pub use crate::collect::suggest_impl_trait;
@@ -226,6 +227,17 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
226227
tcx.ensure_ok().eval_static_initializer(item_def_id);
227228
check::maybe_check_static_with_link_section(tcx, item_def_id);
228229
}
230+
DefKind::Const
231+
if !tcx.generics_of(item_def_id).own_requires_monomorphization()
232+
&& !tcx.has_attr(item_def_id, sym::type_const) =>
233+
{
234+
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but
235+
// seems to be fine for now. Revisit this!
236+
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
237+
let cid = GlobalId { instance, promoted: None };
238+
let typing_env = ty::TypingEnv::fully_monomorphized();
239+
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
240+
}
229241
_ => (),
230242
}
231243
// Skip `AnonConst`s because we feed their `type_of`.

0 commit comments

Comments
 (0)