Skip to content

Commit a48c2f0

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

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
215215
tcx.ensure_ok().eval_static_initializer(item_def_id);
216216
check::maybe_check_static_with_link_section(tcx, item_def_id);
217217
}
218-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
218+
DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() => {
219+
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but
220+
// seems to be fine for now. Revisit this!
219221
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
220222
let cid = GlobalId { instance, promoted: None };
221223
let typing_env = ty::TypingEnv::fully_monomorphized();

compiler/rustc_monomorphize/src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ impl<'v> RootCollector<'_, 'v> {
14651465

14661466
// But even just declaring them must collect the items they refer to
14671467
// unless their generics require monomorphization.
1468-
if !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
1468+
if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization()
14691469
&& let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id())
14701470
{
14711471
collect_const_value(self.tcx, val, self.output);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0080]: evaluation of `_::<'_>` failed
2-
--> $DIR/def-site-eval.rs:14:20
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/def-site-eval.rs:13:20
33
|
44
LL | const _<'_a>: () = panic!();
55
| ^^^^^^^^ evaluation panicked: explicit panic

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#![allow(incomplete_features)]
55

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

109
const _<_T>: () = panic!();
1110
const _<const _N: usize>: () = panic!();
1211

1312
#[cfg(fail)]
14-
const _<'_a>: () = panic!(); //[fail]~ ERROR evaluation of `_::<'_>` failed
13+
const _<'_a>: () = panic!(); //[fail]~ ERROR evaluation of constant value failed
1514

1615
fn main() {}

0 commit comments

Comments
 (0)