Skip to content

Commit a83f8d0

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

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
203203
tcx.ensure_ok().eval_static_initializer(item_def_id);
204204
check::maybe_check_static_with_link_section(tcx, item_def_id);
205205
}
206-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
206+
DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() => {
207+
// FIXME(generic_const_items): Passing empty instead of identity args is fishy but
208+
// seems to be fine for now. Revisit this!
207209
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
208210
let cid = GlobalId { instance, promoted: None };
209211
let typing_env = ty::TypingEnv::fully_monomorphized();

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ impl<'v> RootCollector<'_, 'v> {
14831483

14841484
// But even just declaring them must collect the items they refer to
14851485
// unless their generics require monomorphization.
1486-
if !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
1486+
if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization()
14871487
&& let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id())
14881488
{
14891489
collect_const_value(self.tcx, val, self.output);

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

Lines changed: 2 additions & 2 deletions
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
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
//! Test that we only evaluate free const items (their def site to be clear)
22
//! whose generics don't require monomorphization.
33
#![feature(generic_const_items)]
4-
#![allow(incomplete_features)]
4+
#![expect(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)