DestructuredConst
split mir and ty
This commit is contained in:
parent
526856768d
commit
c54c5a3c77
5 changed files with 10 additions and 20 deletions
|
@ -100,7 +100,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
val: mir::ConstantKind<'tcx>,
|
val: mir::ConstantKind<'tcx>,
|
||||||
) -> InterpResult<'tcx, mir::DestructuredMirConstant<'tcx>> {
|
) -> InterpResult<'tcx, mir::DestructuredConstant<'tcx>> {
|
||||||
trace!("destructure_mir_constant: {:?}", val);
|
trace!("destructure_mir_constant: {:?}", val);
|
||||||
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
|
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
|
||||||
let op = ecx.const_to_op(&val, None)?;
|
let op = ecx.const_to_op(&val, None)?;
|
||||||
|
@ -129,7 +129,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
|
||||||
.collect::<InterpResult<'tcx, Vec<_>>>()?;
|
.collect::<InterpResult<'tcx, Vec<_>>>()?;
|
||||||
let fields = tcx.arena.alloc_from_iter(fields_iter);
|
let fields = tcx.arena.alloc_from_iter(fields_iter);
|
||||||
|
|
||||||
Ok(mir::DestructuredMirConstant { variant, fields })
|
Ok(mir::DestructuredConstant { variant, fields })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(tcx), level = "debug")]
|
#[instrument(skip(tcx), level = "debug")]
|
||||||
|
|
|
@ -211,7 +211,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self,
|
self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
constant: mir::ConstantKind<'tcx>,
|
constant: mir::ConstantKind<'tcx>,
|
||||||
) -> mir::DestructuredMirConstant<'tcx> {
|
) -> mir::DestructuredConstant<'tcx> {
|
||||||
self.try_destructure_mir_constant(param_env.and(constant)).unwrap()
|
self.try_destructure_mir_constant(param_env.and(constant)).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,16 +392,9 @@ pub enum ClosureOutlivesSubject<'tcx> {
|
||||||
Region(ty::RegionVid),
|
Region(ty::RegionVid),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The constituent parts of a type level constant of kind ADT or array.
|
|
||||||
#[derive(Copy, Clone, Debug, HashStable)]
|
|
||||||
pub struct DestructuredConst<'tcx> {
|
|
||||||
pub variant: Option<VariantIdx>,
|
|
||||||
pub fields: &'tcx [ty::Const<'tcx>],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The constituent parts of a mir constant of kind ADT or array.
|
/// The constituent parts of a mir constant of kind ADT or array.
|
||||||
#[derive(Copy, Clone, Debug, HashStable)]
|
#[derive(Copy, Clone, Debug, HashStable)]
|
||||||
pub struct DestructuredMirConstant<'tcx> {
|
pub struct DestructuredConstant<'tcx> {
|
||||||
pub variant: Option<VariantIdx>,
|
pub variant: Option<VariantIdx>,
|
||||||
pub fields: &'tcx [ConstantKind<'tcx>],
|
pub fields: &'tcx [ConstantKind<'tcx>],
|
||||||
}
|
}
|
||||||
|
|
|
@ -1007,7 +1007,9 @@ rustc_queries! {
|
||||||
|
|
||||||
/// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
|
/// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
|
||||||
/// and its field values.
|
/// and its field values.
|
||||||
query try_destructure_mir_constant(key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>) -> Option<mir::DestructuredMirConstant<'tcx>> {
|
query try_destructure_mir_constant(
|
||||||
|
key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
|
||||||
|
) -> Option<mir::DestructuredConstant<'tcx>> {
|
||||||
desc { "destructuring mir constant"}
|
desc { "destructuring mir constant"}
|
||||||
remap_env_constness
|
remap_env_constness
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::struct_span_err;
|
use rustc_errors::struct_span_err;
|
||||||
use rustc_errors::{Diagnostic, ErrorGuaranteed};
|
use rustc_errors::{Diagnostic, ErrorGuaranteed};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::subst::InternalSubsts;
|
use rustc_middle::ty::subst::InternalSubsts;
|
||||||
use rustc_middle::ty::util::IgnoreRegions;
|
use rustc_middle::ty::util::IgnoreRegions;
|
||||||
|
@ -229,12 +228,8 @@ fn emit_orphan_check_error<'tcx>(
|
||||||
"only traits defined in the current crate {msg}"
|
"only traits defined in the current crate {msg}"
|
||||||
);
|
);
|
||||||
err.span_label(sp, "impl doesn't use only types from inside the current crate");
|
err.span_label(sp, "impl doesn't use only types from inside the current crate");
|
||||||
for (ty, is_target_ty) in &tys {
|
for &(mut ty, is_target_ty) in &tys {
|
||||||
let mut ty = *ty;
|
ty = tcx.erase_regions(ty);
|
||||||
tcx.infer_ctxt().enter(|infcx| {
|
|
||||||
// Remove the lifetimes unnecessary for this error.
|
|
||||||
ty = infcx.freshen(ty);
|
|
||||||
});
|
|
||||||
ty = match ty.kind() {
|
ty = match ty.kind() {
|
||||||
// Remove the type arguments from the output, as they are not relevant.
|
// Remove the type arguments from the output, as they are not relevant.
|
||||||
// You can think of this as the reverse of `resolve_vars_if_possible`.
|
// You can think of this as the reverse of `resolve_vars_if_possible`.
|
||||||
|
@ -264,7 +259,7 @@ fn emit_orphan_check_error<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
|
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
|
||||||
if *is_target_ty {
|
if is_target_ty {
|
||||||
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
|
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
|
||||||
err.span_label(self_ty_span, &msg);
|
err.span_label(self_ty_span, &msg);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue