Skip to content

Commit c98f662

Browse files
Always evaluate free lifetime-generic constants
Co-authored-by: Michael Goulet <[email protected]>
1 parent e08cd3c commit c98f662

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ use rustc_abi::ExternAbi;
9797
use rustc_hir as hir;
9898
use rustc_hir::def::DefKind;
9999
use rustc_middle::middle;
100-
use rustc_middle::mir::interpret::GlobalId;
101100
use rustc_middle::query::Providers;
102-
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
101+
use rustc_middle::ty::{Const, Ty, TyCtxt};
103102
use rustc_span::Span;
104103
use rustc_trait_selection::traits;
105104

@@ -168,11 +167,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
168167
let def_kind = tcx.def_kind(item_def_id);
169168
match def_kind {
170169
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
171-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
172-
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
173-
let cid = GlobalId { instance, promoted: None };
174-
let typing_env = ty::TypingEnv::fully_monomorphized();
175-
tcx.ensure().eval_to_const_value_raw(typing_env.as_query_input(cid));
170+
DefKind::Const if !tcx.generics_of(item_def_id).requires_monomorphization(tcx) => {
171+
tcx.ensure().const_eval_poly(item_def_id.into())
176172
}
177173
_ => (),
178174
}

tests/ui/generic-const-items/def-site-eval.fail.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0080]: evaluation of `_::<'_>` failed
2-
--> $DIR/def-site-eval.rs:14:20
2+
--> $DIR/def-site-eval.rs:13:20
33
|
44
LL | const _<'_a>: () = panic!();
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/def-site-eval.rs:14:20
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/def-site-eval.rs:13:20
66
|
77
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

tests/ui/generic-const-items/def-site-eval.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(incomplete_features)]
55

66
//@ revisions: fail pass
7-
//@[fail] build-fail (we require monomorphization)
87
//@[pass] build-pass (we require monomorphization)
98

109
const _<_T>: () = panic!();

0 commit comments

Comments
 (0)