Skip to content

Commit

Permalink
Auto merge of rust-lang#134873 - camelid:const-ctor-mir, r=<try>
Browse files Browse the repository at this point in the history
Encode MIR for const ctors in metadata

Fixes rust-lang#132985.

This is needed for them to be usable under `min_generic_const_args`.
They are not currently encoded for some reason.

r? `@BoxyUwU`
  • Loading branch information
bors committed Dec 29, 2024
2 parents 0b63477 + 55cc8e4 commit e10a2b0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::Ordering::Relaxed;

use either::{Left, Right};
use rustc_abi::{self as abi, BackendRepr};
use rustc_hir::def::DefKind;
use rustc_hir::def::{CtorKind, DefKind};
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo, ReportedErrorInfo};
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
use rustc_middle::query::TyCtxtAt;
Expand Down Expand Up @@ -41,6 +41,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
| DefKind::AnonConst
| DefKind::InlineConst
| DefKind::AssocConst
| DefKind::Ctor(_, CtorKind::Const)
),
"Unexpected DefKind: {:?}",
ecx.tcx.def_kind(cid.instance.def_id())
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_const_eval::util;
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::steal::Steal;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_index::IndexVec;
use rustc_middle::mir::{
Expand Down Expand Up @@ -324,7 +324,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
for item in tcx.hir_crate_items(()).free_items() {
if let DefKind::Struct | DefKind::Enum = tcx.def_kind(item.owner_id) {
for variant in tcx.adt_def(item.owner_id).variants() {
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
if let Some((_, ctor_def_id)) = variant.ctor {
set.insert(ctor_def_id.expect_local());
}
}
Expand Down
17 changes: 0 additions & 17 deletions tests/crashes/132985.rs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/crashes/auxiliary/aux132985.rs

This file was deleted.

3 changes: 3 additions & 0 deletions tests/ui/const-generics/auxiliary/xcrate-const-ctor-a.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// NOTE: This aux file inherits revisions from its parent tests.

#![feature(adt_const_params)]
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]

use std::marker::ConstParamTy;

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/const-generics/xcrate-const-ctor-b.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//@ check-pass
//@ revisions: normal mgca
//@ aux-build:xcrate-const-ctor-a.rs

#![feature(adt_const_params)]
#![cfg_attr(mgca, feature(min_generic_const_args), allow(incomplete_features))]

extern crate xcrate_const_ctor_a;
use xcrate_const_ctor_a::Foo;
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/stable-mir-print/operands.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ fn closures::{closure#0}(_1: {closure@$DIR/operands.rs:47:5: 47:19}, _2: bool) -
return;
}
}
fn Ctors::Unit() -> Ctors {
let mut _0: Ctors;
bb0: {
_0 = Ctors::Unit;
return;
}
}
fn Ctors::TupLike(_1: bool) -> Ctors {
let mut _0: Ctors;
bb0: {
Expand Down

0 comments on commit e10a2b0

Please sign in to comment.