Skip to content

Commit 57a68fb

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

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::{ErrorGuaranteed, Span};
104103
use rustc_trait_selection::traits;
105104

@@ -172,11 +171,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
172171
let def_kind = tcx.def_kind(item_def_id);
173172
match def_kind {
174173
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
175-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
176-
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
177-
let cid = GlobalId { instance, promoted: None };
178-
let typing_env = ty::TypingEnv::fully_monomorphized();
179-
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
174+
DefKind::Const if !tcx.generics_of(item_def_id).requires_monomorphization(tcx) => {
175+
tcx.ensure_ok().const_eval_poly(item_def_id.into())
180176
}
181177
_ => (),
182178
}

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)