mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 05:26:47 +00:00
Auto merge of #78313 - lcnr:somebody-fold-me, r=nikomatsakis
TypeFoldable: take self by value Implements https://github.com/rust-lang/compiler-team/issues/371 which is currently still in FCP. r? `@nikomatsakis`
This commit is contained in:
commit
9b2b02a840
@ -216,7 +216,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
|
||||
assert!(!inst.substs.needs_infer());
|
||||
let fn_sig = tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&fn_sig_for_fn_abi(tcx, inst),
|
||||
fn_sig_for_fn_abi(tcx, inst),
|
||||
);
|
||||
if fn_sig.c_variadic && !support_vararg {
|
||||
tcx.sess.span_fatal(
|
||||
@ -372,7 +372,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||
.mir
|
||||
.args_iter()
|
||||
.map(|local| {
|
||||
let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
|
||||
let arg_ty = fx.monomorphize(fx.mir.local_decls[local].ty);
|
||||
|
||||
// Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
|
||||
if Some(local) == fx.mir.spread_arg {
|
||||
@ -470,7 +470,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||
}
|
||||
|
||||
for local in fx.mir.vars_and_temps_iter() {
|
||||
let ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
|
||||
let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
|
||||
let layout = fx.layout_of(ty);
|
||||
|
||||
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
|
||||
@ -492,10 +492,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
args: &[Operand<'tcx>],
|
||||
destination: Option<(Place<'tcx>, BasicBlock)>,
|
||||
) {
|
||||
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
|
||||
let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx));
|
||||
let fn_sig = fx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx));
|
||||
|
||||
let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
|
||||
|
||||
@ -711,7 +711,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
let drop_fn_ty = drop_fn.ty(fx.tcx, ParamEnv::reveal_all());
|
||||
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&drop_fn_ty.fn_sig(fx.tcx),
|
||||
drop_fn_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, S
|
||||
.local_decls
|
||||
.iter()
|
||||
.map(|local_decl| {
|
||||
let ty = fx.monomorphize(&local_decl.ty);
|
||||
let ty = fx.monomorphize(local_decl.ty);
|
||||
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
|
||||
SsaKind::Ssa
|
||||
} else {
|
||||
|
@ -445,43 +445,43 @@ fn codegen_stmt<'tcx>(
|
||||
StatementKind::Assign(to_place_and_rval) => {
|
||||
let lval = codegen_place(fx, to_place_and_rval.0);
|
||||
let dest_layout = lval.layout();
|
||||
match &to_place_and_rval.1 {
|
||||
Rvalue::Use(operand) => {
|
||||
match to_place_and_rval.1 {
|
||||
Rvalue::Use(ref operand) => {
|
||||
let val = codegen_operand(fx, operand);
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
||||
let place = codegen_place(fx, *place);
|
||||
let place = codegen_place(fx, place);
|
||||
let ref_ = place.place_ref(fx, lval.layout());
|
||||
lval.write_cvalue(fx, ref_);
|
||||
}
|
||||
Rvalue::ThreadLocalRef(def_id) => {
|
||||
let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout());
|
||||
let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout());
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
|
||||
Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => {
|
||||
let lhs = codegen_operand(fx, lhs);
|
||||
let rhs = codegen_operand(fx, rhs);
|
||||
|
||||
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
|
||||
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
|
||||
lval.write_cvalue(fx, res);
|
||||
}
|
||||
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
|
||||
Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => {
|
||||
let lhs = codegen_operand(fx, lhs);
|
||||
let rhs = codegen_operand(fx, rhs);
|
||||
|
||||
let res = if !fx.tcx.sess.overflow_checks() {
|
||||
let val =
|
||||
crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
||||
crate::num::codegen_int_binop(fx, bin_op, lhs, rhs).load_scalar(fx);
|
||||
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
||||
CValue::by_val_pair(val, is_overflow, lval.layout())
|
||||
} else {
|
||||
crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs)
|
||||
crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs)
|
||||
};
|
||||
|
||||
lval.write_cvalue(fx, res);
|
||||
}
|
||||
Rvalue::UnaryOp(un_op, operand) => {
|
||||
Rvalue::UnaryOp(un_op, ref operand) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let layout = operand.layout();
|
||||
let val = operand.load_scalar(fx);
|
||||
@ -509,8 +509,8 @@ fn codegen_stmt<'tcx>(
|
||||
};
|
||||
lval.write_cvalue(fx, res);
|
||||
}
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
|
||||
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.tcx));
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, to_ty) => {
|
||||
let from_ty = fx.monomorphize(operand.ty(&fx.mir.local_decls, fx.tcx));
|
||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||
match *from_ty.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
@ -530,14 +530,14 @@ fn codegen_stmt<'tcx>(
|
||||
_ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty),
|
||||
}
|
||||
}
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), ref operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), ref operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), ref operand, to_ty) => {
|
||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||
let operand = codegen_operand(fx, operand);
|
||||
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
|
||||
}
|
||||
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
|
||||
Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let from_ty = operand.layout().ty;
|
||||
let to_ty = fx.monomorphize(to_ty);
|
||||
@ -577,12 +577,12 @@ fn codegen_stmt<'tcx>(
|
||||
|
||||
use rustc_target::abi::{Int, TagEncoding, Variants};
|
||||
|
||||
match &operand.layout().variants {
|
||||
match operand.layout().variants {
|
||||
Variants::Single { index } => {
|
||||
let discr = operand
|
||||
.layout()
|
||||
.ty
|
||||
.discriminant_for_variant(fx.tcx, *index)
|
||||
.discriminant_for_variant(fx.tcx, index)
|
||||
.unwrap();
|
||||
let discr = if discr.ty.is_signed() {
|
||||
fx.layout_of(discr.ty).size.sign_extend(discr.val)
|
||||
@ -595,7 +595,7 @@ fn codegen_stmt<'tcx>(
|
||||
lval.write_cvalue(fx, discr);
|
||||
}
|
||||
Variants::Multiple {
|
||||
tag,
|
||||
ref tag,
|
||||
tag_field,
|
||||
tag_encoding: TagEncoding::Direct,
|
||||
variants: _,
|
||||
@ -604,7 +604,7 @@ fn codegen_stmt<'tcx>(
|
||||
|
||||
// Read the tag/niche-encoded discriminant from memory.
|
||||
let encoded_discr =
|
||||
operand.value_field(fx, mir::Field::new(*tag_field));
|
||||
operand.value_field(fx, mir::Field::new(tag_field));
|
||||
let encoded_discr = encoded_discr.load_scalar(fx);
|
||||
|
||||
// Decode the discriminant (specifically if it's niche-encoded).
|
||||
@ -634,7 +634,7 @@ fn codegen_stmt<'tcx>(
|
||||
}
|
||||
Rvalue::Cast(
|
||||
CastKind::Pointer(PointerCast::ClosureFnPointer(_)),
|
||||
operand,
|
||||
ref operand,
|
||||
_to_ty,
|
||||
) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
@ -654,18 +654,18 @@ fn codegen_stmt<'tcx>(
|
||||
_ => bug!("{} cannot be cast to a fn ptr", operand.layout().ty),
|
||||
}
|
||||
}
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), ref operand, _to_ty) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
operand.unsize_value(fx, lval);
|
||||
}
|
||||
Rvalue::Discriminant(place) => {
|
||||
let place = codegen_place(fx, *place);
|
||||
let place = codegen_place(fx, place);
|
||||
let value = place.to_cvalue(fx);
|
||||
let discr =
|
||||
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
|
||||
lval.write_cvalue(fx, discr);
|
||||
}
|
||||
Rvalue::Repeat(operand, times) => {
|
||||
Rvalue::Repeat(ref operand, times) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let times = fx
|
||||
.monomorphize(times)
|
||||
@ -704,7 +704,7 @@ fn codegen_stmt<'tcx>(
|
||||
}
|
||||
}
|
||||
Rvalue::Len(place) => {
|
||||
let place = codegen_place(fx, *place);
|
||||
let place = codegen_place(fx, place);
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
let len = codegen_array_len(fx, place);
|
||||
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
||||
@ -749,7 +749,7 @@ fn codegen_stmt<'tcx>(
|
||||
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
Rvalue::Aggregate(kind, operands) => match **kind {
|
||||
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
|
||||
AggregateKind::Array(_ty) => {
|
||||
for (i, operand) in operands.iter().enumerate() {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
@ -877,8 +877,7 @@ fn codegen_array_len<'tcx>(
|
||||
match *place.layout().ty.kind() {
|
||||
ty::Array(_elem_ty, len) => {
|
||||
let len = fx
|
||||
.monomorphize(&len)
|
||||
.eval(fx.tcx, ParamEnv::reveal_all())
|
||||
.monomorphize(len)
|
||||
.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
|
||||
fx.bcx.ins().iconst(fx.pointer_type, len)
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ impl<'tcx, M: Module> HasTargetSpec for FunctionCx<'_, 'tcx, M> {
|
||||
}
|
||||
|
||||
impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
|
||||
pub(crate) fn monomorphize<T>(&self, value: &T) -> T
|
||||
pub(crate) fn monomorphize<T>(&self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx> + Copy,
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ impl ConstantCx {
|
||||
|
||||
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||
for constant in &fx.mir.required_consts {
|
||||
let const_ = fx.monomorphize(&constant.literal);
|
||||
let const_ = fx.monomorphize(constant.literal);
|
||||
match const_.val {
|
||||
ConstKind::Value(_) => {}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
@ -110,7 +110,7 @@ pub(crate) fn codegen_constant<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
constant: &Constant<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let const_ = fx.monomorphize(&constant.literal);
|
||||
let const_ = fx.monomorphize(constant.literal);
|
||||
let const_val = match const_.val {
|
||||
ConstKind::Value(const_val) => const_val,
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
|
||||
@ -466,7 +466,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
||||
match operand {
|
||||
Operand::Copy(_) | Operand::Move(_) => None,
|
||||
Operand::Constant(const_) => Some(
|
||||
fx.monomorphize(&const_.literal)
|
||||
fx.monomorphize(const_.literal)
|
||||
.eval(fx.tcx, ParamEnv::reveal_all()),
|
||||
),
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
let ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&mir.local_decls[local].ty,
|
||||
mir.local_decls[local].ty,
|
||||
);
|
||||
let var_id = self.define_local(entry_id, format!("{:?}", local), ty);
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
// late-bound regions, since late-bound
|
||||
// regions must appear in the argument
|
||||
// listing.
|
||||
let main_ret_ty = tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap());
|
||||
let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
|
||||
|
||||
let cmain_sig = Signature {
|
||||
params: vec![
|
||||
|
@ -80,7 +80,7 @@ impl CommentWriter {
|
||||
"sig {:?}",
|
||||
tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&crate::abi::fn_sig_for_fn_abi(tcx, instance)
|
||||
crate::abi::fn_sig_for_fn_abi(tcx, instance)
|
||||
)
|
||||
),
|
||||
String::new(),
|
||||
|
@ -455,7 +455,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
from_ty: Ty<'tcx>,
|
||||
to_ty: Ty<'tcx>,
|
||||
) {
|
||||
match (&from_ty.kind(), &to_ty.kind()) {
|
||||
match (from_ty.kind(), to_ty.kind()) {
|
||||
(ty::Ref(_, a, _), ty::Ref(_, b, _))
|
||||
| (
|
||||
ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
|
||||
@ -466,11 +466,11 @@ impl<'tcx> CPlace<'tcx> {
|
||||
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
||||
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&from_ty.fn_sig(fx.tcx),
|
||||
from_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
let to_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&to_ty.fn_sig(fx.tcx),
|
||||
to_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(
|
||||
from_sig, to_sig,
|
||||
@ -479,7 +479,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
);
|
||||
// fn(&T) -> for<'l> fn(&'l T) is allowed
|
||||
}
|
||||
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => {
|
||||
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
|
||||
let from_traits = fx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
|
||||
|
@ -92,7 +92,7 @@ fn make_mir_scope(
|
||||
let callee = cx.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&callee,
|
||||
callee,
|
||||
);
|
||||
let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]);
|
||||
cx.dbg_scope_fn(callee, &callee_fn_abi, None)
|
||||
|
@ -189,7 +189,7 @@ impl TypeMap<'ll, 'tcx> {
|
||||
// something that provides more than the 64 bits of the DefaultHasher.
|
||||
let mut hasher = StableHasher::new();
|
||||
let mut hcx = cx.tcx.create_stable_hashing_context();
|
||||
let type_ = cx.tcx.erase_regions(&type_);
|
||||
let type_ = cx.tcx.erase_regions(type_);
|
||||
hcx.while_hashing_spans(false, |hcx| {
|
||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||
type_.hash_stable(hcx, &mut hasher);
|
||||
@ -427,7 +427,7 @@ fn subroutine_type_metadata(
|
||||
span: Span,
|
||||
) -> MetadataCreationResult<'ll> {
|
||||
let signature =
|
||||
cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &signature);
|
||||
cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), signature);
|
||||
|
||||
let signature_metadata: Vec<_> = iter::once(
|
||||
// return type
|
||||
|
@ -501,7 +501,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&cx.tcx.type_of(impl_def_id),
|
||||
cx.tcx.type_of(impl_def_id),
|
||||
);
|
||||
|
||||
// Only "class" methods are generally understood by LLVM,
|
||||
|
@ -91,7 +91,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
};
|
||||
|
||||
let sig = callee_ty.fn_sig(tcx);
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
|
||||
let arg_tys = sig.inputs();
|
||||
let ret_ty = sig.output();
|
||||
let name = tcx.item_name(def_id);
|
||||
@ -777,8 +777,8 @@ fn generic_simd_intrinsic(
|
||||
}
|
||||
|
||||
let tcx = bx.tcx();
|
||||
let sig = tcx
|
||||
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &callee_ty.fn_sig(tcx));
|
||||
let sig =
|
||||
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
|
||||
let arg_tys = sig.inputs();
|
||||
let name_str = &*name.as_str();
|
||||
|
||||
|
@ -252,7 +252,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
||||
|
||||
// Make sure lifetimes are erased, to avoid generating distinct LLVM
|
||||
// types for Rust types that only differ in the choice of lifetimes.
|
||||
let normal_ty = cx.tcx.erase_regions(&self.ty);
|
||||
let normal_ty = cx.tcx.erase_regions(self.ty);
|
||||
|
||||
let mut defer = None;
|
||||
let llty = if self.ty != normal_ty {
|
||||
|
@ -399,7 +399,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// late-bound regions, since late-bound
|
||||
// regions must appear in the argument
|
||||
// listing.
|
||||
let main_ret_ty = cx.tcx().erase_regions(&main_ret_ty.no_bound_vars().unwrap());
|
||||
let main_ret_ty = cx.tcx().erase_regions(main_ret_ty.no_bound_vars().unwrap());
|
||||
|
||||
let llfn = match cx.declare_c_main(llfty) {
|
||||
Some(llfn) => llfn,
|
||||
|
@ -120,8 +120,8 @@ pub fn push_debuginfo_type_name<'tcx>(
|
||||
}
|
||||
ty::Dynamic(ref trait_data, ..) => {
|
||||
if let Some(principal) = trait_data.principal() {
|
||||
let principal = tcx
|
||||
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &principal);
|
||||
let principal =
|
||||
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
|
||||
push_item_name(tcx, principal.def_id, false, output);
|
||||
push_type_params(tcx, principal.substs, output, visited);
|
||||
} else {
|
||||
@ -159,7 +159,7 @@ pub fn push_debuginfo_type_name<'tcx>(
|
||||
|
||||
output.push_str("fn(");
|
||||
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
|
||||
if !sig.inputs().is_empty() {
|
||||
for ¶meter_type in sig.inputs() {
|
||||
push_debuginfo_type_name(tcx, parameter_type, true, output, visited);
|
||||
|
@ -24,7 +24,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
analyzer.visit_body(&mir);
|
||||
|
||||
for (local, decl) in mir.local_decls.iter_enumerated() {
|
||||
let ty = fx.monomorphize(&decl.ty);
|
||||
let ty = fx.monomorphize(decl.ty);
|
||||
debug!("local {:?} has type `{}`", local, ty);
|
||||
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
|
||||
if fx.cx.is_backend_immediate(layout) {
|
||||
@ -121,10 +121,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
|
||||
if is_consume {
|
||||
let base_ty =
|
||||
mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx());
|
||||
let base_ty = self.fx.monomorphize(&base_ty);
|
||||
let base_ty = self.fx.monomorphize(base_ty);
|
||||
|
||||
// ZSTs don't require any actual memory access.
|
||||
let elem_ty = base_ty.projection_ty(cx.tcx(), self.fx.monomorphize(&elem)).ty;
|
||||
let elem_ty = base_ty.projection_ty(cx.tcx(), self.fx.monomorphize(elem)).ty;
|
||||
let span = self.fx.mir.local_decls[place_ref.local].source_info.span;
|
||||
if cx.spanned_layout_of(elem_ty, span).is_zst() {
|
||||
return;
|
||||
@ -313,7 +313,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
|
||||
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
|
||||
let ty = self.fx.mir.local_decls[local].ty;
|
||||
let ty = self.fx.monomorphize(&ty);
|
||||
let ty = self.fx.monomorphize(ty);
|
||||
|
||||
// Only need the place if we're actually dropping it.
|
||||
if self.fx.cx.type_needs_drop(ty) {
|
||||
|
@ -306,7 +306,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
unwind: Option<mir::BasicBlock>,
|
||||
) {
|
||||
let ty = location.ty(self.mir, bx.tcx()).ty;
|
||||
let ty = self.monomorphize(&ty);
|
||||
let ty = self.monomorphize(ty);
|
||||
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
|
||||
|
||||
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
|
||||
@ -576,7 +576,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
.iter()
|
||||
.map(|op_arg| {
|
||||
let op_ty = op_arg.ty(self.mir, bx.tcx());
|
||||
self.monomorphize(&op_ty)
|
||||
self.monomorphize(op_ty)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -900,7 +900,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
}
|
||||
mir::InlineAsmOperand::SymFn { ref value } => {
|
||||
let literal = self.monomorphize(&value.literal);
|
||||
let literal = self.monomorphize(value.literal);
|
||||
if let ty::FnDef(def_id, substs) = *literal.ty.kind() {
|
||||
let instance = ty::Instance::resolve_for_fn_ptr(
|
||||
bx.tcx(),
|
||||
|
@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
constant: &mir::Constant<'tcx>,
|
||||
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
|
||||
let val = self.eval_mir_constant(constant)?;
|
||||
let ty = self.monomorphize(&constant.literal.ty);
|
||||
let ty = self.monomorphize(constant.literal.ty);
|
||||
Ok(OperandRef::from_const(bx, val, ty))
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
&mut self,
|
||||
constant: &mir::Constant<'tcx>,
|
||||
) -> Result<ConstValue<'tcx>, ErrorHandled> {
|
||||
match self.monomorphize(&constant.literal).val {
|
||||
match self.monomorphize(constant.literal).val {
|
||||
ty::ConstKind::Unevaluated(def, substs, promoted) => self
|
||||
.cx
|
||||
.tcx()
|
||||
@ -83,7 +83,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
.unwrap_or_else(|_| {
|
||||
bx.tcx().sess.span_err(span, "could not evaluate shuffle_indices at compile time");
|
||||
// We've errored, so we don't have to produce working code.
|
||||
let ty = self.monomorphize(&ty);
|
||||
let ty = self.monomorphize(ty);
|
||||
let llty = bx.backend_type(bx.layout_of(ty));
|
||||
(bx.const_undef(llty), ty)
|
||||
})
|
||||
|
@ -160,7 +160,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
// FIXME(eddyb) is this `+ 1` needed at all?
|
||||
let kind = VariableKind::ArgumentVariable(arg_index + 1);
|
||||
|
||||
let arg_ty = self.monomorphize(&decl.ty);
|
||||
let arg_ty = self.monomorphize(decl.ty);
|
||||
|
||||
self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span)
|
||||
},
|
||||
|
@ -64,7 +64,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
};
|
||||
|
||||
let sig = callee_ty.fn_sig(bx.tcx());
|
||||
let sig = bx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
|
||||
let sig = bx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
|
||||
let arg_tys = sig.inputs();
|
||||
let ret_ty = sig.output();
|
||||
let name = bx.tcx().item_name(def_id);
|
||||
|
@ -87,7 +87,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
pub fn monomorphize<T>(&self, value: &T) -> T
|
||||
pub fn monomorphize<T>(&self, value: T) -> T
|
||||
where
|
||||
T: Copy + TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -208,7 +208,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
|
||||
let mut allocate_local = |local| {
|
||||
let decl = &mir.local_decls[local];
|
||||
let layout = bx.layout_of(fx.monomorphize(&decl.ty));
|
||||
let layout = bx.layout_of(fx.monomorphize(decl.ty));
|
||||
assert!(!layout.ty.has_erasable_regions());
|
||||
|
||||
if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() {
|
||||
@ -364,7 +364,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// to reconstruct it into a tuple local variable, from multiple
|
||||
// individual LLVM function arguments.
|
||||
|
||||
let arg_ty = fx.monomorphize(&arg_decl.ty);
|
||||
let arg_ty = fx.monomorphize(arg_decl.ty);
|
||||
let tupled_arg_tys = match arg_ty.kind() {
|
||||
ty::Tuple(tys) => tys,
|
||||
_ => bug!("spread argument isn't a tuple?!"),
|
||||
@ -385,7 +385,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
}
|
||||
|
||||
if fx.fn_abi.c_variadic && arg_index == fx.fn_abi.args.len() {
|
||||
let arg_ty = fx.monomorphize(&arg_decl.ty);
|
||||
let arg_ty = fx.monomorphize(arg_decl.ty);
|
||||
|
||||
let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
|
||||
bx.va_start(va_list.llval);
|
||||
|
@ -452,7 +452,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
bx.abort();
|
||||
// We still have to return an operand but it doesn't matter,
|
||||
// this code is unreachable.
|
||||
let ty = self.monomorphize(&constant.literal.ty);
|
||||
let ty = self.monomorphize(constant.literal.ty);
|
||||
let layout = bx.cx().layout_of(ty);
|
||||
bx.load_operand(PlaceRef::new_sized(
|
||||
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))),
|
||||
|
@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
cg_base.project_index(bx, bx.cx().const_usize(from as u64));
|
||||
let projected_ty =
|
||||
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem).ty;
|
||||
subslice.layout = bx.cx().layout_of(self.monomorphize(&projected_ty));
|
||||
subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty));
|
||||
|
||||
if subslice.layout.is_unsized() {
|
||||
assert!(from_end, "slice subslices should be `from_end`");
|
||||
@ -515,6 +515,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> {
|
||||
let tcx = self.cx.tcx();
|
||||
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, self.mir, tcx);
|
||||
self.monomorphize(&place_ty.ty)
|
||||
self.monomorphize(place_ty.ty)
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
|
||||
let count =
|
||||
self.monomorphize(&count).eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
|
||||
self.monomorphize(count).eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
|
||||
|
||||
bx.write_operand_repeatedly(cg_elem, count, dest)
|
||||
}
|
||||
@ -181,7 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => {
|
||||
let operand = self.codegen_operand(&mut bx, source);
|
||||
debug!("cast operand is {:?}", operand);
|
||||
let cast = bx.cx().layout_of(self.monomorphize(&mir_cast_ty));
|
||||
let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty));
|
||||
|
||||
let val = match *kind {
|
||||
mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => {
|
||||
@ -502,7 +502,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
|
||||
mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => {
|
||||
let ty = self.monomorphize(&ty);
|
||||
let ty = self.monomorphize(ty);
|
||||
assert!(bx.cx().type_is_sized(ty));
|
||||
let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes());
|
||||
let tcx = self.cx.tcx();
|
||||
@ -516,7 +516,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
|
||||
mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => {
|
||||
let content_ty = self.monomorphize(&content_ty);
|
||||
let content_ty = self.monomorphize(content_ty);
|
||||
let content_layout = bx.cx().layout_of(content_ty);
|
||||
let llsize = bx.cx().const_usize(content_layout.size.bytes());
|
||||
let llalign = bx.cx().const_usize(content_layout.align.abi.bytes());
|
||||
@ -554,7 +554,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
// aggregate rvalues are allowed to be operands.
|
||||
let ty = rvalue.ty(self.mir, self.cx.tcx());
|
||||
let operand =
|
||||
OperandRef::new_zst(&mut bx, self.cx.layout_of(self.monomorphize(&ty)));
|
||||
OperandRef::new_zst(&mut bx, self.cx.layout_of(self.monomorphize(ty)));
|
||||
(bx, operand)
|
||||
}
|
||||
}
|
||||
@ -774,7 +774,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
mir::Rvalue::Repeat(..) |
|
||||
mir::Rvalue::Aggregate(..) => {
|
||||
let ty = rvalue.ty(self.mir, self.cx.tcx());
|
||||
let ty = self.monomorphize(&ty);
|
||||
let ty = self.monomorphize(ty);
|
||||
self.cx.spanned_layout_of(ty, span).is_zst()
|
||||
}
|
||||
}
|
||||
|
82
compiler/rustc_data_structures/src/functor.rs
Normal file
82
compiler/rustc_data_structures/src/functor.rs
Normal file
@ -0,0 +1,82 @@
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
pub trait IdFunctor {
|
||||
type Inner;
|
||||
|
||||
fn map_id<F>(self, f: F) -> Self
|
||||
where
|
||||
F: FnMut(Self::Inner) -> Self::Inner;
|
||||
}
|
||||
|
||||
impl<T> IdFunctor for Box<T> {
|
||||
type Inner = T;
|
||||
|
||||
#[inline]
|
||||
fn map_id<F>(self, mut f: F) -> Self
|
||||
where
|
||||
F: FnMut(Self::Inner) -> Self::Inner,
|
||||
{
|
||||
let raw = Box::into_raw(self);
|
||||
unsafe {
|
||||
// SAFETY: The raw pointer points to a valid value of type `T`.
|
||||
let value = ptr::read(raw);
|
||||
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
|
||||
// inverse of `Box::assume_init()` and should be safe.
|
||||
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
|
||||
// SAFETY: Write the mapped value back into the `Box`.
|
||||
ptr::write(raw.as_mut_ptr(), f(value));
|
||||
// SAFETY: We just initialized `raw`.
|
||||
raw.assume_init()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IdFunctor for Vec<T> {
|
||||
type Inner = T;
|
||||
|
||||
#[inline]
|
||||
fn map_id<F>(mut self, mut f: F) -> Self
|
||||
where
|
||||
F: FnMut(Self::Inner) -> Self::Inner,
|
||||
{
|
||||
// FIXME: We don't really care about panics here and leak
|
||||
// far more than we should, but that should be fine for now.
|
||||
let len = self.len();
|
||||
unsafe {
|
||||
self.set_len(0);
|
||||
let start = self.as_mut_ptr();
|
||||
for i in 0..len {
|
||||
let p = start.add(i);
|
||||
ptr::write(p, f(ptr::read(p)));
|
||||
}
|
||||
self.set_len(len);
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IdFunctor for Box<[T]> {
|
||||
type Inner = T;
|
||||
|
||||
#[inline]
|
||||
fn map_id<F>(self, f: F) -> Self
|
||||
where
|
||||
F: FnMut(Self::Inner) -> Self::Inner,
|
||||
{
|
||||
Vec::from(self).map_id(f).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Idx, T> IdFunctor for IndexVec<I, T> {
|
||||
type Inner = T;
|
||||
|
||||
#[inline]
|
||||
fn map_id<F>(self, f: F) -> Self
|
||||
where
|
||||
F: FnMut(Self::Inner) -> Self::Inner,
|
||||
{
|
||||
IndexVec::from_raw(self.raw.map_id(f))
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#![feature(extend_one)]
|
||||
#![feature(const_panic)]
|
||||
#![feature(min_const_generics)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(once_cell)]
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
#![allow(rustc::default_hash_types)]
|
||||
@ -70,6 +71,7 @@ pub mod box_region;
|
||||
pub mod captures;
|
||||
pub mod const_cstr;
|
||||
pub mod flock;
|
||||
pub mod functor;
|
||||
pub mod fx;
|
||||
pub mod graph;
|
||||
pub mod jobserver;
|
||||
|
@ -38,7 +38,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query
|
||||
pub fn canonicalize_query<V>(
|
||||
&self,
|
||||
value: &V,
|
||||
value: V,
|
||||
query_state: &mut OriginalQueryValues<'tcx>,
|
||||
) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
@ -80,7 +80,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
/// out the [chapter in the rustc dev guide][c].
|
||||
///
|
||||
/// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query-result
|
||||
pub fn canonicalize_response<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||
pub fn canonicalize_response<V>(&self, value: V) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -94,7 +94,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn canonicalize_user_type_annotation<V>(&self, value: &V) -> Canonicalized<'tcx, V>
|
||||
pub fn canonicalize_user_type_annotation<V>(&self, value: V) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -123,7 +123,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
// and just use `canonicalize_query`.
|
||||
pub fn canonicalize_hr_query_hack<V>(
|
||||
&self,
|
||||
value: &V,
|
||||
value: V,
|
||||
query_state: &mut OriginalQueryValues<'tcx>,
|
||||
) -> Canonicalized<'tcx, V>
|
||||
where
|
||||
@ -293,7 +293,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
|
||||
fn fold_binder<T>(&mut self, t: ty::Binder<T>) -> ty::Binder<T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -479,7 +479,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
||||
/// The main `canonicalize` method, shared impl of
|
||||
/// `canonicalize_query` and `canonicalize_response`.
|
||||
fn canonicalize<V>(
|
||||
value: &V,
|
||||
value: V,
|
||||
infcx: Option<&InferCtxt<'_, 'tcx>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
canonicalize_region_mode: &dyn CanonicalizeRegionMode,
|
||||
|
@ -59,7 +59,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
|
||||
{
|
||||
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
|
||||
let canonical_result = self.canonicalize_response(&query_response);
|
||||
let canonical_result = self.canonicalize_response(query_response);
|
||||
|
||||
debug!("make_canonicalized_query_response: canonical_result = {:#?}", canonical_result);
|
||||
|
||||
@ -83,7 +83,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
where
|
||||
T: Debug + TypeFoldable<'tcx>,
|
||||
{
|
||||
self.canonicalize_response(&QueryResponse {
|
||||
self.canonicalize_response(QueryResponse {
|
||||
var_values: inference_vars,
|
||||
region_constraints: QueryRegionConstraints::default(),
|
||||
certainty: Certainty::Proven, // Ambiguities are OK!
|
||||
@ -176,7 +176,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
));
|
||||
|
||||
let user_result: R =
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone());
|
||||
|
||||
Ok(InferOk { value: user_result, obligations })
|
||||
}
|
||||
@ -238,7 +238,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
for (index, original_value) in original_values.var_values.iter().enumerate() {
|
||||
// ...with the value `v_r` of that variable from the query.
|
||||
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
|
||||
&v.var_values[BoundVar::new(index)]
|
||||
v.var_values[BoundVar::new(index)]
|
||||
});
|
||||
match (original_value.unpack(), result_value.unpack()) {
|
||||
(
|
||||
@ -296,7 +296,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
|
||||
// ...also include the other query region constraints from the query.
|
||||
output_query_region_constraints.outlives.extend(
|
||||
query_response.value.region_constraints.outlives.iter().filter_map(|r_c| {
|
||||
query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| {
|
||||
let r_c = substitute_value(self.tcx, &result_subst, r_c);
|
||||
|
||||
// Screen out `'a: 'a` cases -- we skip the binder here but
|
||||
@ -314,11 +314,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
.region_constraints
|
||||
.member_constraints
|
||||
.iter()
|
||||
.map(|p_c| substitute_value(self.tcx, &result_subst, p_c)),
|
||||
.map(|p_c| substitute_value(self.tcx, &result_subst, p_c.clone())),
|
||||
);
|
||||
|
||||
let user_result: R =
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone());
|
||||
|
||||
Ok(InferOk { value: user_result, obligations })
|
||||
}
|
||||
@ -502,7 +502,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
// `query_response.var_values` after applying the substitution
|
||||
// `result_subst`.
|
||||
let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> {
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
|
||||
query_response.substitute_projected(self.tcx, &result_subst, |v| v.var_values[index])
|
||||
};
|
||||
|
||||
// Unify the original value for each variable with the value
|
||||
@ -524,7 +524,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
unsubstituted_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
|
||||
result_subst: &'a CanonicalVarValues<'tcx>,
|
||||
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
|
||||
unsubstituted_region_constraints.iter().map(move |constraint| {
|
||||
unsubstituted_region_constraints.iter().map(move |&constraint| {
|
||||
let ty::OutlivesPredicate(k1, r2) =
|
||||
substitute_value(self.tcx, result_subst, constraint).skip_binder();
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub(super) trait CanonicalExt<'tcx, V> {
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
projection_fn: impl FnOnce(&V) -> &T,
|
||||
projection_fn: impl FnOnce(&V) -> T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>;
|
||||
@ -39,14 +39,14 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
||||
where
|
||||
V: TypeFoldable<'tcx>,
|
||||
{
|
||||
self.substitute_projected(tcx, var_values, |value| value)
|
||||
self.substitute_projected(tcx, var_values, |value| value.clone())
|
||||
}
|
||||
|
||||
fn substitute_projected<T>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
projection_fn: impl FnOnce(&V) -> &T,
|
||||
projection_fn: impl FnOnce(&V) -> T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -60,16 +60,16 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
||||
/// Substitute the values from `var_values` into `value`. `var_values`
|
||||
/// must be values for the set of canonical variables that appear in
|
||||
/// `value`.
|
||||
pub(super) fn substitute_value<'a, 'tcx, T>(
|
||||
pub(super) fn substitute_value<'tcx, T>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
value: &'a T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
if var_values.var_values.is_empty() {
|
||||
value.clone()
|
||||
value
|
||||
} else {
|
||||
let fld_r =
|
||||
|br: ty::BoundRegion| match var_values.var_values[br.assert_bound_var()].unpack() {
|
||||
|
@ -389,7 +389,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
member_region,
|
||||
span,
|
||||
} => {
|
||||
let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
|
||||
let hidden_ty = self.resolve_vars_if_possible(hidden_ty);
|
||||
unexpected_hidden_region_diagnostic(
|
||||
self.tcx,
|
||||
span,
|
||||
@ -590,7 +590,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
) {
|
||||
match cause.code {
|
||||
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
|
||||
let ty = self.resolve_vars_if_possible(&root_ty);
|
||||
let ty = self.resolve_vars_if_possible(root_ty);
|
||||
if ty.is_suggestable() {
|
||||
// don't show type `_`
|
||||
err.span_label(span, format!("this expression has type `{}`", ty));
|
||||
@ -661,7 +661,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
_ => {
|
||||
// `last_ty` can be `!`, `expected` will have better info when present.
|
||||
let t = self.resolve_vars_if_possible(&match exp_found {
|
||||
let t = self.resolve_vars_if_possible(match exp_found {
|
||||
Some(ty::error::ExpectedFound { expected, .. }) => expected,
|
||||
_ => last_ty,
|
||||
});
|
||||
@ -1547,7 +1547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
||||
_ => (false, Mismatch::Fixed("type")),
|
||||
};
|
||||
let vals = match self.values_str(&values) {
|
||||
let vals = match self.values_str(values) {
|
||||
Some((expected, found)) => Some((expected, found)),
|
||||
None => {
|
||||
// Derived error. Cancel the emitter.
|
||||
@ -1893,32 +1893,32 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
fn values_str(
|
||||
&self,
|
||||
values: &ValuePairs<'tcx>,
|
||||
values: ValuePairs<'tcx>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
match *values {
|
||||
infer::Types(ref exp_found) => self.expected_found_str_ty(exp_found),
|
||||
infer::Regions(ref exp_found) => self.expected_found_str(exp_found),
|
||||
infer::Consts(ref exp_found) => self.expected_found_str(exp_found),
|
||||
infer::TraitRefs(ref exp_found) => {
|
||||
match values {
|
||||
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
|
||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||
infer::Consts(exp_found) => self.expected_found_str(exp_found),
|
||||
infer::TraitRefs(exp_found) => {
|
||||
let pretty_exp_found = ty::error::ExpectedFound {
|
||||
expected: exp_found.expected.print_only_trait_path(),
|
||||
found: exp_found.found.print_only_trait_path(),
|
||||
};
|
||||
self.expected_found_str(&pretty_exp_found)
|
||||
self.expected_found_str(pretty_exp_found)
|
||||
}
|
||||
infer::PolyTraitRefs(ref exp_found) => {
|
||||
infer::PolyTraitRefs(exp_found) => {
|
||||
let pretty_exp_found = ty::error::ExpectedFound {
|
||||
expected: exp_found.expected.print_only_trait_path(),
|
||||
found: exp_found.found.print_only_trait_path(),
|
||||
};
|
||||
self.expected_found_str(&pretty_exp_found)
|
||||
self.expected_found_str(pretty_exp_found)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn expected_found_str_ty(
|
||||
&self,
|
||||
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
|
||||
exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
@ -1931,7 +1931,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// Returns a string of the form "expected `{}`, found `{}`".
|
||||
fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
exp_found: &ty::error::ExpectedFound<T>,
|
||||
exp_found: ty::error::ExpectedFound<T>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
@ -2180,7 +2180,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
"...",
|
||||
);
|
||||
if let Some(infer::RelateParamBound(_, t)) = origin {
|
||||
let t = self.resolve_vars_if_possible(&t);
|
||||
let t = self.resolve_vars_if_possible(t);
|
||||
match t.kind() {
|
||||
// We've got:
|
||||
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
|
||||
@ -2237,7 +2237,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values);
|
||||
|
||||
if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) =
|
||||
(self.values_str(&sup_trace.values), self.values_str(&sub_trace.values))
|
||||
(self.values_str(sup_trace.values), self.values_str(sub_trace.values))
|
||||
{
|
||||
if sub_expected == sup_expected && sub_found == sup_found {
|
||||
note_and_explain_region(
|
||||
|
@ -49,7 +49,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
|
||||
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
|
||||
match ty_opt {
|
||||
Some(ty) => {
|
||||
let ty = self.infcx.resolve_vars_if_possible(&ty);
|
||||
let ty = self.infcx.resolve_vars_if_possible(ty);
|
||||
if ty.walk().any(|inner| {
|
||||
inner == self.target
|
||||
|| match (inner.unpack(), self.target.unpack()) {
|
||||
@ -343,7 +343,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
arg: GenericArg<'tcx>,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let arg = self.resolve_vars_if_possible(&arg);
|
||||
let arg = self.resolve_vars_if_possible(arg);
|
||||
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
||||
let kind_str = match arg.unpack() {
|
||||
GenericArgKind::Type(_) => "type",
|
||||
@ -686,7 +686,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
span: Span,
|
||||
ty: Ty<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
let data = self.extract_inference_diagnostics_data(ty.into(), None);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
|
@ -234,14 +234,13 @@ impl NiceRegionError<'me, 'tcx> {
|
||||
false
|
||||
};
|
||||
|
||||
let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
|
||||
let expected_trait_ref = self.infcx.resolve_vars_if_possible(ty::TraitRef {
|
||||
def_id: trait_def_id,
|
||||
substs: expected_substs,
|
||||
});
|
||||
let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
|
||||
def_id: trait_def_id,
|
||||
substs: actual_substs,
|
||||
});
|
||||
let actual_trait_ref = self
|
||||
.infcx
|
||||
.resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs });
|
||||
|
||||
// Search the expected and actual trait references to see (a)
|
||||
// whether the sub/sup placeholders appear in them (sometimes
|
||||
|
@ -414,7 +414,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
tcx,
|
||||
ctxt.param_env,
|
||||
ctxt.assoc_item.def_id,
|
||||
self.infcx.resolve_vars_if_possible(&ctxt.substs),
|
||||
self.infcx.resolve_vars_if_possible(ctxt.substs),
|
||||
) {
|
||||
Ok(Some(instance)) => instance,
|
||||
_ => return false,
|
||||
|
@ -86,7 +86,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
}
|
||||
|
||||
if let Some((expected, found)) =
|
||||
self.infcx.expected_found_str_ty(&ExpectedFound { expected, found })
|
||||
self.infcx.expected_found_str_ty(ExpectedFound { expected, found })
|
||||
{
|
||||
// Highlighted the differences when showing the "expected/found" note.
|
||||
err.note_expected_found(&"", expected, &"", found);
|
||||
|
@ -55,12 +55,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
let owner_id = hir.body_owner(body_id);
|
||||
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
|
||||
let poly_fn_sig = self.tcx().fn_sig(id);
|
||||
let fn_sig = self.tcx().liberate_late_bound_regions(id, &poly_fn_sig);
|
||||
let fn_sig = self.tcx().liberate_late_bound_regions(id, poly_fn_sig);
|
||||
body.params.iter().enumerate().find_map(|(index, param)| {
|
||||
// May return None; sometimes the tables are not yet populated.
|
||||
let ty = fn_sig.inputs()[index];
|
||||
let mut found_anon_region = false;
|
||||
let new_param_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
|
||||
let new_param_ty = self.tcx().fold_regions(ty, &mut false, |r, _| {
|
||||
if *r == *anon_region {
|
||||
found_anon_region = true;
|
||||
replace_region
|
||||
|
@ -24,7 +24,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
};
|
||||
match *origin {
|
||||
infer::Subtype(ref trace) => {
|
||||
if let Some((expected, found)) = self.values_str(&trace.values) {
|
||||
if let Some((expected, found)) = self.values_str(trace.values) {
|
||||
label_or_note(
|
||||
trace.cause.span,
|
||||
&format!("...so that the {}", trace.cause.as_requirement_str()),
|
||||
|
@ -105,7 +105,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
let (mut fudger, value) = self.probe(|_| {
|
||||
match f() {
|
||||
Ok(value) => {
|
||||
let value = self.resolve_vars_if_possible(&value);
|
||||
let value = self.resolve_vars_if_possible(value);
|
||||
|
||||
// At this point, `value` could in principle refer
|
||||
// to inference variables that have been created during
|
||||
|
@ -33,14 +33,14 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
|
||||
self.infcx.commit_if_ok(|_| {
|
||||
// First, we instantiate each bound region in the supertype with a
|
||||
// fresh placeholder region.
|
||||
let b_prime = self.infcx.replace_bound_vars_with_placeholders(&b);
|
||||
let b_prime = self.infcx.replace_bound_vars_with_placeholders(b);
|
||||
|
||||
// Next, we instantiate each bound region in the subtype
|
||||
// with a fresh region variable. These region variables --
|
||||
// but no other pre-existing region variables -- can name
|
||||
// the placeholders.
|
||||
let (a_prime, _) =
|
||||
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, &a);
|
||||
self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a);
|
||||
|
||||
debug!("a_prime={:?}", a_prime);
|
||||
debug!("b_prime={:?}", b_prime);
|
||||
@ -66,7 +66,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// the [rustc dev guide].
|
||||
///
|
||||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
|
||||
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: &ty::Binder<T>) -> T
|
||||
pub fn replace_bound_vars_with_placeholders<T>(&self, binder: ty::Binder<T>) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -113,10 +113,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
debug!(
|
||||
"replace_bound_vars_with_placeholders(\
|
||||
next_universe={:?}, \
|
||||
binder={:?}, \
|
||||
result={:?}, \
|
||||
map={:?})",
|
||||
next_universe, binder, result, map,
|
||||
next_universe, result, map,
|
||||
);
|
||||
|
||||
result
|
||||
|
@ -1001,7 +1001,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&value, &mut false, |r, _db| match r {
|
||||
tcx.fold_regions(value, &mut false, |r, _db| match r {
|
||||
ty::ReVar(rid) => self.resolve_var(*rid),
|
||||
_ => r,
|
||||
})
|
||||
|
@ -345,7 +345,7 @@ pub struct InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// See the `error_reporting` module for more details.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, TypeFoldable)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
|
||||
pub enum ValuePairs<'tcx> {
|
||||
Types(ExpectedFound<Ty<'tcx>>),
|
||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||
@ -955,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
Some(self.commit_if_ok(|_snapshot| {
|
||||
let ty::SubtypePredicate { a_is_expected, a, b } =
|
||||
self.replace_bound_vars_with_placeholders(&predicate);
|
||||
self.replace_bound_vars_with_placeholders(predicate);
|
||||
|
||||
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
|
||||
|
||||
@ -970,7 +970,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
) -> UnitResult<'tcx> {
|
||||
self.commit_if_ok(|_snapshot| {
|
||||
let ty::OutlivesPredicate(r_a, r_b) =
|
||||
self.replace_bound_vars_with_placeholders(&predicate);
|
||||
self.replace_bound_vars_with_placeholders(predicate);
|
||||
let origin = SubregionOrigin::from_obligation_cause(cause, || {
|
||||
RelateRegionParamBound(cause.span)
|
||||
});
|
||||
@ -1266,7 +1266,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
|
||||
self.resolve_vars_if_possible(&t).to_string()
|
||||
self.resolve_vars_if_possible(t).to_string()
|
||||
}
|
||||
|
||||
pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
|
||||
@ -1274,7 +1274,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
format!("({})", tstrs.join(", "))
|
||||
}
|
||||
|
||||
pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
|
||||
pub fn trait_ref_to_string(&self, t: ty::TraitRef<'tcx>) -> String {
|
||||
self.resolve_vars_if_possible(t).print_only_trait_path().to_string()
|
||||
}
|
||||
|
||||
@ -1314,7 +1314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// is left as is. This is an idempotent operation that does
|
||||
/// not affect inference state in any way and so you can do it
|
||||
/// at will.
|
||||
pub fn resolve_vars_if_possible<T>(&self, value: &T) -> T
|
||||
pub fn resolve_vars_if_possible<T>(&self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -1349,7 +1349,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
|
||||
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: T) -> FixupResult<'tcx, T> {
|
||||
/*!
|
||||
* Attempts to resolve all type/region/const variables in
|
||||
* `value`. Region inference must have been run already (e.g.,
|
||||
@ -1383,7 +1383,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
where
|
||||
M: FnOnce(String) -> DiagnosticBuilder<'tcx>,
|
||||
{
|
||||
let actual_ty = self.resolve_vars_if_possible(&actual_ty);
|
||||
let actual_ty = self.resolve_vars_if_possible(actual_ty);
|
||||
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
|
||||
|
||||
// Don't report an error if actual type is `Error`.
|
||||
@ -1420,7 +1420,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
span: Span,
|
||||
lbrct: LateBoundRegionConversionTime,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -1508,7 +1508,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
span: Option<Span>,
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
let mut original_values = OriginalQueryValues::default();
|
||||
let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values);
|
||||
let canonical = self.canonicalize_query((param_env, substs), &mut original_values);
|
||||
|
||||
let (param_env, substs) = canonical.value;
|
||||
// The return value is the evaluated value which doesn't contain any reference to inference
|
||||
|
@ -167,7 +167,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
sup_type, sub_region, origin
|
||||
);
|
||||
|
||||
let sup_type = self.resolve_vars_if_possible(&sup_type);
|
||||
let sup_type = self.resolve_vars_if_possible(sup_type);
|
||||
|
||||
if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
|
||||
let outlives = &mut TypeOutlives::new(
|
||||
@ -205,7 +205,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
implicit_region_bound,
|
||||
param_env,
|
||||
);
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
outlives.type_must_outlive(origin, ty, region);
|
||||
}
|
||||
}
|
||||
|
@ -124,10 +124,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
) -> Vec<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
|
||||
let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx);
|
||||
let erased_projection_ty = self.tcx.erase_regions(&projection_ty);
|
||||
let erased_projection_ty = self.tcx.erase_regions(projection_ty);
|
||||
self.declared_generic_bounds_from_env_with_compare_fn(|ty| {
|
||||
if let ty::Projection(..) = ty.kind() {
|
||||
let erased_ty = self.tcx.erase_regions(&ty);
|
||||
let erased_ty = self.tcx.erase_regions(ty);
|
||||
erased_ty == erased_projection_ty
|
||||
} else {
|
||||
false
|
||||
|
@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
|
||||
/// Full type resolution replaces all type and region variables with
|
||||
/// their concrete results. If any variable cannot be replaced (never unified, etc)
|
||||
/// then an `Err` result is returned.
|
||||
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: &T) -> FixupResult<'tcx, T>
|
||||
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: T) -> FixupResult<'tcx, T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -60,9 +60,9 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
|
||||
// TypeFoldable implementations.
|
||||
|
||||
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
traits::Obligation {
|
||||
cause: self.cause.clone(),
|
||||
cause: self.cause,
|
||||
recursion_depth: self.recursion_depth,
|
||||
predicate: self.predicate.fold_with(folder),
|
||||
param_env: self.param_env.fold_with(folder),
|
||||
|
@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pred: ty::Predicate<'tcx>,
|
||||
) -> ty::Predicate<'tcx> {
|
||||
match pred.kind() {
|
||||
match *pred.kind() {
|
||||
ty::PredicateKind::ForAll(binder) => {
|
||||
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
|
||||
tcx.reuse_or_mk_predicate(pred, new)
|
||||
|
@ -880,7 +880,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
return FfiSafe;
|
||||
}
|
||||
|
||||
match ty.kind() {
|
||||
match *ty.kind() {
|
||||
ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => {
|
||||
FfiSafe
|
||||
}
|
||||
@ -1044,7 +1044,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
};
|
||||
}
|
||||
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
if !sig.output().is_unit() {
|
||||
let r = self.check_type_for_ffi(cache, sig.output());
|
||||
match r {
|
||||
@ -1218,7 +1218,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) {
|
||||
let def_id = self.cx.tcx.hir().local_def_id(id);
|
||||
let sig = self.cx.tcx.fn_sig(def_id);
|
||||
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
|
||||
let sig = self.cx.tcx.erase_late_bound_regions(sig);
|
||||
|
||||
for (input_ty, input_hir) in sig.inputs().iter().zip(decl.inputs) {
|
||||
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false, false);
|
||||
@ -1295,7 +1295,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
||||
if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind {
|
||||
let item_def_id = cx.tcx.hir().local_def_id(it.hir_id);
|
||||
let t = cx.tcx.type_of(item_def_id);
|
||||
let ty = cx.tcx.erase_regions(&t);
|
||||
let ty = cx.tcx.erase_regions(t);
|
||||
let layout = match cx.layout_of(ty) {
|
||||
Ok(layout) => layout,
|
||||
Err(
|
||||
|
@ -6,6 +6,12 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
|
||||
}
|
||||
|
||||
s.add_bounds(synstructure::AddBounds::Generics);
|
||||
let body_visit = s.each(|bind| {
|
||||
quote! {
|
||||
::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?;
|
||||
}
|
||||
});
|
||||
s.bind_with(|_| synstructure::BindStyle::Move);
|
||||
let body_fold = s.each_variant(|vi| {
|
||||
let bindings = vi.bindings();
|
||||
vi.construct(|_, index| {
|
||||
@ -16,20 +22,14 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
|
||||
})
|
||||
});
|
||||
|
||||
let body_visit = s.each(|bind| {
|
||||
quote! {
|
||||
::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?;
|
||||
}
|
||||
});
|
||||
|
||||
s.bound_impl(
|
||||
quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>),
|
||||
quote! {
|
||||
fn super_fold_with<__F: ::rustc_middle::ty::fold::TypeFolder<'tcx>>(
|
||||
&self,
|
||||
self,
|
||||
__folder: &mut __F
|
||||
) -> Self {
|
||||
match *self { #body_fold }
|
||||
match self { #body_fold }
|
||||
}
|
||||
|
||||
fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>(
|
||||
|
@ -286,7 +286,7 @@ impl<'tcx, V> Canonical<'tcx, V> {
|
||||
pub type QueryOutlivesConstraint<'tcx> =
|
||||
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
for <'tcx> {
|
||||
crate::infer::canonical::Certainty,
|
||||
crate::infer::canonical::CanonicalVarInfo<'tcx>,
|
||||
@ -294,7 +294,7 @@ CloneTypeFoldableAndLiftImpls! {
|
||||
}
|
||||
}
|
||||
|
||||
CloneTypeFoldableImpls! {
|
||||
TrivialTypeFoldableImpls! {
|
||||
for <'tcx> {
|
||||
crate::infer::canonical::CanonicalVarInfos<'tcx>,
|
||||
}
|
||||
|
@ -48,15 +48,15 @@ macro_rules! CloneLiftImpls {
|
||||
/// Used for types that are `Copy` and which **do not care arena
|
||||
/// allocated data** (i.e., don't need to be folded).
|
||||
#[macro_export]
|
||||
macro_rules! CloneTypeFoldableImpls {
|
||||
macro_rules! TrivialTypeFoldableImpls {
|
||||
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
|
||||
$(
|
||||
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
|
||||
fn super_fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>(
|
||||
&self,
|
||||
self,
|
||||
_: &mut F
|
||||
) -> $ty {
|
||||
Clone::clone(self)
|
||||
self
|
||||
}
|
||||
|
||||
fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
|
||||
@ -71,7 +71,7 @@ macro_rules! CloneTypeFoldableImpls {
|
||||
};
|
||||
|
||||
($($ty:ty,)+) => {
|
||||
CloneTypeFoldableImpls! {
|
||||
TrivialTypeFoldableImpls! {
|
||||
for <'tcx> {
|
||||
$($ty,)+
|
||||
}
|
||||
@ -80,9 +80,9 @@ macro_rules! CloneTypeFoldableImpls {
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! CloneTypeFoldableAndLiftImpls {
|
||||
macro_rules! TrivialTypeFoldableAndLiftImpls {
|
||||
($($t:tt)*) => {
|
||||
CloneTypeFoldableImpls! { $($t)* }
|
||||
TrivialTypeFoldableImpls! { $($t)* }
|
||||
CloneLiftImpls! { $($t)* }
|
||||
}
|
||||
}
|
||||
@ -96,7 +96,7 @@ macro_rules! EnumTypeFoldableImpl {
|
||||
$(where $($wc)*)*
|
||||
{
|
||||
fn super_fold_with<V: $crate::ty::fold::TypeFolder<$tcx>>(
|
||||
&self,
|
||||
self,
|
||||
folder: &mut V,
|
||||
) -> Self {
|
||||
EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())
|
||||
|
@ -29,7 +29,7 @@ impl From<ErrorReported> for ErrorHandled {
|
||||
}
|
||||
}
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
ErrorHandled,
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
|
||||
// improve caching of queries.
|
||||
let inputs = self.erase_regions(¶m_env.and(cid));
|
||||
let inputs = self.erase_regions(param_env.and(cid));
|
||||
if let Some(span) = span {
|
||||
self.at(span).eval_to_const_value_raw(inputs)
|
||||
} else {
|
||||
|
@ -742,7 +742,7 @@ pub enum ImplicitSelfKind {
|
||||
None,
|
||||
}
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
|
||||
TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
|
||||
|
||||
mod binding_form_impl {
|
||||
use crate::ich::StableHashingContext;
|
||||
@ -2452,29 +2452,14 @@ impl UserTypeProjection {
|
||||
}
|
||||
}
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! { ProjectionKind, }
|
||||
TrivialTypeFoldableAndLiftImpls! { ProjectionKind, }
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
use crate::mir::ProjectionElem::*;
|
||||
|
||||
let base = self.base.fold_with(folder);
|
||||
let projs: Vec<_> = self
|
||||
.projs
|
||||
.iter()
|
||||
.map(|&elem| match elem {
|
||||
Deref => Deref,
|
||||
Field(f, ()) => Field(f, ()),
|
||||
Index(()) => Index(()),
|
||||
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
|
||||
ConstantIndex { offset, min_length, from_end } => {
|
||||
ConstantIndex { offset, min_length, from_end }
|
||||
}
|
||||
Subslice { from, to, from_end } => Subslice { from, to, from_end },
|
||||
})
|
||||
.collect();
|
||||
|
||||
UserTypeProjection { base, projs }
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
UserTypeProjection {
|
||||
base: self.base.fold_with(folder),
|
||||
projs: self.projs.fold_with(folder),
|
||||
}
|
||||
}
|
||||
|
||||
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<()> {
|
||||
|
@ -75,6 +75,6 @@ impl<CTX> HashStable<CTX> for PredecessorCache {
|
||||
}
|
||||
}
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
PredecessorCache,
|
||||
}
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
use super::*;
|
||||
use crate::ty;
|
||||
use rustc_data_structures::functor::IdFunctor;
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
BlockTailInfo,
|
||||
MirPhase,
|
||||
SourceInfo,
|
||||
@ -15,34 +16,33 @@ CloneTypeFoldableAndLiftImpls! {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
use crate::mir::TerminatorKind::*;
|
||||
|
||||
let kind = match self.kind {
|
||||
Goto { target } => Goto { target },
|
||||
SwitchInt { ref discr, switch_ty, ref targets } => SwitchInt {
|
||||
SwitchInt { discr, switch_ty, targets } => SwitchInt {
|
||||
discr: discr.fold_with(folder),
|
||||
switch_ty: switch_ty.fold_with(folder),
|
||||
targets: targets.clone(),
|
||||
targets,
|
||||
},
|
||||
Drop { ref place, target, unwind } => {
|
||||
Drop { place, target, unwind } => {
|
||||
Drop { place: place.fold_with(folder), target, unwind }
|
||||
}
|
||||
DropAndReplace { ref place, ref value, target, unwind } => DropAndReplace {
|
||||
DropAndReplace { place, value, target, unwind } => DropAndReplace {
|
||||
place: place.fold_with(folder),
|
||||
value: value.fold_with(folder),
|
||||
target,
|
||||
unwind,
|
||||
},
|
||||
Yield { ref value, resume, ref resume_arg, drop } => Yield {
|
||||
Yield { value, resume, resume_arg, drop } => Yield {
|
||||
value: value.fold_with(folder),
|
||||
resume,
|
||||
resume_arg: resume_arg.fold_with(folder),
|
||||
drop,
|
||||
},
|
||||
Call { ref func, ref args, ref destination, cleanup, from_hir_call, fn_span } => {
|
||||
let dest =
|
||||
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));
|
||||
Call { func, args, destination, cleanup, from_hir_call, fn_span } => {
|
||||
let dest = destination.map(|(loc, dest)| (loc.fold_with(folder), dest));
|
||||
|
||||
Call {
|
||||
func: func.fold_with(folder),
|
||||
@ -53,17 +53,17 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
||||
fn_span,
|
||||
}
|
||||
}
|
||||
Assert { ref cond, expected, ref msg, target, cleanup } => {
|
||||
Assert { cond, expected, msg, target, cleanup } => {
|
||||
use AssertKind::*;
|
||||
let msg = match msg {
|
||||
BoundsCheck { len, index } => {
|
||||
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
|
||||
}
|
||||
Overflow(op, l, r) => Overflow(*op, l.fold_with(folder), r.fold_with(folder)),
|
||||
Overflow(op, l, r) => Overflow(op, l.fold_with(folder), r.fold_with(folder)),
|
||||
OverflowNeg(op) => OverflowNeg(op.fold_with(folder)),
|
||||
DivisionByZero(op) => DivisionByZero(op.fold_with(folder)),
|
||||
RemainderByZero(op) => RemainderByZero(op.fold_with(folder)),
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg.clone(),
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg,
|
||||
};
|
||||
Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
|
||||
}
|
||||
@ -76,7 +76,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
||||
FalseEdge { real_target, imaginary_target }
|
||||
}
|
||||
FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind },
|
||||
InlineAsm { template, ref operands, options, line_spans, destination } => InlineAsm {
|
||||
InlineAsm { template, operands, options, line_spans, destination } => InlineAsm {
|
||||
template,
|
||||
operands: operands.fold_with(folder),
|
||||
options,
|
||||
@ -140,8 +140,8 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
|
||||
@ -150,7 +150,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
|
||||
}
|
||||
|
||||
@ -161,9 +161,8 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
|
||||
folder.tcx().intern_place_elems(&v)
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -172,29 +171,25 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
use crate::mir::Rvalue::*;
|
||||
match *self {
|
||||
Use(ref op) => Use(op.fold_with(folder)),
|
||||
Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
|
||||
match self {
|
||||
Use(op) => Use(op.fold_with(folder)),
|
||||
Repeat(op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
|
||||
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
|
||||
Ref(region, bk, ref place) => {
|
||||
Ref(region.fold_with(folder), bk, place.fold_with(folder))
|
||||
}
|
||||
AddressOf(mutability, ref place) => AddressOf(mutability, place.fold_with(folder)),
|
||||
Len(ref place) => Len(place.fold_with(folder)),
|
||||
Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
|
||||
BinaryOp(op, ref rhs, ref lhs) => {
|
||||
BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
|
||||
}
|
||||
CheckedBinaryOp(op, ref rhs, ref lhs) => {
|
||||
Ref(region, bk, place) => Ref(region.fold_with(folder), bk, place.fold_with(folder)),
|
||||
AddressOf(mutability, place) => AddressOf(mutability, place.fold_with(folder)),
|
||||
Len(place) => Len(place.fold_with(folder)),
|
||||
Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
|
||||
BinaryOp(op, rhs, lhs) => BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)),
|
||||
CheckedBinaryOp(op, rhs, lhs) => {
|
||||
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
|
||||
}
|
||||
UnaryOp(op, ref val) => UnaryOp(op, val.fold_with(folder)),
|
||||
Discriminant(ref place) => Discriminant(place.fold_with(folder)),
|
||||
UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)),
|
||||
Discriminant(place) => Discriminant(place.fold_with(folder)),
|
||||
NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)),
|
||||
Aggregate(ref kind, ref fields) => {
|
||||
let kind = box match **kind {
|
||||
Aggregate(kind, fields) => {
|
||||
let kind = kind.map_id(|kind| match kind {
|
||||
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
|
||||
AggregateKind::Tuple => AggregateKind::Tuple,
|
||||
AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt(
|
||||
@ -210,7 +205,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
||||
AggregateKind::Generator(id, substs, movablity) => {
|
||||
AggregateKind::Generator(id, substs.fold_with(folder), movablity)
|
||||
}
|
||||
};
|
||||
});
|
||||
Aggregate(kind, fields.fold_with(folder))
|
||||
}
|
||||
}
|
||||
@ -263,11 +258,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
Operand::Copy(ref place) => Operand::Copy(place.fold_with(folder)),
|
||||
Operand::Move(ref place) => Operand::Move(place.fold_with(folder)),
|
||||
Operand::Constant(ref c) => Operand::Constant(c.fold_with(folder)),
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
match self {
|
||||
Operand::Copy(place) => Operand::Copy(place.fold_with(folder)),
|
||||
Operand::Move(place) => Operand::Move(place.fold_with(folder)),
|
||||
Operand::Constant(c) => Operand::Constant(c.fold_with(folder)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,10 +275,10 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
use crate::mir::ProjectionElem::*;
|
||||
|
||||
match *self {
|
||||
match self {
|
||||
Deref => Deref,
|
||||
Field(f, ty) => Field(f, ty.fold_with(folder)),
|
||||
Index(v) => Index(v.fold_with(folder)),
|
||||
@ -307,8 +302,8 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Field {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
|
||||
ControlFlow::CONTINUE
|
||||
@ -316,8 +311,8 @@ impl<'tcx> TypeFoldable<'tcx> for Field {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
|
||||
ControlFlow::CONTINUE
|
||||
@ -325,8 +320,8 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
|
||||
}
|
||||
|
||||
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
|
||||
self.clone()
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
|
||||
ControlFlow::CONTINUE
|
||||
@ -334,7 +329,7 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
Constant {
|
||||
span: self.span,
|
||||
user_ty: self.user_ty.fold_with(folder),
|
||||
|
@ -367,7 +367,7 @@ rustc_queries! {
|
||||
|
||||
TypeChecking {
|
||||
/// Erases regions from `ty` to yield a new type.
|
||||
/// Normally you would just use `tcx.erase_regions(&value)`,
|
||||
/// Normally you would just use `tcx.erase_regions(value)`,
|
||||
/// however, which uses this query as a kind of cache.
|
||||
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
// This query is not expected to have input -- as a result, it
|
||||
|
@ -105,7 +105,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx,
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Lift implementations
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
super::IfExpressionCause,
|
||||
super::ImplSourceDiscriminantKindData,
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub enum BindingMode {
|
||||
BindByValue(Mutability),
|
||||
}
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! { BindingMode, }
|
||||
TrivialTypeFoldableAndLiftImpls! { BindingMode, }
|
||||
|
||||
impl BindingMode {
|
||||
pub fn convert(ba: BindingAnnotation) -> BindingMode {
|
||||
|
@ -103,9 +103,9 @@ impl<'tcx> ConstKind<'tcx> {
|
||||
// so that we don't try to invoke this query with
|
||||
// any region variables.
|
||||
let param_env_and_substs = tcx
|
||||
.erase_regions(¶m_env)
|
||||
.erase_regions(param_env)
|
||||
.with_reveal_all_normalized(tcx)
|
||||
.and(tcx.erase_regions(&substs));
|
||||
.and(tcx.erase_regions(substs));
|
||||
|
||||
// HACK(eddyb) when the query key would contain inference variables,
|
||||
// attempt using identity substs and `ParamEnv` instead, that will succeed
|
||||
|
@ -1495,7 +1495,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
match ret_ty.kind() {
|
||||
ty::FnDef(_, _) => {
|
||||
let sig = ret_ty.fn_sig(self);
|
||||
let output = self.erase_late_bound_regions(&sig.output());
|
||||
let output = self.erase_late_bound_regions(sig.output());
|
||||
if output.is_impl_trait() {
|
||||
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
|
||||
Some((output, fn_decl.output.span()))
|
||||
|
@ -15,17 +15,17 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Returns an equivalent value with all free regions removed (note
|
||||
/// that late-bound regions remain, because they are important for
|
||||
/// subtyping, but they are anonymized and normalized as well)..
|
||||
pub fn erase_regions<T>(self, value: &T) -> T
|
||||
pub fn erase_regions<T>(self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
// If there's nothing to erase avoid performing the query at all
|
||||
if !value.has_type_flags(TypeFlags::HAS_RE_LATE_BOUND | TypeFlags::HAS_FREE_REGIONS) {
|
||||
return value.clone();
|
||||
return value;
|
||||
}
|
||||
|
||||
debug!("erase_regions({:?})", value);
|
||||
let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self });
|
||||
debug!("erase_regions({:?}) = {:?}", value, value1);
|
||||
debug!("erase_regions = {:?}", value1);
|
||||
value1
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,7 @@ impl TypeFolder<'tcx> for RegionEraserVisitor<'tcx> {
|
||||
if ty.needs_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) }
|
||||
}
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
|
||||
fn fold_binder<T>(&mut self, t: ty::Binder<T>) -> ty::Binder<T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -44,8 +44,8 @@ use std::ops::ControlFlow;
|
||||
///
|
||||
/// To implement this conveniently, use the derive macro located in librustc_macros.
|
||||
pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self;
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self;
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.super_fold_with(folder)
|
||||
}
|
||||
|
||||
@ -158,8 +158,8 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
||||
}
|
||||
|
||||
impl TypeFoldable<'tcx> for hir::Constness {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
|
||||
ControlFlow::CONTINUE
|
||||
@ -174,7 +174,7 @@ impl TypeFoldable<'tcx> for hir::Constness {
|
||||
pub trait TypeFolder<'tcx>: Sized {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
|
||||
|
||||
fn fold_binder<T>(&mut self, t: &Binder<T>) -> Binder<T>
|
||||
fn fold_binder<T>(&mut self, t: Binder<T>) -> Binder<T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -266,7 +266,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// and skipped.
|
||||
pub fn fold_regions<T>(
|
||||
self,
|
||||
value: &T,
|
||||
value: T,
|
||||
skipped_regions: &mut bool,
|
||||
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
|
||||
) -> T
|
||||
@ -406,7 +406,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.current_index.shift_in(1);
|
||||
let t = t.super_fold_with(self);
|
||||
self.current_index.shift_out(1);
|
||||
@ -466,7 +466,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.current_index.shift_in(1);
|
||||
let t = t.super_fold_with(self);
|
||||
self.current_index.shift_out(1);
|
||||
@ -549,7 +549,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// contain escaping bound types.
|
||||
pub fn replace_late_bound_regions<T, F>(
|
||||
self,
|
||||
value: &Binder<T>,
|
||||
value: Binder<T>,
|
||||
fld_r: F,
|
||||
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
|
||||
where
|
||||
@ -561,7 +561,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
let fld_c = |bound_ct, ty| {
|
||||
self.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, bound_ct), ty })
|
||||
};
|
||||
self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c)
|
||||
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c)
|
||||
}
|
||||
|
||||
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
|
||||
@ -569,7 +569,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// closure replaces escaping bound consts.
|
||||
pub fn replace_escaping_bound_vars<T, F, G, H>(
|
||||
self,
|
||||
value: &T,
|
||||
value: T,
|
||||
mut fld_r: F,
|
||||
mut fld_t: G,
|
||||
mut fld_c: H,
|
||||
@ -609,7 +609,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// types.
|
||||
pub fn replace_bound_vars<T, F, G, H>(
|
||||
self,
|
||||
value: &Binder<T>,
|
||||
value: Binder<T>,
|
||||
fld_r: F,
|
||||
fld_t: G,
|
||||
fld_c: H,
|
||||
@ -620,16 +620,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c)
|
||||
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c)
|
||||
}
|
||||
|
||||
/// Replaces any late-bound regions bound in `value` with
|
||||
/// free variants attached to `all_outlive_scope`.
|
||||
pub fn liberate_late_bound_regions<T>(
|
||||
self,
|
||||
all_outlive_scope: DefId,
|
||||
value: &ty::Binder<T>,
|
||||
) -> T
|
||||
pub fn liberate_late_bound_regions<T>(self, all_outlive_scope: DefId, value: ty::Binder<T>) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -683,7 +679,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
/// Replaces any late-bound regions bound in `value` with `'erased`. Useful in codegen but also
|
||||
/// method lookup and a few other places where precise region relationships are not required.
|
||||
pub fn erase_late_bound_regions<T>(self, value: &Binder<T>) -> T
|
||||
pub fn erase_late_bound_regions<T>(self, value: Binder<T>) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -698,7 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// `FnSig`s or `TraitRef`s which are equivalent up to region naming will become
|
||||
/// structurally identical. For example, `for<'a, 'b> fn(&'a isize, &'b isize)` and
|
||||
/// `for<'a, 'b> fn(&'b isize, &'a isize)` will become identical after anonymization.
|
||||
pub fn anonymize_late_bound_regions<T>(self, sig: &Binder<T>) -> Binder<T>
|
||||
pub fn anonymize_late_bound_regions<T>(self, sig: Binder<T>) -> Binder<T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -740,7 +736,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.current_index.shift_in(1);
|
||||
let t = t.super_fold_with(self);
|
||||
self.current_index.shift_out(1);
|
||||
@ -804,7 +800,7 @@ pub fn shift_region<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shift_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: &T, amount: u32) -> T
|
||||
pub fn shift_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: T, amount: u32) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -359,15 +359,15 @@ impl<'tcx> Instance<'tcx> {
|
||||
// HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)`
|
||||
// below is more likely to ignore the bounds in scope (e.g. if the only
|
||||
// generic parameters mentioned by `substs` were lifetime ones).
|
||||
let substs = tcx.erase_regions(&substs);
|
||||
let substs = tcx.erase_regions(substs);
|
||||
|
||||
// FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
|
||||
if let Some((did, param_did)) = def.as_const_arg() {
|
||||
tcx.resolve_instance_of_const_arg(
|
||||
tcx.erase_regions(¶m_env.and((did, param_did, substs))),
|
||||
tcx.erase_regions(param_env.and((did, param_did, substs))),
|
||||
)
|
||||
} else {
|
||||
tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def.did, substs))))
|
||||
tcx.resolve_instance(tcx.erase_regions(param_env.and((def.did, substs))))
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,7 +452,7 @@ impl<'tcx> Instance<'tcx> {
|
||||
let self_ty = tcx.mk_closure(closure_did, substs);
|
||||
|
||||
let sig = substs.as_closure().sig();
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
|
||||
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
|
||||
assert_eq!(sig.inputs().len(), 1);
|
||||
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
|
||||
|
||||
@ -485,7 +485,7 @@ impl<'tcx> Instance<'tcx> {
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
v: &T,
|
||||
v: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx> + Clone,
|
||||
@ -493,7 +493,7 @@ impl<'tcx> Instance<'tcx> {
|
||||
if let Some(substs) = self.substs_for_mir_body() {
|
||||
tcx.subst_and_normalize_erasing_regions(substs, param_env, v)
|
||||
} else {
|
||||
tcx.normalize_erasing_regions(param_env, v.clone())
|
||||
tcx.normalize_erasing_regions(param_env, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1756,7 +1756,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
|
||||
match tail.kind() {
|
||||
ty::Param(_) | ty::Projection(_) => {
|
||||
debug_assert!(tail.has_param_types_or_consts());
|
||||
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(&tail) })
|
||||
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
|
||||
}
|
||||
_ => bug!(
|
||||
"SizeSkeleton::compute({}): layout errored ({}), yet \
|
||||
@ -2545,7 +2545,7 @@ where
|
||||
) -> Self {
|
||||
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
|
||||
|
||||
let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
|
||||
let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
|
||||
|
||||
use rustc_target::spec::abi::Abi::*;
|
||||
let conv = match cx.tcx().sess.target.adjust_abi(sig.abi) {
|
||||
|
@ -1788,7 +1788,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> {
|
||||
fn super_fold_with<F: ty::fold::TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: ty::fold::TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ParamEnv::new(self.caller_bounds().fold_with(folder), self.reveal().fold_with(folder))
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
// Erase first before we do the real query -- this keeps the
|
||||
// cache from being too polluted.
|
||||
let value = self.erase_regions(&value);
|
||||
let value = self.erase_regions(value);
|
||||
if !value.has_projections() {
|
||||
value
|
||||
} else {
|
||||
@ -49,7 +49,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn normalize_erasing_late_bound_regions<T>(
|
||||
self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -65,7 +65,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self,
|
||||
param_substs: SubstsRef<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
|
@ -1750,7 +1750,7 @@ impl<F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
let mut region_index = self.region_index;
|
||||
let new_value = self.tcx.replace_late_bound_regions(value, |br| {
|
||||
let new_value = self.tcx.replace_late_bound_regions(value.clone(), |br| {
|
||||
let _ = start_or_continue(&mut self, "for<", ", ");
|
||||
let br = match br {
|
||||
ty::BrNamed(_, name) => {
|
||||
|
@ -7,12 +7,12 @@ use crate::mir::ProjectionKind;
|
||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
|
||||
use crate::ty::{self, InferConst, Lift, Ty, TyCtxt};
|
||||
use rustc_data_structures::functor::IdFunctor;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_hir::def_id::CRATE_DEF_INDEX;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
use std::ops::ControlFlow;
|
||||
use std::rc::Rc;
|
||||
@ -274,7 +274,7 @@ impl fmt::Debug for ty::PredicateAtom<'tcx> {
|
||||
// For things that don't carry any arena-allocated data (and are
|
||||
// copy...), just add them to this list.
|
||||
|
||||
CloneTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
(),
|
||||
bool,
|
||||
usize,
|
||||
@ -725,8 +725,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
|
||||
|
||||
/// AdtDefs are basically the same as a DefId.
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -735,7 +735,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> (T, U) {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> (T, U) {
|
||||
(self.0.fold_with(folder), self.1.fold_with(folder))
|
||||
}
|
||||
|
||||
@ -748,7 +748,7 @@ impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for
|
||||
impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx>
|
||||
for (A, B, C)
|
||||
{
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> (A, B, C) {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> (A, B, C) {
|
||||
(self.0.fold_with(folder), self.1.fold_with(folder), self.2.fold_with(folder))
|
||||
}
|
||||
|
||||
@ -774,8 +774,9 @@ EnumTypeFoldableImpl! {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
Rc::new((**self).fold_with(folder))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
// FIXME: Reuse the `Rc` here.
|
||||
Rc::new((*self).clone().fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -784,8 +785,9 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
Arc::new((**self).fold_with(folder))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
// FIXME: Reuse the `Arc` here.
|
||||
Arc::new((*self).clone().fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -794,9 +796,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let content: T = (**self).fold_with(folder);
|
||||
box content
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.map_id(|value| value.fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -805,8 +806,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.iter().map(|t| t.fold_with(folder)).collect()
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.map_id(|t| t.fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -815,8 +816,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.map_id(|t| t.fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -825,11 +826,11 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.map_bound_ref(|ty| ty.fold_with(folder))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.map_bound(|ty| ty.fold_with(folder))
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_binder(self)
|
||||
}
|
||||
|
||||
@ -843,8 +844,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fold_list(*self, folder, |tcx, v| tcx.intern_existential_predicates(v))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -853,8 +854,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>>
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fold_list(*self, folder, |tcx, v| tcx.intern_type_list(v))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -863,8 +864,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fold_list(*self, folder, |tcx, v| tcx.intern_projs(v))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -873,7 +874,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
use crate::ty::InstanceDef::*;
|
||||
Self {
|
||||
substs: self.substs.fold_with(folder),
|
||||
@ -915,7 +916,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
Self { instance: self.instance.fold_with(folder), promoted: self.promoted }
|
||||
}
|
||||
|
||||
@ -925,26 +926,26 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let kind = match self.kind() {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
let kind = match *self.kind() {
|
||||
ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
|
||||
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
|
||||
ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
|
||||
ty::Adt(tid, substs) => ty::Adt(*tid, substs.fold_with(folder)),
|
||||
ty::Dynamic(ref trait_ty, ref region) => {
|
||||
ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
|
||||
ty::Dynamic(trait_ty, region) => {
|
||||
ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
|
||||
}
|
||||
ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
|
||||
ty::FnDef(def_id, substs) => ty::FnDef(*def_id, substs.fold_with(folder)),
|
||||
ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)),
|
||||
ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
|
||||
ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), *mutbl),
|
||||
ty::Ref(r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
|
||||
ty::Generator(did, substs, movability) => {
|
||||
ty::Generator(*did, substs.fold_with(folder), *movability)
|
||||
ty::Generator(did, substs.fold_with(folder), movability)
|
||||
}
|
||||
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
|
||||
ty::Closure(did, substs) => ty::Closure(*did, substs.fold_with(folder)),
|
||||
ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
|
||||
ty::Opaque(did, substs) => ty::Opaque(*did, substs.fold_with(folder)),
|
||||
ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
|
||||
ty::Projection(data) => ty::Projection(data.fold_with(folder)),
|
||||
ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
|
||||
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
@ -964,8 +965,8 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_ty(*self)
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_ty(self)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1016,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_region(*self)
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_region(self)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1034,9 +1035,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let new = ty::PredicateKind::super_fold_with(&self.inner.kind, folder);
|
||||
folder.tcx().reuse_or_mk_predicate(*self, new)
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder);
|
||||
folder.tcx().reuse_or_mk_predicate(self, new)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1057,8 +1058,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v))
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1067,8 +1068,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||
}
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
self.iter().map(|x| x.fold_with(folder)).collect()
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
self.map_id(|x| x.fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1077,18 +1078,18 @@ impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T>
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
let ty = self.ty.fold_with(folder);
|
||||
let val = self.val.fold_with(folder);
|
||||
if ty != self.ty || val != self.val {
|
||||
folder.tcx().mk_const(ty::Const { ty, val })
|
||||
} else {
|
||||
*self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.fold_const(*self)
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_const(self)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
||||
@ -1102,8 +1103,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
match *self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
match self {
|
||||
ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)),
|
||||
ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)),
|
||||
ty::ConstKind::Unevaluated(did, substs, promoted) => {
|
||||
@ -1112,7 +1113,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
|
||||
ty::ConstKind::Value(_)
|
||||
| ty::ConstKind::Bound(..)
|
||||
| ty::ConstKind::Placeholder(..)
|
||||
| ty::ConstKind::Error(_) => *self,
|
||||
| ty::ConstKind::Error(_) => self,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1130,42 +1131,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
|
||||
*self
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
// Does the equivalent of
|
||||
// ```
|
||||
// let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
|
||||
// folder.tcx().intern_*(&v)
|
||||
// ```
|
||||
fn fold_list<'tcx, F, T>(
|
||||
list: &'tcx ty::List<T>,
|
||||
folder: &mut F,
|
||||
intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List<T>,
|
||||
) -> &'tcx ty::List<T>
|
||||
where
|
||||
F: TypeFolder<'tcx>,
|
||||
T: TypeFoldable<'tcx> + PartialEq + Copy,
|
||||
{
|
||||
let mut iter = list.iter();
|
||||
// Look for the first element that changed
|
||||
if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| {
|
||||
let new_t = t.fold_with(folder);
|
||||
if new_t == t { None } else { Some((i, new_t)) }
|
||||
}) {
|
||||
// An element changed, prepare to intern the resulting list
|
||||
let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len());
|
||||
new_list.extend_from_slice(&list[..i]);
|
||||
new_list.push(new_t);
|
||||
new_list.extend(iter.map(|t| t.fold_with(folder)));
|
||||
intern(folder.tcx(), &new_list)
|
||||
} else {
|
||||
list
|
||||
}
|
||||
}
|
||||
|
@ -1001,7 +1001,7 @@ impl<T> Binder<T> {
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
if value.has_escaping_bound_vars() {
|
||||
Binder::bind(super::fold::shift_vars(tcx, &value, 1))
|
||||
Binder::bind(super::fold::shift_vars(tcx, value, 1))
|
||||
} else {
|
||||
Binder::dummy(value)
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
match self.unpack() {
|
||||
GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(),
|
||||
GenericArgKind::Type(ty) => ty.fold_with(folder).into(),
|
||||
@ -363,7 +363,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
// This code is hot enough that it's worth specializing for the most
|
||||
// common length lists, to avoid the overhead of `SmallVec` creation.
|
||||
// The match arms are in order of frequency. The 1, 2, and 0 cases are
|
||||
@ -405,12 +405,12 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
|
||||
// there is more information available (for better errors).
|
||||
|
||||
pub trait Subst<'tcx>: Sized {
|
||||
fn subst(&self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self {
|
||||
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self {
|
||||
self.subst_spanned(tcx, substs, None)
|
||||
}
|
||||
|
||||
fn subst_spanned(
|
||||
&self,
|
||||
self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
substs: &[GenericArg<'tcx>],
|
||||
span: Option<Span>,
|
||||
@ -419,13 +419,13 @@ pub trait Subst<'tcx>: Sized {
|
||||
|
||||
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
|
||||
fn subst_spanned(
|
||||
&self,
|
||||
self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
substs: &[GenericArg<'tcx>],
|
||||
span: Option<Span>,
|
||||
) -> T {
|
||||
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
|
||||
(*self).fold_with(&mut folder)
|
||||
self.fold_with(&mut folder)
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,7 +448,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
|
||||
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: ty::Binder<T>) -> ty::Binder<T> {
|
||||
self.binders_passed += 1;
|
||||
let t = t.super_fold_with(self);
|
||||
self.binders_passed -= 1;
|
||||
@ -634,7 +634,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
|
||||
return val;
|
||||
}
|
||||
|
||||
let result = ty::fold::shift_vars(self.tcx(), &val, self.binders_passed);
|
||||
let result = ty::fold::shift_vars(self.tcx(), val, self.binders_passed);
|
||||
debug!("shift_vars: shifted result = {:?}", result);
|
||||
|
||||
result
|
||||
|
@ -160,7 +160,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
// We want the type_id be independent of the types free regions, so we
|
||||
// erase them. The erase_regions() call will also anonymize bound
|
||||
// regions, which is desirable too.
|
||||
let ty = self.erase_regions(&ty);
|
||||
let ty = self.erase_regions(ty);
|
||||
|
||||
hcx.while_hashing_spans(false, |hcx| {
|
||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||
@ -1130,6 +1130,37 @@ pub fn needs_drop_components(
|
||||
}
|
||||
}
|
||||
|
||||
// Does the equivalent of
|
||||
// ```
|
||||
// let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
|
||||
// folder.tcx().intern_*(&v)
|
||||
// ```
|
||||
pub fn fold_list<'tcx, F, T>(
|
||||
list: &'tcx ty::List<T>,
|
||||
folder: &mut F,
|
||||
intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List<T>,
|
||||
) -> &'tcx ty::List<T>
|
||||
where
|
||||
F: TypeFolder<'tcx>,
|
||||
T: TypeFoldable<'tcx> + PartialEq + Copy,
|
||||
{
|
||||
let mut iter = list.iter();
|
||||
// Look for the first element that changed
|
||||
if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| {
|
||||
let new_t = t.fold_with(folder);
|
||||
if new_t == t { None } else { Some((i, new_t)) }
|
||||
}) {
|
||||
// An element changed, prepare to intern the resulting list
|
||||
let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len());
|
||||
new_list.extend_from_slice(&list[..i]);
|
||||
new_list.push(new_t);
|
||||
new_list.extend(iter.map(|t| t.fold_with(folder)));
|
||||
intern(folder.tcx(), &new_list)
|
||||
} else {
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable, TyEncodable, TyDecodable)]
|
||||
pub struct AlwaysRequiresDrop;
|
||||
|
||||
|
@ -876,7 +876,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
// Type-test failed. Report the error.
|
||||
let erased_generic_kind = infcx.tcx.erase_regions(&type_test.generic_kind);
|
||||
let erased_generic_kind = infcx.tcx.erase_regions(type_test.generic_kind);
|
||||
|
||||
// Skip duplicate-ish errors.
|
||||
if deduplicate_errors.insert((
|
||||
@ -1006,7 +1006,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
|
||||
debug!("try_promote_type_test_subject(ty = {:?})", ty);
|
||||
|
||||
let ty = tcx.fold_regions(&ty, &mut false, |r, _depth| {
|
||||
let ty = tcx.fold_regions(ty, &mut false, |r, _depth| {
|
||||
let region_vid = self.to_region_vid(r);
|
||||
|
||||
// The challenge if this. We have some region variable `r`
|
||||
@ -1248,7 +1248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&value, &mut false, |r, _db| {
|
||||
tcx.fold_regions(value, &mut false, |r, _db| {
|
||||
let vid = self.to_region_vid(r);
|
||||
let scc = self.constraint_sccs.scc(vid);
|
||||
let repr = self.scc_representatives[scc];
|
||||
|
@ -63,7 +63,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
|
||||
let mut subst_regions = vec![self.universal_regions.fr_static];
|
||||
let universal_substs =
|
||||
infcx.tcx.fold_regions(&substs, &mut false, |region, _| match *region {
|
||||
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => {
|
||||
subst_regions.push(vid);
|
||||
self.definitions[vid].external_name.unwrap_or_else(|| {
|
||||
@ -94,7 +94,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
subst_regions.dedup();
|
||||
|
||||
let universal_concrete_type =
|
||||
infcx.tcx.fold_regions(&concrete_type, &mut false, |region, _| match *region {
|
||||
infcx.tcx.fold_regions(concrete_type, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => subst_regions
|
||||
.iter()
|
||||
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
|
||||
@ -139,7 +139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&ty, &mut false, |region, _| match *region {
|
||||
tcx.fold_regions(ty, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => {
|
||||
// Find something that we can name
|
||||
let upper_bound = self.approx_universal_upper_bound(vid);
|
||||
|
@ -26,7 +26,7 @@ pub fn renumber_mir<'tcx>(
|
||||
|
||||
/// Replaces all regions appearing in `value` with fresh inference
|
||||
/// variables.
|
||||
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: &T) -> T
|
||||
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -43,7 +43,7 @@ struct NLLVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> NLLVisitor<'a, 'tcx> {
|
||||
fn renumber_regions<T>(&mut self, value: &T) -> T
|
||||
fn renumber_regions<T>(&mut self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
@ -70,7 +70,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
|
||||
_: Location,
|
||||
) -> Option<PlaceElem<'tcx>> {
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
let new_ty = self.renumber_regions(&ty);
|
||||
let new_ty = self.renumber_regions(ty);
|
||||
|
||||
if new_ty != ty {
|
||||
return Some(PlaceElem::Field(field, new_ty));
|
||||
@ -83,7 +83,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
|
||||
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
||||
debug!("visit_substs(substs={:?}, location={:?})", substs, location);
|
||||
|
||||
*substs = self.renumber_regions(&{ *substs });
|
||||
*substs = self.renumber_regions(*substs);
|
||||
|
||||
debug!("visit_substs: substs={:?}", substs);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
.replace_bound_vars_with_fresh_vars(
|
||||
body.span,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
&poly_sig,
|
||||
poly_sig,
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
@ -784,7 +784,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
};
|
||||
|
||||
if let Some(field) = variant.fields.get(field.index()) {
|
||||
Ok(self.cx.normalize(&field.ty(tcx, substs), location))
|
||||
Ok(self.cx.normalize(field.ty(tcx, substs), location))
|
||||
} else {
|
||||
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
|
||||
}
|
||||
@ -1245,7 +1245,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
anon_owner_def_id,
|
||||
dummy_body_id,
|
||||
param_env,
|
||||
&anon_ty,
|
||||
anon_ty,
|
||||
locations.span(body),
|
||||
));
|
||||
debug!(
|
||||
@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
);
|
||||
|
||||
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
|
||||
let resolved_ty = infcx.resolve_vars_if_possible(&opaque_decl.concrete_ty);
|
||||
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
|
||||
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
|
||||
*def_id == opaque_def_id
|
||||
} else {
|
||||
@ -1296,7 +1296,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let subst_opaque_defn_ty =
|
||||
opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs);
|
||||
let renumbered_opaque_defn_ty =
|
||||
renumber::renumber_regions(infcx, &subst_opaque_defn_ty);
|
||||
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
|
||||
|
||||
debug!(
|
||||
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}",
|
||||
@ -1601,7 +1601,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let (sig, map) = self.infcx.replace_bound_vars_with_fresh_vars(
|
||||
term.source_info.span,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
&sig,
|
||||
sig,
|
||||
);
|
||||
let sig = self.normalize(sig, term_location);
|
||||
self.check_call_dest(body, term, &sig, destination, term_location);
|
||||
@ -1900,7 +1900,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
// Erase the regions from `ty` to get a global type. The
|
||||
// `Sized` bound in no way depends on precise regions, so this
|
||||
// shouldn't affect `is_sized`.
|
||||
let erased_ty = tcx.erase_regions(&ty);
|
||||
let erased_ty = tcx.erase_regions(ty);
|
||||
if !erased_ty.is_sized(tcx.at(span), self.param_env) {
|
||||
// in current MIR construction, all non-control-flow rvalue
|
||||
// expressions evaluate through `as_temp` or `into` a return
|
||||
|
@ -438,7 +438,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
|
||||
FR,
|
||||
self.mir_def.did,
|
||||
&bound_inputs_and_output,
|
||||
bound_inputs_and_output,
|
||||
&mut indices,
|
||||
);
|
||||
// Converse of above, if this is a function then the late-bound regions declared on its
|
||||
@ -522,7 +522,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
|
||||
|
||||
let defining_ty =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, &defining_ty);
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty);
|
||||
|
||||
match *defining_ty.kind() {
|
||||
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
|
||||
@ -543,7 +543,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
assert_eq!(self.mir_def.did.to_def_id(), closure_base_def_id);
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
|
||||
let substs =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, &identity_substs);
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
|
||||
DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
|
||||
}
|
||||
}
|
||||
@ -628,7 +628,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
|
||||
DefiningTy::FnDef(def_id, _) => {
|
||||
let sig = tcx.fn_sig(def_id);
|
||||
let sig = indices.fold_to_region_vids(tcx, &sig);
|
||||
let sig = indices.fold_to_region_vids(tcx, sig);
|
||||
sig.inputs_and_output()
|
||||
}
|
||||
|
||||
@ -637,7 +637,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
// "output" (the type of the constant).
|
||||
assert_eq!(self.mir_def.did.to_def_id(), def_id);
|
||||
let ty = tcx.type_of(self.mir_def.def_id_for_type_of());
|
||||
let ty = indices.fold_to_region_vids(tcx, &ty);
|
||||
let ty = indices.fold_to_region_vids(tcx, ty);
|
||||
ty::Binder::dummy(tcx.intern_type_list(&[ty]))
|
||||
}
|
||||
}
|
||||
@ -648,7 +648,7 @@ trait InferCtxtExt<'tcx> {
|
||||
fn replace_free_regions_with_nll_infer_vars<T>(
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>;
|
||||
@ -657,7 +657,7 @@ trait InferCtxtExt<'tcx> {
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
all_outlive_scope: LocalDefId,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
indices: &mut UniversalRegionIndices<'tcx>,
|
||||
) -> T
|
||||
where
|
||||
@ -674,7 +674,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
||||
fn replace_free_regions_with_nll_infer_vars<T>(
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -686,7 +686,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
all_outlive_scope: LocalDefId,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
indices: &mut UniversalRegionIndices<'tcx>,
|
||||
) -> T
|
||||
where
|
||||
@ -771,7 +771,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
||||
|
||||
/// Replaces all free regions in `value` with region vids, as
|
||||
/// returned by `to_region_vid`.
|
||||
pub fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: &T) -> T
|
||||
pub fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>(
|
||||
let ty = place.ty(body, tcx).ty;
|
||||
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
|
||||
|
||||
let erased_ty = tcx.erase_regions(&ty);
|
||||
let erased_ty = tcx.erase_regions(ty);
|
||||
if erased_ty.needs_drop(tcx, ctxt.param_env) {
|
||||
each_child(child);
|
||||
} else {
|
||||
|
@ -505,7 +505,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
|
||||
value: T,
|
||||
) -> T {
|
||||
frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, &value)
|
||||
frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value)
|
||||
}
|
||||
|
||||
/// The `substs` are assumed to already be in our interpreter "universe" (param_env).
|
||||
|
@ -21,7 +21,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
|
||||
trace!("get_vtable(trait_ref={:?})", poly_trait_ref);
|
||||
|
||||
let (ty, poly_trait_ref) = self.tcx.erase_regions(&(ty, poly_trait_ref));
|
||||
let (ty, poly_trait_ref) = self.tcx.erase_regions((ty, poly_trait_ref));
|
||||
|
||||
// All vtables must be monomorphic, bail out otherwise.
|
||||
ensure_monomorphic_enough(*self.tcx, ty)?;
|
||||
@ -37,7 +37,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
||||
let methods = if let Some(poly_trait_ref) = poly_trait_ref {
|
||||
let trait_ref = poly_trait_ref.with_self_ty(*self.tcx, ty);
|
||||
let trait_ref = self.tcx.erase_regions(&trait_ref);
|
||||
let trait_ref = self.tcx.erase_regions(trait_ref);
|
||||
|
||||
self.tcx.vtable_methods(trait_ref)
|
||||
} else {
|
||||
@ -143,7 +143,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;
|
||||
trace!("Found drop fn: {:?}", drop_instance);
|
||||
let fn_sig = drop_instance.ty(*self.tcx, self.param_env).fn_sig(*self.tcx);
|
||||
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, &fn_sig);
|
||||
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig);
|
||||
// The drop function takes `*mut T` where `T` is the type being dropped, so get that.
|
||||
let args = fn_sig.inputs();
|
||||
if args.len() != 1 {
|
||||
|
@ -546,7 +546,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
|
||||
self.instance.subst_mir_and_normalize_erasing_regions(
|
||||
self.tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&value,
|
||||
value,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1118,7 +1118,7 @@ impl RootCollector<'_, 'v> {
|
||||
// late-bound regions, since late-bound
|
||||
// regions must appear in the argument
|
||||
// listing.
|
||||
let main_ret_ty = self.tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap());
|
||||
let main_ret_ty = self.tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
|
||||
|
||||
let start_instance = Instance::resolve(
|
||||
self.tcx,
|
||||
|
@ -304,7 +304,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
||||
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&tcx.type_of(impl_def_id),
|
||||
tcx.type_of(impl_def_id),
|
||||
);
|
||||
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
|
||||
return Some(def_id);
|
||||
|
@ -135,7 +135,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
||||
// Check if this is a generator, if so, return the drop glue for it
|
||||
if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) {
|
||||
let body = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap();
|
||||
return body.subst(tcx, substs);
|
||||
return body.clone().subst(tcx, substs);
|
||||
}
|
||||
|
||||
let substs = if let Some(ty) = ty {
|
||||
@ -144,7 +144,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
||||
InternalSubsts::identity_for_item(tcx, def_id)
|
||||
};
|
||||
let sig = tcx.fn_sig(def_id).subst(tcx, substs);
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
@ -338,7 +338,7 @@ impl CloneShimBuilder<'tcx> {
|
||||
// or access fields of a Place of type TySelf.
|
||||
let substs = tcx.mk_substs_trait(self_ty, &[]);
|
||||
let sig = tcx.fn_sig(def_id).subst(tcx, substs);
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
CloneShimBuilder {
|
||||
@ -656,7 +656,7 @@ fn build_call_shim<'tcx>(
|
||||
// to substitute into the signature of the shim. It is not necessary for users of this
|
||||
// MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`).
|
||||
let (sig_substs, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
|
||||
let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx));
|
||||
let sig = tcx.erase_late_bound_regions(ty.fn_sig(tcx));
|
||||
|
||||
let untuple_args = sig.inputs();
|
||||
|
||||
@ -671,7 +671,7 @@ fn build_call_shim<'tcx>(
|
||||
|
||||
let def_id = instance.def_id();
|
||||
let sig = tcx.fn_sig(def_id);
|
||||
let mut sig = tcx.erase_late_bound_regions(&sig);
|
||||
let mut sig = tcx.erase_late_bound_regions(sig);
|
||||
|
||||
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
||||
if let Some(sig_substs) = sig_substs {
|
||||
|
@ -720,13 +720,13 @@ fn sanitize_witness<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
witness: Ty<'tcx>,
|
||||
upvars: &Vec<Ty<'tcx>>,
|
||||
upvars: Vec<Ty<'tcx>>,
|
||||
saved_locals: &GeneratorSavedLocals,
|
||||
) {
|
||||
let did = body.source.def_id();
|
||||
let allowed_upvars = tcx.erase_regions(upvars);
|
||||
let allowed = match witness.kind() {
|
||||
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
|
||||
&ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s),
|
||||
_ => {
|
||||
tcx.sess.delay_span_bug(
|
||||
body.span,
|
||||
@ -1303,7 +1303,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
let liveness_info =
|
||||
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);
|
||||
|
||||
sanitize_witness(tcx, body, interior, &upvars, &liveness_info.saved_locals);
|
||||
sanitize_witness(tcx, body, interior, upvars, &liveness_info.saved_locals);
|
||||
|
||||
if tcx.sess.opts.debugging_opts.validate_mir {
|
||||
let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias {
|
||||
|
@ -122,7 +122,7 @@ impl Inliner<'tcx> {
|
||||
let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions(
|
||||
self.tcx,
|
||||
self.param_env,
|
||||
callee_body,
|
||||
callee_body.clone(),
|
||||
);
|
||||
|
||||
let old_blocks = caller_body.basic_blocks().next_index();
|
||||
|
@ -240,7 +240,7 @@ fn liberated_closure_env_ty(
|
||||
};
|
||||
|
||||
let closure_env_ty = tcx.closure_env_ty(closure_def_id, closure_substs).unwrap();
|
||||
tcx.erase_late_bound_regions(&closure_env_ty)
|
||||
tcx.erase_late_bound_regions(closure_env_ty)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
@ -51,7 +51,7 @@ pub(super) fn mangle(
|
||||
|
||||
// Erase regions because they may not be deterministic when hashed
|
||||
// and should not matter anyhow.
|
||||
let instance_ty = tcx.erase_regions(&instance_ty);
|
||||
let instance_ty = tcx.erase_regions(instance_ty);
|
||||
|
||||
let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);
|
||||
|
||||
|
@ -39,7 +39,7 @@ impl SymbolNamesTest<'tcx> {
|
||||
let def_id = def_id.to_def_id();
|
||||
let instance = Instance::new(
|
||||
def_id,
|
||||
tcx.erase_regions(&InternalSubsts::identity_for_item(tcx, def_id)),
|
||||
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
|
||||
);
|
||||
let mangled = tcx.symbol_name(instance);
|
||||
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
|
||||
|
@ -109,7 +109,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
||||
param_env,
|
||||
state: AutoderefSnapshot {
|
||||
steps: vec![],
|
||||
cur_ty: infcx.resolve_vars_if_possible(&base_ty),
|
||||
cur_ty: infcx.resolve_vars_if_possible(base_ty),
|
||||
obligations: vec![],
|
||||
at_start: true,
|
||||
reached_recursion_limit: false,
|
||||
@ -164,14 +164,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
||||
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
|
||||
self.state.obligations.extend(obligations);
|
||||
|
||||
Some(self.infcx.resolve_vars_if_possible(&normalized_ty))
|
||||
Some(self.infcx.resolve_vars_if_possible(normalized_ty))
|
||||
}
|
||||
|
||||
/// Returns the final type we ended up with, which may be an inference
|
||||
/// variable (we will resolve it first, if we want).
|
||||
pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> {
|
||||
if resolve {
|
||||
self.infcx.resolve_vars_if_possible(&self.state.cur_ty)
|
||||
self.infcx.resolve_vars_if_possible(self.state.cur_ty)
|
||||
} else {
|
||||
self.state.cur_ty
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
span: Span,
|
||||
body_id: hir::HirId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> InferOk<'tcx, T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>;
|
||||
@ -41,7 +41,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
|
||||
if !(param_env, ty).needs_infer() {
|
||||
return ty.is_copy_modulo_regions(self.tcx.at(span), param_env);
|
||||
@ -63,7 +63,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
||||
span: Span,
|
||||
body_id: hir::HirId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> InferOk<'tcx, T>
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -173,7 +173,7 @@ impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
|
||||
debug!("add_implied_bounds()");
|
||||
|
||||
for &ty in fn_sig_tys {
|
||||
let ty = infcx.resolve_vars_if_possible(&ty);
|
||||
let ty = infcx.resolve_vars_if_possible(ty);
|
||||
debug!("add_implied_bounds: ty = {}", ty);
|
||||
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
|
||||
self.add_outlives_bounds(Some(infcx), implied_bounds)
|
||||
|
@ -112,7 +112,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
parent_def_id: LocalDefId,
|
||||
body_id: hir::HirId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: T,
|
||||
value_span: Span,
|
||||
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>;
|
||||
|
||||
@ -188,7 +188,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
parent_def_id: LocalDefId,
|
||||
body_id: hir::HirId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: T,
|
||||
value_span: Span,
|
||||
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
|
||||
debug!(
|
||||
@ -402,7 +402,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
let tcx = self.tcx;
|
||||
|
||||
let concrete_ty = self.resolve_vars_if_possible(&opaque_defn.concrete_ty);
|
||||
let concrete_ty = self.resolve_vars_if_possible(opaque_defn.concrete_ty);
|
||||
|
||||
debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
|
||||
|
||||
@ -1001,7 +1001,7 @@ struct Instantiator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
|
||||
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
|
||||
debug!("instantiate_opaque_types_in_map(value={:?})", value);
|
||||
let tcx = self.infcx.tcx;
|
||||
value.fold_with(&mut BottomUpFolder {
|
||||
@ -1125,7 +1125,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
|
||||
let param_env = tcx.param_env(def_id);
|
||||
let InferOk { value: bounds, obligations } =
|
||||
infcx.partially_normalize_associated_types_in(span, self.body_id, param_env, &bounds);
|
||||
infcx.partially_normalize_associated_types_in(span, self.body_id, param_env, bounds);
|
||||
self.obligations.extend(obligations);
|
||||
|
||||
debug!("instantiate_opaque_types: bounds={:?}", bounds);
|
||||
@ -1173,7 +1173,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
// Change the predicate to refer to the type variable,
|
||||
// which will be the concrete type instead of the opaque type.
|
||||
// This also instantiates nested instances of `impl Trait`.
|
||||
let predicate = self.instantiate_opaque_types_in_map(&predicate);
|
||||
let predicate = self.instantiate_opaque_types_in_map(predicate);
|
||||
|
||||
let cause = traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);
|
||||
|
||||
|
@ -304,11 +304,8 @@ impl AutoTraitFinder<'tcx> {
|
||||
|
||||
// Call `infcx.resolve_vars_if_possible` to see if we can
|
||||
// get rid of any inference variables.
|
||||
let obligation = infcx.resolve_vars_if_possible(&Obligation::new(
|
||||
dummy_cause.clone(),
|
||||
new_env,
|
||||
pred,
|
||||
));
|
||||
let obligation =
|
||||
infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred));
|
||||
let result = select.select(&obligation);
|
||||
|
||||
match &result {
|
||||
@ -627,7 +624,7 @@ impl AutoTraitFinder<'tcx> {
|
||||
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate));
|
||||
|
||||
// Resolve any inference variables that we can, to help selection succeed
|
||||
let predicate = select.infcx().resolve_vars_if_possible(&obligation.predicate);
|
||||
let predicate = select.infcx().resolve_vars_if_possible(obligation.predicate);
|
||||
|
||||
// We only add a predicate as a user-displayable bound if
|
||||
// it involves a generic parameter, and doesn't contain
|
||||
|
@ -37,7 +37,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
obligation: PredicateObligation<'tcx>,
|
||||
) {
|
||||
assert!(!infcx.is_in_snapshot());
|
||||
let obligation = infcx.resolve_vars_if_possible(&obligation);
|
||||
let obligation = infcx.resolve_vars_if_possible(obligation);
|
||||
|
||||
self.obligations.insert(obligation);
|
||||
}
|
||||
@ -80,11 +80,11 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
// We iterate over all obligations, and record if we are able
|
||||
// to unambiguously prove at least one obligation.
|
||||
for obligation in self.obligations.drain(..) {
|
||||
let obligation = infcx.resolve_vars_if_possible(&obligation);
|
||||
let obligation = infcx.resolve_vars_if_possible(obligation);
|
||||
let environment = obligation.param_env.caller_bounds();
|
||||
let goal = ChalkEnvironmentAndGoal { environment, goal: obligation.predicate };
|
||||
let mut orig_values = OriginalQueryValues::default();
|
||||
let canonical_goal = infcx.canonicalize_query(&goal, &mut orig_values);
|
||||
let canonical_goal = infcx.canonicalize_query(goal, &mut orig_values);
|
||||
|
||||
match infcx.tcx.evaluate_goal(canonical_goal) {
|
||||
Ok(response) => {
|
||||
@ -100,7 +100,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
Ok(infer_ok) => next_round.extend(
|
||||
infer_ok.obligations.into_iter().map(|obligation| {
|
||||
assert!(!infcx.is_in_snapshot());
|
||||
infcx.resolve_vars_if_possible(&obligation)
|
||||
infcx.resolve_vars_if_possible(obligation)
|
||||
}),
|
||||
),
|
||||
|
||||
|
@ -25,7 +25,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
|
||||
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
|
||||
) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
|
||||
// Remove any references to regions; this helps improve caching.
|
||||
let trait_ref = tcx.erase_regions(&trait_ref);
|
||||
let trait_ref = tcx.erase_regions(trait_ref);
|
||||
// We expect the input to be fully normalized.
|
||||
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref));
|
||||
debug!(
|
||||
@ -89,7 +89,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
|
||||
debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
|
||||
fulfill_cx.register_predicate_obligation(&infcx, predicate);
|
||||
});
|
||||
let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, &impl_source);
|
||||
let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, impl_source);
|
||||
|
||||
info!("Cache miss: {:?} => {:?}", trait_ref, impl_source);
|
||||
Ok(impl_source)
|
||||
@ -110,7 +110,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
|
||||
fn drain_fulfillment_cx_or_panic<T>(
|
||||
infcx: &InferCtxt<'_, 'tcx>,
|
||||
fulfill_cx: &mut FulfillmentContext<'tcx>,
|
||||
result: &T,
|
||||
result: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
@ -128,5 +128,5 @@ where
|
||||
}
|
||||
|
||||
let result = infcx.resolve_vars_if_possible(result);
|
||||
infcx.tcx.erase_regions(&result)
|
||||
infcx.tcx.erase_regions(result)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
|
||||
};
|
||||
|
||||
let Normalized { value: mut header, obligations } =
|
||||
traits::normalize(selcx, param_env, ObligationCause::dummy(), &header);
|
||||
traits::normalize(selcx, param_env, ObligationCause::dummy(), header);
|
||||
|
||||
header.predicates.extend(obligations.into_iter().map(|o| o.predicate));
|
||||
header
|
||||
@ -162,7 +162,8 @@ fn overlap_within_probe(
|
||||
let opt_failing_obligation = a_impl_header
|
||||
.predicates
|
||||
.iter()
|
||||
.chain(&b_impl_header.predicates)
|
||||
.copied()
|
||||
.chain(b_impl_header.predicates)
|
||||
.map(|p| infcx.resolve_vars_if_possible(p))
|
||||
.map(|p| Obligation {
|
||||
cause: ObligationCause::dummy(),
|
||||
@ -188,7 +189,7 @@ fn overlap_within_probe(
|
||||
}
|
||||
}
|
||||
|
||||
let impl_header = selcx.infcx().resolve_vars_if_possible(&a_impl_header);
|
||||
let impl_header = selcx.infcx().resolve_vars_if_possible(a_impl_header);
|
||||
let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes();
|
||||
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
|
||||
|
||||
|
@ -182,7 +182,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
where
|
||||
T: fmt::Display + TypeFoldable<'tcx>,
|
||||
{
|
||||
let predicate = self.resolve_vars_if_possible(&obligation.predicate);
|
||||
let predicate = self.resolve_vars_if_possible(obligation.predicate.clone());
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
obligation.cause.span,
|
||||
@ -213,7 +213,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
/// we do not suggest increasing the overflow limit, which is not
|
||||
/// going to help).
|
||||
fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! {
|
||||
let cycle = self.resolve_vars_if_possible(&cycle.to_owned());
|
||||
let cycle = self.resolve_vars_if_possible(cycle.to_owned());
|
||||
assert!(!cycle.is_empty());
|
||||
|
||||
debug!("report_overflow_error_cycle: cycle={:?}", cycle);
|
||||
@ -259,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateAtom::Trait(trait_predicate, _) => {
|
||||
let trait_predicate = bound_predicate.rebind(trait_predicate);
|
||||
let trait_predicate = self.resolve_vars_if_possible(&trait_predicate);
|
||||
let trait_predicate = self.resolve_vars_if_possible(trait_predicate);
|
||||
|
||||
if self.tcx.sess.has_errors() && trait_predicate.references_error() {
|
||||
return;
|
||||
@ -414,17 +414,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
err.span_label(enclosing_scope_span, s.as_str());
|
||||
}
|
||||
|
||||
self.suggest_dereferences(&obligation, &mut err, &trait_ref, points_at_arg);
|
||||
self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);
|
||||
self.suggest_remove_reference(&obligation, &mut err, &trait_ref);
|
||||
self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref);
|
||||
self.suggest_dereferences(&obligation, &mut err, trait_ref, points_at_arg);
|
||||
self.suggest_fn_call(&obligation, &mut err, trait_ref, points_at_arg);
|
||||
self.suggest_remove_reference(&obligation, &mut err, trait_ref);
|
||||
self.suggest_semicolon_removal(&obligation, &mut err, span, trait_ref);
|
||||
self.note_version_mismatch(&mut err, &trait_ref);
|
||||
|
||||
if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() {
|
||||
self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span);
|
||||
self.suggest_await_before_try(&mut err, &obligation, trait_ref, span);
|
||||
}
|
||||
|
||||
if self.suggest_impl_trait(&mut err, span, &obligation, &trait_ref) {
|
||||
if self.suggest_impl_trait(&mut err, span, &obligation, trait_ref) {
|
||||
err.emit();
|
||||
return;
|
||||
}
|
||||
@ -487,7 +487,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
self.suggest_change_mut(
|
||||
&obligation,
|
||||
&mut err,
|
||||
&trait_ref,
|
||||
trait_ref,
|
||||
points_at_arg,
|
||||
);
|
||||
}
|
||||
@ -533,7 +533,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
ty::PredicateAtom::RegionOutlives(predicate) => {
|
||||
let predicate = bound_predicate.rebind(predicate);
|
||||
let predicate = self.resolve_vars_if_possible(&predicate);
|
||||
let predicate = self.resolve_vars_if_possible(predicate);
|
||||
let err = self
|
||||
.region_outlives_predicate(&obligation.cause, predicate)
|
||||
.err()
|
||||
@ -549,7 +549,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => {
|
||||
let predicate = self.resolve_vars_if_possible(&obligation.predicate);
|
||||
let predicate = self.resolve_vars_if_possible(obligation.predicate);
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
span,
|
||||
@ -671,9 +671,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => {
|
||||
let found_trait_ref = self.resolve_vars_if_possible(&*found_trait_ref);
|
||||
let expected_trait_ref = self.resolve_vars_if_possible(&*expected_trait_ref);
|
||||
OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => {
|
||||
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
|
||||
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
|
||||
|
||||
if expected_trait_ref.self_ty().references_error() {
|
||||
return;
|
||||
@ -1035,7 +1035,7 @@ trait InferCtxtPrivExt<'tcx> {
|
||||
fn mk_trait_obligation_with_new_self_ty(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
new_self_ty: Ty<'tcx>,
|
||||
) -> PredicateObligation<'tcx>;
|
||||
|
||||
@ -1157,7 +1157,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
error: &MismatchedProjectionTypes<'tcx>,
|
||||
) {
|
||||
let predicate = self.resolve_vars_if_possible(&obligation.predicate);
|
||||
let predicate = self.resolve_vars_if_possible(obligation.predicate);
|
||||
|
||||
if predicate.references_error() {
|
||||
return;
|
||||
@ -1178,7 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let (data, _) = self.replace_bound_vars_with_fresh_vars(
|
||||
obligation.cause.span,
|
||||
infer::LateBoundRegionConversionTime::HigherRankedType,
|
||||
&bound_predicate.rebind(data),
|
||||
bound_predicate.rebind(data),
|
||||
);
|
||||
let mut obligations = vec![];
|
||||
let normalized_ty = super::normalize_projection_type(
|
||||
@ -1343,7 +1343,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
// Sort impl candidates so that ordering is consistent for UI tests.
|
||||
let mut normalized_impl_candidates =
|
||||
impl_candidates.iter().map(normalize).collect::<Vec<String>>();
|
||||
impl_candidates.iter().copied().map(normalize).collect::<Vec<String>>();
|
||||
|
||||
// Sort before taking the `..end` range,
|
||||
// because the ordering of `impl_candidates` may not be deterministic:
|
||||
@ -1364,7 +1364,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
) -> Option<(String, Option<Span>)> {
|
||||
match code {
|
||||
&ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
match self.get_parent_trait_ref(&data.parent_code) {
|
||||
Some(t) => Some(t),
|
||||
None => {
|
||||
@ -1414,7 +1414,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
fn mk_trait_obligation_with_new_self_ty(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
new_self_ty: Ty<'tcx>,
|
||||
) -> PredicateObligation<'tcx> {
|
||||
assert!(!new_self_ty.has_escaping_bound_vars());
|
||||
@ -1441,7 +1441,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// ambiguous impls. The latter *ought* to be a
|
||||
// coherence violation, so we don't report it here.
|
||||
|
||||
let predicate = self.resolve_vars_if_possible(&obligation.predicate);
|
||||
let predicate = self.resolve_vars_if_possible(obligation.predicate);
|
||||
let span = obligation.cause.span;
|
||||
|
||||
debug!(
|
||||
@ -1673,7 +1673,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&mut selcx,
|
||||
param_env,
|
||||
ObligationCause::dummy(),
|
||||
&cleaned_pred,
|
||||
cleaned_pred,
|
||||
)
|
||||
.value;
|
||||
|
||||
@ -1808,7 +1808,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
cause_code: &ObligationCauseCode<'tcx>,
|
||||
) -> bool {
|
||||
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
|
||||
if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) {
|
||||
return true;
|
||||
|
@ -36,7 +36,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
) -> Option<DefId> {
|
||||
let tcx = self.tcx;
|
||||
let param_env = obligation.param_env;
|
||||
let trait_ref = tcx.erase_late_bound_regions(&trait_ref);
|
||||
let trait_ref = tcx.erase_late_bound_regions(trait_ref);
|
||||
let trait_self_ty = trait_ref.self_ty();
|
||||
|
||||
let mut self_match_impls = vec![];
|
||||
|
@ -49,7 +49,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
points_at_arg: bool,
|
||||
);
|
||||
|
||||
@ -64,7 +64,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
);
|
||||
|
||||
@ -81,14 +81,14 @@ pub trait InferCtxtExt<'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
);
|
||||
|
||||
fn suggest_change_mut(
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
);
|
||||
|
||||
@ -97,7 +97,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
);
|
||||
|
||||
fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span>;
|
||||
@ -107,7 +107,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) -> bool;
|
||||
|
||||
fn point_at_returns_when_relevant(
|
||||
@ -168,7 +168,7 @@ pub trait InferCtxtExt<'tcx> {
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
span: Span,
|
||||
);
|
||||
}
|
||||
@ -462,7 +462,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
points_at_arg: bool,
|
||||
) {
|
||||
// It only make sense when suggesting dereferences for arguments
|
||||
@ -475,7 +475,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let real_trait_ref = match &obligation.cause.code {
|
||||
ObligationCauseCode::ImplDerivedObligation(cause)
|
||||
| ObligationCauseCode::DerivedObligation(cause)
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(cause) => &cause.parent_trait_ref,
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(cause) => cause.parent_trait_ref,
|
||||
_ => trait_ref,
|
||||
};
|
||||
let real_ty = match real_trait_ref.self_ty().no_bound_vars() {
|
||||
@ -556,7 +556,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
) {
|
||||
let self_ty = match trait_ref.self_ty().no_bound_vars() {
|
||||
@ -734,7 +734,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) {
|
||||
let span = obligation.cause.span;
|
||||
|
||||
@ -797,7 +797,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
points_at_arg: bool,
|
||||
) {
|
||||
let span = obligation.cause.span;
|
||||
@ -832,7 +832,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
let new_obligation = self.mk_trait_obligation_with_new_self_ty(
|
||||
obligation.param_env,
|
||||
&trait_ref,
|
||||
trait_ref,
|
||||
suggested_ty,
|
||||
);
|
||||
let suggested_ty_would_satisfy_obligation = self
|
||||
@ -869,7 +869,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) {
|
||||
let is_empty_tuple =
|
||||
|ty: ty::Binder<Ty<'_>>| *ty.skip_binder().kind() == ty::Tuple(ty::List::empty());
|
||||
@ -919,7 +919,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
) -> bool {
|
||||
match obligation.cause.code.peel_derives() {
|
||||
// Only suggest `impl Trait` if the return type is unsized because it is `dyn Trait`.
|
||||
@ -976,12 +976,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
.returns
|
||||
.iter()
|
||||
.filter_map(|expr| typeck_results.node_type_opt(expr.hir_id))
|
||||
.map(|ty| self.resolve_vars_if_possible(&ty));
|
||||
.map(|ty| self.resolve_vars_if_possible(ty));
|
||||
let (last_ty, all_returns_have_same_type, only_never_return) = ret_types.clone().fold(
|
||||
(None, true, true),
|
||||
|(last_ty, mut same, only_never_return): (std::option::Option<Ty<'_>>, bool, bool),
|
||||
ty| {
|
||||
let ty = self.resolve_vars_if_possible(&ty);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
same &=
|
||||
!matches!(ty.kind(), ty::Error(_))
|
||||
&& last_ty.map_or(true, |last_ty| {
|
||||
@ -1133,7 +1133,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let typeck_results = self.in_progress_typeck_results.map(|t| t.borrow()).unwrap();
|
||||
for expr in &visitor.returns {
|
||||
if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) {
|
||||
let ty = self.resolve_vars_if_possible(&returned_ty);
|
||||
let ty = self.resolve_vars_if_possible(returned_ty);
|
||||
err.span_label(expr.span, &format!("this returned value is of type `{}`", ty));
|
||||
}
|
||||
}
|
||||
@ -1406,7 +1406,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
// Look for a type inside the generator interior that matches the target type to get
|
||||
// a span.
|
||||
let target_ty_erased = self.tcx.erase_regions(&target_ty);
|
||||
let target_ty_erased = self.tcx.erase_regions(target_ty);
|
||||
let ty_matches = |ty| -> bool {
|
||||
// Careful: the regions for types that appear in the
|
||||
// generator interior are not generally known, so we
|
||||
@ -1420,8 +1420,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// generator frame. Bound regions are preserved by
|
||||
// `erase_regions` and so we must also call
|
||||
// `erase_late_bound_regions`.
|
||||
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty));
|
||||
let ty_erased = self.tcx.erase_regions(&ty_erased);
|
||||
let ty_erased = self.tcx.erase_late_bound_regions(ty::Binder::bind(ty));
|
||||
let ty_erased = self.tcx.erase_regions(ty_erased);
|
||||
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
|
||||
debug!(
|
||||
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
|
||||
@ -1437,7 +1437,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
|
||||
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
|
||||
let upvar_ty = typeck_results.node_type(*upvar_id);
|
||||
let upvar_ty = self.resolve_vars_if_possible(&upvar_ty);
|
||||
let upvar_ty = self.resolve_vars_if_possible(upvar_ty);
|
||||
if ty_matches(&upvar_ty) {
|
||||
Some(GeneratorInteriorOrUpvar::Upvar(upvar.span))
|
||||
} else {
|
||||
@ -2010,7 +2010,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
err.note("shared static variables must have a type that implements `Sync`");
|
||||
}
|
||||
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
let ty = parent_trait_ref.skip_binder().self_ty();
|
||||
if parent_trait_ref.references_error() {
|
||||
err.cancel();
|
||||
@ -2025,8 +2025,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) =
|
||||
*data.parent_code
|
||||
{
|
||||
let parent_trait_ref =
|
||||
self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
let ty = parent_trait_ref.skip_binder().self_ty();
|
||||
matches!(ty.kind(), ty::Generator(..))
|
||||
|| matches!(ty.kind(), ty::Closure(..))
|
||||
@ -2056,7 +2055,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
ObligationCauseCode::ImplDerivedObligation(ref data) => {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
err.note(&format!(
|
||||
"required because of the requirements on the impl of `{}` for `{}`",
|
||||
parent_trait_ref.print_only_trait_path(),
|
||||
@ -2074,7 +2073,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
});
|
||||
}
|
||||
ObligationCauseCode::DerivedObligation(ref data) => {
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
|
||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||
let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx);
|
||||
// #74711: avoid a stack overflow
|
||||
ensure_sufficient_stack(|| {
|
||||
@ -2132,7 +2131,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
|
||||
trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
|
||||
span: Span,
|
||||
) {
|
||||
debug!(
|
||||
@ -2150,13 +2149,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind {
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||
|
||||
let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty());
|
||||
let self_ty = self.resolve_vars_if_possible(trait_ref.self_ty());
|
||||
|
||||
// Do not check on infer_types to avoid panic in evaluate_obligation.
|
||||
if self_ty.has_infer_types() {
|
||||
return;
|
||||
}
|
||||
let self_ty = self.tcx.erase_regions(&self_ty);
|
||||
let self_ty = self.tcx.erase_regions(self_ty);
|
||||
|
||||
let impls_future = self.tcx.type_implements_trait((
|
||||
future_trait,
|
||||
@ -2197,7 +2196,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
debug!(
|
||||
"suggest_await_before_try: normalized_projection_type {:?}",
|
||||
self.resolve_vars_if_possible(&normalized_ty)
|
||||
self.resolve_vars_if_possible(normalized_ty)
|
||||
);
|
||||
let try_obligation = self.mk_trait_obligation_with_new_self_ty(
|
||||
obligation.param_env,
|
||||
|
@ -202,7 +202,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
|
||||
) {
|
||||
// this helps to reduce duplicate errors, as well as making
|
||||
// debug output much nicer to read and so on.
|
||||
let obligation = infcx.resolve_vars_if_possible(&obligation);
|
||||
let obligation = infcx.resolve_vars_if_possible(obligation);
|
||||
|
||||
debug!(?obligation, "register_predicate_obligation");
|
||||
|
||||
@ -298,7 +298,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
|
||||
if !change {
|
||||
debug!(
|
||||
"process_predicate: pending obligation {:?} still stalled on {:?}",
|
||||
self.selcx.infcx().resolve_vars_if_possible(&pending_obligation.obligation),
|
||||
self.selcx.infcx().resolve_vars_if_possible(pending_obligation.obligation.clone()),
|
||||
pending_obligation.stalled_on
|
||||
);
|
||||
return ProcessResult::Unchanged;
|
||||
@ -338,14 +338,14 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
if obligation.predicate.has_infer_types_or_consts() {
|
||||
obligation.predicate =
|
||||
self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate);
|
||||
self.selcx.infcx().resolve_vars_if_possible(obligation.predicate);
|
||||
}
|
||||
|
||||
debug!(?obligation, ?obligation.cause, "process_obligation");
|
||||
|
||||
let infcx = self.selcx.infcx();
|
||||
|
||||
match obligation.predicate.kind() {
|
||||
match *obligation.predicate.kind() {
|
||||
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
|
||||
// Evaluation will discard candidates using the leak check.
|
||||
// This means we need to pass it the bound version of our
|
||||
@ -384,9 +384,9 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
||||
bug!("TypeWellFormedFromEnv is only used for Chalk")
|
||||
}
|
||||
},
|
||||
&ty::PredicateKind::Atom(atom) => match atom {
|
||||
ty::PredicateAtom::Trait(ref data, _) => {
|
||||
let trait_obligation = obligation.with(Binder::dummy(*data));
|
||||
ty::PredicateKind::Atom(atom) => match atom {
|
||||
ty::PredicateAtom::Trait(data, _) => {
|
||||
let trait_obligation = obligation.with(Binder::dummy(data));
|
||||
|
||||
self.process_trait_obligation(
|
||||
obligation,
|
||||
@ -639,7 +639,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
||||
|
||||
debug!(
|
||||
"process_predicate: pending obligation {:?} now stalled on {:?}",
|
||||
infcx.resolve_vars_if_possible(obligation),
|
||||
infcx.resolve_vars_if_possible(obligation.clone()),
|
||||
stalled_on
|
||||
);
|
||||
|
||||
@ -684,7 +684,7 @@ fn trait_ref_infer_vars<'a, 'tcx>(
|
||||
) -> Vec<TyOrConstInferVar<'tcx>> {
|
||||
selcx
|
||||
.infcx()
|
||||
.resolve_vars_if_possible(&trait_ref)
|
||||
.resolve_vars_if_possible(trait_ref)
|
||||
.skip_binder()
|
||||
.substs
|
||||
.iter()
|
||||
|
@ -50,7 +50,7 @@ pub fn can_type_implement_copy(
|
||||
let span = tcx.def_span(field.did);
|
||||
let cause = ObligationCause::dummy_with_span(span);
|
||||
let ctx = traits::FulfillmentContext::new();
|
||||
match traits::fully_normalize(&infcx, ctx, cause, param_env, &ty) {
|
||||
match traits::fully_normalize(&infcx, ctx, cause, param_env, ty) {
|
||||
Ok(ty) => {
|
||||
if !infcx.type_is_copy_modulo_regions(param_env, ty, span) {
|
||||
infringing.push(field);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user