Skip to content

Commit c54c5a3

Browse files
committed
DestructuredConst split mir and ty
1 parent 5268567 commit c54c5a3

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
100100
tcx: TyCtxt<'tcx>,
101101
param_env: ty::ParamEnv<'tcx>,
102102
val: mir::ConstantKind<'tcx>,
103-
) -> InterpResult<'tcx, mir::DestructuredMirConstant<'tcx>> {
103+
) -> InterpResult<'tcx, mir::DestructuredConstant<'tcx>> {
104104
trace!("destructure_mir_constant: {:?}", val);
105105
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
106106
let op = ecx.const_to_op(&val, None)?;
@@ -129,7 +129,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
129129
.collect::<InterpResult<'tcx, Vec<_>>>()?;
130130
let fields = tcx.arena.alloc_from_iter(fields_iter);
131131

132-
Ok(mir::DestructuredMirConstant { variant, fields })
132+
Ok(mir::DestructuredConstant { variant, fields })
133133
}
134134

135135
#[instrument(skip(tcx), level = "debug")]

compiler/rustc_middle/src/mir/interpret/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'tcx> TyCtxt<'tcx> {
211211
self,
212212
param_env: ty::ParamEnv<'tcx>,
213213
constant: mir::ConstantKind<'tcx>,
214-
) -> mir::DestructuredMirConstant<'tcx> {
214+
) -> mir::DestructuredConstant<'tcx> {
215215
self.try_destructure_mir_constant(param_env.and(constant)).unwrap()
216216
}
217217
}

compiler/rustc_middle/src/mir/query.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,9 @@ pub enum ClosureOutlivesSubject<'tcx> {
392392
Region(ty::RegionVid),
393393
}
394394

395-
/// The constituent parts of a type level constant of kind ADT or array.
396-
#[derive(Copy, Clone, Debug, HashStable)]
397-
pub struct DestructuredConst<'tcx> {
398-
pub variant: Option<VariantIdx>,
399-
pub fields: &'tcx [ty::Const<'tcx>],
400-
}
401-
402395
/// The constituent parts of a mir constant of kind ADT or array.
403396
#[derive(Copy, Clone, Debug, HashStable)]
404-
pub struct DestructuredMirConstant<'tcx> {
397+
pub struct DestructuredConstant<'tcx> {
405398
pub variant: Option<VariantIdx>,
406399
pub fields: &'tcx [ConstantKind<'tcx>],
407400
}

compiler/rustc_middle/src/query/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,9 @@ rustc_queries! {
10071007

10081008
/// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
10091009
/// and its field values.
1010-
query try_destructure_mir_constant(key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>) -> Option<mir::DestructuredMirConstant<'tcx>> {
1010+
query try_destructure_mir_constant(
1011+
key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1012+
) -> Option<mir::DestructuredConstant<'tcx>> {
10111013
desc { "destructuring mir constant"}
10121014
remap_env_constness
10131015
}

compiler/rustc_typeck/src/coherence/orphan.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::struct_span_err;
66
use rustc_errors::{Diagnostic, ErrorGuaranteed};
77
use rustc_hir as hir;
8-
use rustc_infer::infer::TyCtxtInferExt;
98
use rustc_middle::ty::subst::GenericArgKind;
109
use rustc_middle::ty::subst::InternalSubsts;
1110
use rustc_middle::ty::util::IgnoreRegions;
@@ -229,12 +228,8 @@ fn emit_orphan_check_error<'tcx>(
229228
"only traits defined in the current crate {msg}"
230229
);
231230
err.span_label(sp, "impl doesn't use only types from inside the current crate");
232-
for (ty, is_target_ty) in &tys {
233-
let mut ty = *ty;
234-
tcx.infer_ctxt().enter(|infcx| {
235-
// Remove the lifetimes unnecessary for this error.
236-
ty = infcx.freshen(ty);
237-
});
231+
for &(mut ty, is_target_ty) in &tys {
232+
ty = tcx.erase_regions(ty);
238233
ty = match ty.kind() {
239234
// Remove the type arguments from the output, as they are not relevant.
240235
// You can think of this as the reverse of `resolve_vars_if_possible`.
@@ -264,7 +259,7 @@ fn emit_orphan_check_error<'tcx>(
264259
};
265260

266261
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
267-
if *is_target_ty {
262+
if is_target_ty {
268263
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
269264
err.span_label(self_ty_span, &msg);
270265
} else {

0 commit comments

Comments
 (0)