Skip to content

Commit 55cc8e4

Browse files
committed
Encode MIR for const ctors in metadata
This is needed for them to be usable under `min_generic_const_args`. They are not currently encoded for some reason.
1 parent b76036c commit 55cc8e4

File tree

7 files changed

+16
-26
lines changed

7 files changed

+16
-26
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::atomic::Ordering::Relaxed;
22

33
use either::{Left, Right};
44
use rustc_abi::{self as abi, BackendRepr};
5-
use rustc_hir::def::DefKind;
5+
use rustc_hir::def::{CtorKind, DefKind};
66
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
77
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
88
use rustc_middle::query::TyCtxtAt;
@@ -41,6 +41,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
4141
| DefKind::AnonConst
4242
| DefKind::InlineConst
4343
| DefKind::AssocConst
44+
| DefKind::Ctor(_, CtorKind::Const)
4445
),
4546
"Unexpected DefKind: {:?}",
4647
ecx.tcx.def_kind(cid.instance.def_id())

compiler/rustc_mir_transform/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_const_eval::util;
2121
use rustc_data_structures::fx::FxIndexSet;
2222
use rustc_data_structures::steal::Steal;
2323
use rustc_hir as hir;
24-
use rustc_hir::def::{CtorKind, DefKind};
24+
use rustc_hir::def::DefKind;
2525
use rustc_hir::def_id::LocalDefId;
2626
use rustc_index::IndexVec;
2727
use rustc_middle::mir::{
@@ -324,7 +324,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
324324
for item in tcx.hir_crate_items(()).free_items() {
325325
if let DefKind::Struct | DefKind::Enum = tcx.def_kind(item.owner_id) {
326326
for variant in tcx.adt_def(item.owner_id).variants() {
327-
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
327+
if let Some((_, ctor_def_id)) = variant.ctor {
328328
set.insert(ctor_def_id.expect_local());
329329
}
330330
}

tests/crashes/132985.rs

-17
This file was deleted.

tests/crashes/auxiliary/aux132985.rs

-6
This file was deleted.

tests/ui/const-generics/auxiliary/xcrate-const-ctor-a.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// NOTE: This aux file inherits revisions from its parent tests.
2+
13
#![feature(adt_const_params)]
4+
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]
25

36
use std::marker::ConstParamTy;
47

tests/ui/const-generics/xcrate-const-ctor-b.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//@ check-pass
2+
//@ revisions: normal mgca
23
//@ aux-build:xcrate-const-ctor-a.rs
34

45
#![feature(adt_const_params)]
6+
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]
57

68
extern crate xcrate_const_ctor_a;
79
use xcrate_const_ctor_a::Foo;

tests/ui/stable-mir-print/operands.stdout

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) -
250250
return;
251251
}
252252
}
253+
fn Ctors::Unit() -> Ctors {
254+
let mut _0: Ctors;
255+
bb0: {
256+
_0 = Ctors::Unit;
257+
return;
258+
}
259+
}
253260
fn Ctors::TupLike(_1: bool) -> Ctors {
254261
let mut _0: Ctors;
255262
bb0: {

0 commit comments

Comments
 (0)