1
Fork 0

compiler: fold by value

This commit is contained in:
Bastian Kauschke 2020-10-24 02:21:18 +02:00
parent 3ec6720bf1
commit 2bf93bd852
140 changed files with 679 additions and 699 deletions

View file

@ -92,7 +92,7 @@ fn make_mir_scope(
let callee = cx.tcx.subst_and_normalize_erasing_regions( let callee = cx.tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
&callee, callee,
); );
let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]); let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]);
cx.dbg_scope_fn(callee, &callee_fn_abi, None) cx.dbg_scope_fn(callee, &callee_fn_abi, None)

View file

@ -189,7 +189,7 @@ impl TypeMap<'ll, 'tcx> {
// something that provides more than the 64 bits of the DefaultHasher. // something that provides more than the 64 bits of the DefaultHasher.
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
let mut hcx = cx.tcx.create_stable_hashing_context(); 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.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
type_.hash_stable(hcx, &mut hasher); type_.hash_stable(hcx, &mut hasher);
@ -427,7 +427,7 @@ fn subroutine_type_metadata(
span: Span, span: Span,
) -> MetadataCreationResult<'ll> { ) -> MetadataCreationResult<'ll> {
let signature = 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( let signature_metadata: Vec<_> = iter::once(
// return type // return type

View file

@ -501,7 +501,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions( let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), 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, // Only "class" methods are generally understood by LLVM,

View file

@ -91,7 +91,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
}; };
let sig = callee_ty.fn_sig(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 arg_tys = sig.inputs();
let ret_ty = sig.output(); let ret_ty = sig.output();
let name = tcx.item_name(def_id); let name = tcx.item_name(def_id);
@ -777,8 +777,8 @@ fn generic_simd_intrinsic(
} }
let tcx = bx.tcx(); let tcx = bx.tcx();
let sig = tcx let sig =
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &callee_ty.fn_sig(tcx)); tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
let arg_tys = sig.inputs(); let arg_tys = sig.inputs();
let name_str = &*name.as_str(); let name_str = &*name.as_str();

View file

@ -252,7 +252,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
// Make sure lifetimes are erased, to avoid generating distinct LLVM // Make sure lifetimes are erased, to avoid generating distinct LLVM
// types for Rust types that only differ in the choice of lifetimes. // 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 mut defer = None;
let llty = if self.ty != normal_ty { let llty = if self.ty != normal_ty {

View file

@ -399,7 +399,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// late-bound regions, since late-bound // late-bound regions, since late-bound
// regions must appear in the argument // regions must appear in the argument
// listing. // 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) { let llfn = match cx.declare_c_main(llfty) {
Some(llfn) => llfn, Some(llfn) => llfn,

View file

@ -120,8 +120,8 @@ pub fn push_debuginfo_type_name<'tcx>(
} }
ty::Dynamic(ref trait_data, ..) => { ty::Dynamic(ref trait_data, ..) => {
if let Some(principal) = trait_data.principal() { if let Some(principal) = trait_data.principal() {
let principal = tcx let principal =
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &principal); tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
push_item_name(tcx, principal.def_id, false, output); push_item_name(tcx, principal.def_id, false, output);
push_type_params(tcx, principal.substs, output, visited); push_type_params(tcx, principal.substs, output, visited);
} else { } else {
@ -159,7 +159,7 @@ pub fn push_debuginfo_type_name<'tcx>(
output.push_str("fn("); 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() { if !sig.inputs().is_empty() {
for &parameter_type in sig.inputs() { for &parameter_type in sig.inputs() {
push_debuginfo_type_name(tcx, parameter_type, true, output, visited); push_debuginfo_type_name(tcx, parameter_type, true, output, visited);

View file

@ -24,7 +24,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
analyzer.visit_body(&mir); analyzer.visit_body(&mir);
for (local, decl) in mir.local_decls.iter_enumerated() { 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); debug!("local {:?} has type `{}`", local, ty);
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span); let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
if fx.cx.is_backend_immediate(layout) { if fx.cx.is_backend_immediate(layout) {
@ -121,10 +121,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
if is_consume { if is_consume {
let base_ty = let base_ty =
mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx()); 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. // 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; let span = self.fx.mir.local_decls[place_ref.local].source_info.span;
if cx.spanned_layout_of(elem_ty, span).is_zst() { if cx.spanned_layout_of(elem_ty, span).is_zst() {
return; return;
@ -313,7 +313,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
PlaceContext::MutatingUse(MutatingUseContext::Drop) => { PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
let ty = self.fx.mir.local_decls[local].ty; 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. // Only need the place if we're actually dropping it.
if self.fx.cx.type_needs_drop(ty) { if self.fx.cx.type_needs_drop(ty) {

View file

@ -306,7 +306,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
unwind: Option<mir::BasicBlock>, unwind: Option<mir::BasicBlock>,
) { ) {
let ty = location.ty(self.mir, bx.tcx()).ty; 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); let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def { 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() .iter()
.map(|op_arg| { .map(|op_arg| {
let op_ty = op_arg.ty(self.mir, bx.tcx()); let op_ty = op_arg.ty(self.mir, bx.tcx());
self.monomorphize(&op_ty) self.monomorphize(op_ty)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -900,7 +900,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }
} }
mir::InlineAsmOperand::SymFn { ref value } => { 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() { if let ty::FnDef(def_id, substs) = *literal.ty.kind() {
let instance = ty::Instance::resolve_for_fn_ptr( let instance = ty::Instance::resolve_for_fn_ptr(
bx.tcx(), bx.tcx(),

View file

@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
constant: &mir::Constant<'tcx>, constant: &mir::Constant<'tcx>,
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> { ) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
let val = self.eval_mir_constant(constant)?; 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)) Ok(OperandRef::from_const(bx, val, ty))
} }
@ -24,7 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self, &mut self,
constant: &mir::Constant<'tcx>, constant: &mir::Constant<'tcx>,
) -> Result<ConstValue<'tcx>, ErrorHandled> { ) -> Result<ConstValue<'tcx>, ErrorHandled> {
match self.monomorphize(&constant.literal).val { match self.monomorphize(constant.literal).val {
ty::ConstKind::Unevaluated(def, substs, promoted) => self ty::ConstKind::Unevaluated(def, substs, promoted) => self
.cx .cx
.tcx() .tcx()
@ -83,7 +83,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
bx.tcx().sess.span_err(span, "could not evaluate shuffle_indices at compile time"); 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. // 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)); let llty = bx.backend_type(bx.layout_of(ty));
(bx.const_undef(llty), ty) (bx.const_undef(llty), ty)
}) })

View file

@ -160,7 +160,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// FIXME(eddyb) is this `+ 1` needed at all? // FIXME(eddyb) is this `+ 1` needed at all?
let kind = VariableKind::ArgumentVariable(arg_index + 1); 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) self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span)
}, },

View file

@ -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 = 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 arg_tys = sig.inputs();
let ret_ty = sig.output(); let ret_ty = sig.output();
let name = bx.tcx().item_name(def_id); let name = bx.tcx().item_name(def_id);

View file

@ -87,7 +87,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
} }
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { 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 where
T: Copy + TypeFoldable<'tcx>, T: Copy + TypeFoldable<'tcx>,
{ {
@ -208,7 +208,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mut allocate_local = |local| { let mut allocate_local = |local| {
let decl = &mir.local_decls[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()); assert!(!layout.ty.has_erasable_regions());
if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() { 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 // to reconstruct it into a tuple local variable, from multiple
// individual LLVM function arguments. // 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() { let tupled_arg_tys = match arg_ty.kind() {
ty::Tuple(tys) => tys, ty::Tuple(tys) => tys,
_ => bug!("spread argument isn't a tuple?!"), _ => 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() { 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)); let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
bx.va_start(va_list.llval); bx.va_start(va_list.llval);

View file

@ -452,7 +452,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.abort(); bx.abort();
// We still have to return an operand but it doesn't matter, // We still have to return an operand but it doesn't matter,
// this code is unreachable. // 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); let layout = bx.cx().layout_of(ty);
bx.load_operand(PlaceRef::new_sized( bx.load_operand(PlaceRef::new_sized(
bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))), bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))),

View file

@ -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)); cg_base.project_index(bx, bx.cx().const_usize(from as u64));
let projected_ty = let projected_ty =
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem).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() { if subslice.layout.is_unsized() {
assert!(from_end, "slice subslices should be `from_end`"); 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> { pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> {
let tcx = self.cx.tcx(); let tcx = self.cx.tcx();
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, self.mir, 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)
} }
} }

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }
let count = 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) 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) => { mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => {
let operand = self.codegen_operand(&mut bx, source); let operand = self.codegen_operand(&mut bx, source);
debug!("cast operand is {:?}", operand); 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 { let val = match *kind {
mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => { 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) => { mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => {
let ty = self.monomorphize(&ty); let ty = self.monomorphize(ty);
assert!(bx.cx().type_is_sized(ty)); assert!(bx.cx().type_is_sized(ty));
let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes()); let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes());
let tcx = self.cx.tcx(); 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) => { 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 content_layout = bx.cx().layout_of(content_ty);
let llsize = bx.cx().const_usize(content_layout.size.bytes()); let llsize = bx.cx().const_usize(content_layout.size.bytes());
let llalign = bx.cx().const_usize(content_layout.align.abi.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. // aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(self.mir, self.cx.tcx()); let ty = rvalue.ty(self.mir, self.cx.tcx());
let operand = 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) (bx, operand)
} }
} }
@ -774,7 +774,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Repeat(..) | mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => { mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(self.mir, self.cx.tcx()); 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() self.cx.spanned_layout_of(ty, span).is_zst()
} }
} }

View file

@ -27,6 +27,7 @@
#![feature(extend_one)] #![feature(extend_one)]
#![feature(const_panic)] #![feature(const_panic)]
#![feature(min_const_generics)] #![feature(min_const_generics)]
#![feature(new_uninit)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_uninit_array)]
#![allow(rustc::default_hash_types)] #![allow(rustc::default_hash_types)]
@ -70,6 +71,7 @@ pub mod box_region;
pub mod captures; pub mod captures;
pub mod const_cstr; pub mod const_cstr;
pub mod flock; pub mod flock;
pub mod functor;
pub mod fx; pub mod fx;
pub mod graph; pub mod graph;
pub mod jobserver; pub mod jobserver;

View file

@ -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 /// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query
pub fn canonicalize_query<V>( pub fn canonicalize_query<V>(
&self, &self,
value: &V, value: V,
query_state: &mut OriginalQueryValues<'tcx>, query_state: &mut OriginalQueryValues<'tcx>,
) -> Canonicalized<'tcx, V> ) -> Canonicalized<'tcx, V>
where where
@ -80,7 +80,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// out the [chapter in the rustc dev guide][c]. /// 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 /// [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 where
V: TypeFoldable<'tcx>, 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 where
V: TypeFoldable<'tcx>, V: TypeFoldable<'tcx>,
{ {
@ -123,7 +123,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// and just use `canonicalize_query`. // and just use `canonicalize_query`.
pub fn canonicalize_hr_query_hack<V>( pub fn canonicalize_hr_query_hack<V>(
&self, &self,
value: &V, value: V,
query_state: &mut OriginalQueryValues<'tcx>, query_state: &mut OriginalQueryValues<'tcx>,
) -> Canonicalized<'tcx, V> ) -> Canonicalized<'tcx, V>
where where
@ -293,7 +293,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
self.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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -479,7 +479,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
/// The main `canonicalize` method, shared impl of /// The main `canonicalize` method, shared impl of
/// `canonicalize_query` and `canonicalize_response`. /// `canonicalize_query` and `canonicalize_response`.
fn canonicalize<V>( fn canonicalize<V>(
value: &V, value: V,
infcx: Option<&InferCtxt<'_, 'tcx>>, infcx: Option<&InferCtxt<'_, 'tcx>>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
canonicalize_region_mode: &dyn CanonicalizeRegionMode, canonicalize_region_mode: &dyn CanonicalizeRegionMode,

View file

@ -59,7 +59,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>, Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>,
{ {
let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?; 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); debug!("make_canonicalized_query_response: canonical_result = {:#?}", canonical_result);
@ -83,7 +83,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
where where
T: Debug + TypeFoldable<'tcx>, T: Debug + TypeFoldable<'tcx>,
{ {
self.canonicalize_response(&QueryResponse { self.canonicalize_response(QueryResponse {
var_values: inference_vars, var_values: inference_vars,
region_constraints: QueryRegionConstraints::default(), region_constraints: QueryRegionConstraints::default(),
certainty: Certainty::Proven, // Ambiguities are OK! certainty: Certainty::Proven, // Ambiguities are OK!
@ -176,7 +176,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
)); ));
let user_result: R = 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 }) 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() { for (index, original_value) in original_values.var_values.iter().enumerate() {
// ...with the value `v_r` of that variable from the query. // ...with the value `v_r` of that variable from the query.
let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| { 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()) { 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. // ...also include the other query region constraints from the query.
output_query_region_constraints.outlives.extend( 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); let r_c = substitute_value(self.tcx, &result_subst, r_c);
// Screen out `'a: 'a` cases -- we skip the binder here but // Screen out `'a: 'a` cases -- we skip the binder here but
@ -314,11 +314,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
.region_constraints .region_constraints
.member_constraints .member_constraints
.iter() .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 = 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 }) Ok(InferOk { value: user_result, obligations })
} }
@ -502,7 +502,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// `query_response.var_values` after applying the substitution // `query_response.var_values` after applying the substitution
// `result_subst`. // `result_subst`.
let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> { 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 // 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>], unsubstituted_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
result_subst: &'a CanonicalVarValues<'tcx>, result_subst: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'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) = let ty::OutlivesPredicate(k1, r2) =
substitute_value(self.tcx, result_subst, constraint).skip_binder(); substitute_value(self.tcx, result_subst, constraint).skip_binder();

View file

@ -28,7 +28,7 @@ pub(super) trait CanonicalExt<'tcx, V> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
var_values: &CanonicalVarValues<'tcx>, var_values: &CanonicalVarValues<'tcx>,
projection_fn: impl FnOnce(&V) -> &T, projection_fn: impl FnOnce(&V) -> T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>; T: TypeFoldable<'tcx>;
@ -39,14 +39,14 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
where where
V: TypeFoldable<'tcx>, V: TypeFoldable<'tcx>,
{ {
self.substitute_projected(tcx, var_values, |value| value) self.substitute_projected(tcx, var_values, |value| value.clone())
} }
fn substitute_projected<T>( fn substitute_projected<T>(
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
var_values: &CanonicalVarValues<'tcx>, var_values: &CanonicalVarValues<'tcx>,
projection_fn: impl FnOnce(&V) -> &T, projection_fn: impl FnOnce(&V) -> T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, 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` /// Substitute the values from `var_values` into `value`. `var_values`
/// must be values for the set of canonical variables that appear in /// must be values for the set of canonical variables that appear in
/// `value`. /// `value`.
pub(super) fn substitute_value<'a, 'tcx, T>( pub(super) fn substitute_value<'tcx, T>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
var_values: &CanonicalVarValues<'tcx>, var_values: &CanonicalVarValues<'tcx>,
value: &'a T, value: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
if var_values.var_values.is_empty() { if var_values.var_values.is_empty() {
value.clone() value
} else { } else {
let fld_r = let fld_r =
|br: ty::BoundRegion| match var_values.var_values[br.assert_bound_var()].unpack() { |br: ty::BoundRegion| match var_values.var_values[br.assert_bound_var()].unpack() {

View file

@ -389,7 +389,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
member_region, member_region,
span, 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( unexpected_hidden_region_diagnostic(
self.tcx, self.tcx,
span, span,
@ -590,7 +590,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) { ) {
match cause.code { match cause.code {
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => { 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() { if ty.is_suggestable() {
// don't show type `_` // don't show type `_`
err.span_label(span, format!("this expression has type `{}`", ty)); 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. // `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, Some(ty::error::ExpectedFound { expected, .. }) => expected,
_ => last_ty, _ => last_ty,
}); });
@ -1547,7 +1547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")), ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
_ => (false, Mismatch::Fixed("type")), _ => (false, Mismatch::Fixed("type")),
}; };
let vals = match self.values_str(&values) { let vals = match self.values_str(values) {
Some((expected, found)) => Some((expected, found)), Some((expected, found)) => Some((expected, found)),
None => { None => {
// Derived error. Cancel the emitter. // Derived error. Cancel the emitter.
@ -1893,32 +1893,32 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn values_str( fn values_str(
&self, &self,
values: &ValuePairs<'tcx>, values: ValuePairs<'tcx>,
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
match *values { match values {
infer::Types(ref exp_found) => self.expected_found_str_ty(exp_found), infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
infer::Regions(ref exp_found) => self.expected_found_str(exp_found), infer::Regions(exp_found) => self.expected_found_str(exp_found),
infer::Consts(ref exp_found) => self.expected_found_str(exp_found), infer::Consts(exp_found) => self.expected_found_str(exp_found),
infer::TraitRefs(ref exp_found) => { infer::TraitRefs(exp_found) => {
let pretty_exp_found = ty::error::ExpectedFound { let pretty_exp_found = ty::error::ExpectedFound {
expected: exp_found.expected.print_only_trait_path(), expected: exp_found.expected.print_only_trait_path(),
found: exp_found.found.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 { let pretty_exp_found = ty::error::ExpectedFound {
expected: exp_found.expected.print_only_trait_path(), expected: exp_found.expected.print_only_trait_path(),
found: exp_found.found.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( fn expected_found_str_ty(
&self, &self,
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>, exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
let exp_found = self.resolve_vars_if_possible(exp_found); let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() { if exp_found.references_error() {
@ -1931,7 +1931,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// Returns a string of the form "expected `{}`, found `{}`". /// Returns a string of the form "expected `{}`, found `{}`".
fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>( fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
&self, &self,
exp_found: &ty::error::ExpectedFound<T>, exp_found: ty::error::ExpectedFound<T>,
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
let exp_found = self.resolve_vars_if_possible(exp_found); let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() { if exp_found.references_error() {
@ -2180,7 +2180,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"...", "...",
); );
if let Some(infer::RelateParamBound(_, t)) = origin { 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() { match t.kind() {
// We've got: // We've got:
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ // 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); debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values);
if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) = 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 { if sub_expected == sup_expected && sub_found == sup_found {
note_and_explain_region( note_and_explain_region(

View file

@ -49,7 +49,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id)); .and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
match ty_opt { match ty_opt {
Some(ty) => { 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| { if ty.walk().any(|inner| {
inner == self.target inner == self.target
|| match (inner.unpack(), self.target.unpack()) { || match (inner.unpack(), self.target.unpack()) {
@ -343,7 +343,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
arg: GenericArg<'tcx>, arg: GenericArg<'tcx>,
error_code: TypeAnnotationNeeded, error_code: TypeAnnotationNeeded,
) -> DiagnosticBuilder<'tcx> { ) -> 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 arg_data = self.extract_inference_diagnostics_data(arg, None);
let kind_str = match arg.unpack() { let kind_str = match arg.unpack() {
GenericArgKind::Type(_) => "type", GenericArgKind::Type(_) => "type",
@ -686,7 +686,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
span: Span, span: Span,
ty: Ty<'tcx>, ty: Ty<'tcx>,
) -> DiagnosticBuilder<'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 data = self.extract_inference_diagnostics_data(ty.into(), None);
let mut err = struct_span_err!( let mut err = struct_span_err!(

View file

@ -234,14 +234,13 @@ impl NiceRegionError<'me, 'tcx> {
false 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, def_id: trait_def_id,
substs: expected_substs, substs: expected_substs,
}); });
let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { let actual_trait_ref = self
def_id: trait_def_id, .infcx
substs: actual_substs, .resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs });
});
// Search the expected and actual trait references to see (a) // Search the expected and actual trait references to see (a)
// whether the sub/sup placeholders appear in them (sometimes // whether the sub/sup placeholders appear in them (sometimes

View file

@ -414,7 +414,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
tcx, tcx,
ctxt.param_env, ctxt.param_env,
ctxt.assoc_item.def_id, 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, Ok(Some(instance)) => instance,
_ => return false, _ => return false,

View file

@ -86,7 +86,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
} }
if let Some((expected, found)) = 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. // Highlighted the differences when showing the "expected/found" note.
err.note_expected_found(&"", expected, &"", found); err.note_expected_found(&"", expected, &"", found);

View file

@ -55,12 +55,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let owner_id = hir.body_owner(body_id); let owner_id = hir.body_owner(body_id);
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
let poly_fn_sig = self.tcx().fn_sig(id); 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)| { body.params.iter().enumerate().find_map(|(index, param)| {
// May return None; sometimes the tables are not yet populated. // May return None; sometimes the tables are not yet populated.
let ty = fn_sig.inputs()[index]; let ty = fn_sig.inputs()[index];
let mut found_anon_region = false; 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 { if *r == *anon_region {
found_anon_region = true; found_anon_region = true;
replace_region replace_region

View file

@ -24,7 +24,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}; };
match *origin { match *origin {
infer::Subtype(ref trace) => { 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( label_or_note(
trace.cause.span, trace.cause.span,
&format!("...so that the {}", trace.cause.as_requirement_str()), &format!("...so that the {}", trace.cause.as_requirement_str()),

View file

@ -105,7 +105,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let (mut fudger, value) = self.probe(|_| { let (mut fudger, value) = self.probe(|_| {
match f() { match f() {
Ok(value) => { 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 // At this point, `value` could in principle refer
// to inference variables that have been created during // to inference variables that have been created during

View file

@ -33,14 +33,14 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
self.infcx.commit_if_ok(|_| { self.infcx.commit_if_ok(|_| {
// First, we instantiate each bound region in the supertype with a // First, we instantiate each bound region in the supertype with a
// fresh placeholder region. // 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 // Next, we instantiate each bound region in the subtype
// with a fresh region variable. These region variables -- // with a fresh region variable. These region variables --
// but no other pre-existing region variables -- can name // but no other pre-existing region variables -- can name
// the placeholders. // the placeholders.
let (a_prime, _) = 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!("a_prime={:?}", a_prime);
debug!("b_prime={:?}", b_prime); debug!("b_prime={:?}", b_prime);
@ -66,7 +66,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// the [rustc dev guide]. /// the [rustc dev guide].
/// ///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html /// [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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -113,10 +113,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
debug!( debug!(
"replace_bound_vars_with_placeholders(\ "replace_bound_vars_with_placeholders(\
next_universe={:?}, \ next_universe={:?}, \
binder={:?}, \
result={:?}, \ result={:?}, \
map={:?})", map={:?})",
next_universe, binder, result, map, next_universe, result, map,
); );
result result

View file

@ -1001,7 +1001,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
where where
T: TypeFoldable<'tcx>, 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), ty::ReVar(rid) => self.resolve_var(*rid),
_ => r, _ => r,
}) })

View file

@ -345,7 +345,7 @@ pub struct InferCtxt<'a, 'tcx> {
} }
/// See the `error_reporting` module for more details. /// 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> { pub enum ValuePairs<'tcx> {
Types(ExpectedFound<Ty<'tcx>>), Types(ExpectedFound<Ty<'tcx>>),
Regions(ExpectedFound<ty::Region<'tcx>>), Regions(ExpectedFound<ty::Region<'tcx>>),
@ -955,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
Some(self.commit_if_ok(|_snapshot| { Some(self.commit_if_ok(|_snapshot| {
let ty::SubtypePredicate { a_is_expected, a, b } = 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)?; 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> { ) -> UnitResult<'tcx> {
self.commit_if_ok(|_snapshot| { self.commit_if_ok(|_snapshot| {
let ty::OutlivesPredicate(r_a, r_b) = 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, || { let origin = SubregionOrigin::from_obligation_cause(cause, || {
RelateRegionParamBound(cause.span) RelateRegionParamBound(cause.span)
}); });
@ -1266,7 +1266,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { 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 { pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
@ -1274,7 +1274,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
format!("({})", tstrs.join(", ")) 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() 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 /// is left as is. This is an idempotent operation that does
/// not affect inference state in any way and so you can do it /// not affect inference state in any way and so you can do it
/// at will. /// 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 where
T: TypeFoldable<'tcx>, 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 * Attempts to resolve all type/region/const variables in
* `value`. Region inference must have been run already (e.g., * `value`. Region inference must have been run already (e.g.,
@ -1383,7 +1383,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
where where
M: FnOnce(String) -> DiagnosticBuilder<'tcx>, 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); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
// Don't report an error if actual type is `Error`. // Don't report an error if actual type is `Error`.
@ -1420,7 +1420,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&self, &self,
span: Span, span: Span,
lbrct: LateBoundRegionConversionTime, lbrct: LateBoundRegionConversionTime,
value: &ty::Binder<T>, value: ty::Binder<T>,
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -1508,7 +1508,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
span: Option<Span>, span: Option<Span>,
) -> EvalToConstValueResult<'tcx> { ) -> EvalToConstValueResult<'tcx> {
let mut original_values = OriginalQueryValues::default(); 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; let (param_env, substs) = canonical.value;
// The return value is the evaluated value which doesn't contain any reference to inference // The return value is the evaluated value which doesn't contain any reference to inference

View file

@ -167,7 +167,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
sup_type, sub_region, origin 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) { if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
let outlives = &mut TypeOutlives::new( let outlives = &mut TypeOutlives::new(
@ -205,7 +205,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
implicit_region_bound, implicit_region_bound,
param_env, 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); outlives.type_must_outlive(origin, ty, region);
} }
} }

View file

@ -124,10 +124,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
projection_ty: ty::ProjectionTy<'tcx>, projection_ty: ty::ProjectionTy<'tcx>,
) -> Vec<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> { ) -> Vec<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.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| { self.declared_generic_bounds_from_env_with_compare_fn(|ty| {
if let ty::Projection(..) = ty.kind() { 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 erased_ty == erased_projection_ty
} else { } else {
false false

View file

@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
/// Full type resolution replaces all type and region variables with /// Full type resolution replaces all type and region variables with
/// their concrete results. If any variable cannot be replaced (never unified, etc) /// their concrete results. If any variable cannot be replaced (never unified, etc)
/// then an `Err` result is returned. /// 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {

View file

@ -60,7 +60,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
// TypeFoldable implementations. // TypeFoldable implementations.
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> { 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 { traits::Obligation {
cause: self.cause.clone(), cause: self.cause.clone(),
recursion_depth: self.recursion_depth, recursion_depth: self.recursion_depth,

View file

@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>, pred: ty::Predicate<'tcx>,
) -> ty::Predicate<'tcx> { ) -> ty::Predicate<'tcx> {
match pred.kind() { match *pred.kind() {
ty::PredicateKind::ForAll(binder) => { ty::PredicateKind::ForAll(binder) => {
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder)); let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
tcx.reuse_or_mk_predicate(pred, new) tcx.reuse_or_mk_predicate(pred, new)

View file

@ -880,7 +880,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return FfiSafe; return FfiSafe;
} }
match ty.kind() { match *ty.kind() {
ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => { ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => {
FfiSafe 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() { if !sig.output().is_unit() {
let r = self.check_type_for_ffi(cache, sig.output()); let r = self.check_type_for_ffi(cache, sig.output());
match r { match r {
@ -1218,7 +1218,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) { fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) {
let def_id = self.cx.tcx.hir().local_def_id(id); 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.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) { 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); 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 { if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind {
let item_def_id = cx.tcx.hir().local_def_id(it.hir_id); let item_def_id = cx.tcx.hir().local_def_id(it.hir_id);
let t = cx.tcx.type_of(item_def_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) { let layout = match cx.layout_of(ty) {
Ok(layout) => layout, Ok(layout) => layout,
Err( Err(

View file

@ -6,6 +6,12 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
} }
s.add_bounds(synstructure::AddBounds::Generics); 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 body_fold = s.each_variant(|vi| {
let bindings = vi.bindings(); let bindings = vi.bindings();
vi.construct(|_, index| { 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( s.bound_impl(
quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>), quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>),
quote! { quote! {
fn super_fold_with<__F: ::rustc_middle::ty::fold::TypeFolder<'tcx>>( fn super_fold_with<__F: ::rustc_middle::ty::fold::TypeFolder<'tcx>>(
&self, self,
__folder: &mut __F __folder: &mut __F
) -> Self { ) -> Self {
match *self { #body_fold } match self { #body_fold }
} }
fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>( fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>(

View file

@ -53,10 +53,10 @@ macro_rules! CloneTypeFoldableImpls {
$( $(
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty { impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
fn super_fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>( fn super_fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>(
&self, self,
_: &mut F _: &mut F
) -> $ty { ) -> $ty {
Clone::clone(self) self
} }
fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>( fn super_visit_with<F: $crate::ty::fold::TypeVisitor<$tcx>>(
@ -96,7 +96,7 @@ macro_rules! EnumTypeFoldableImpl {
$(where $($wc)*)* $(where $($wc)*)*
{ {
fn super_fold_with<V: $crate::ty::fold::TypeFolder<$tcx>>( fn super_fold_with<V: $crate::ty::fold::TypeFolder<$tcx>>(
&self, self,
folder: &mut V, folder: &mut V,
) -> Self { ) -> Self {
EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output()) EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output())

View file

@ -67,7 +67,7 @@ impl<'tcx> TyCtxt<'tcx> {
) -> EvalToConstValueResult<'tcx> { ) -> EvalToConstValueResult<'tcx> {
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
// improve caching of queries. // improve caching of queries.
let inputs = self.erase_regions(&param_env.and(cid)); let inputs = self.erase_regions(param_env.and(cid));
if let Some(span) = span { if let Some(span) = span {
self.at(span).eval_to_const_value_raw(inputs) self.at(span).eval_to_const_value_raw(inputs)
} else { } else {

View file

@ -2455,7 +2455,7 @@ impl UserTypeProjection {
CloneTypeFoldableAndLiftImpls! { ProjectionKind, } CloneTypeFoldableAndLiftImpls! { ProjectionKind, }
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection { impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
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::*; use crate::mir::ProjectionElem::*;
let base = self.base.fold_with(folder); let base = self.base.fold_with(folder);

View file

@ -2,6 +2,7 @@
use super::*; use super::*;
use crate::ty; use crate::ty;
use rustc_data_structures::functor::IdFunctor;
CloneTypeFoldableAndLiftImpls! { CloneTypeFoldableAndLiftImpls! {
BlockTailInfo, BlockTailInfo,
@ -15,34 +16,33 @@ CloneTypeFoldableAndLiftImpls! {
} }
impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { 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::*; use crate::mir::TerminatorKind::*;
let kind = match self.kind { let kind = match self.kind {
Goto { target } => Goto { target }, Goto { target } => Goto { target },
SwitchInt { ref discr, switch_ty, ref targets } => SwitchInt { SwitchInt { discr, switch_ty, targets } => SwitchInt {
discr: discr.fold_with(folder), discr: discr.fold_with(folder),
switch_ty: switch_ty.fold_with(folder), switch_ty: switch_ty.fold_with(folder),
targets: targets.clone(), targets: targets.clone(),
}, },
Drop { ref place, target, unwind } => { Drop { place, target, unwind } => {
Drop { place: place.fold_with(folder), 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), place: place.fold_with(folder),
value: value.fold_with(folder), value: value.fold_with(folder),
target, target,
unwind, unwind,
}, },
Yield { ref value, resume, ref resume_arg, drop } => Yield { Yield { value, resume, resume_arg, drop } => Yield {
value: value.fold_with(folder), value: value.fold_with(folder),
resume, resume,
resume_arg: resume_arg.fold_with(folder), resume_arg: resume_arg.fold_with(folder),
drop, drop,
}, },
Call { ref func, ref args, ref destination, cleanup, from_hir_call, fn_span } => { Call { func, args, destination, cleanup, from_hir_call, fn_span } => {
let dest = let dest = destination.as_ref().map(|&(loc, dest)| (loc.fold_with(folder), dest));
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));
Call { Call {
func: func.fold_with(folder), func: func.fold_with(folder),
@ -53,13 +53,13 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
fn_span, fn_span,
} }
} }
Assert { ref cond, expected, ref msg, target, cleanup } => { Assert { cond, expected, msg, target, cleanup } => {
use AssertKind::*; use AssertKind::*;
let msg = match msg { let msg = match msg {
BoundsCheck { len, index } => { BoundsCheck { len, index } => {
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) } 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)), OverflowNeg(op) => OverflowNeg(op.fold_with(folder)),
DivisionByZero(op) => DivisionByZero(op.fold_with(folder)), DivisionByZero(op) => DivisionByZero(op.fold_with(folder)),
RemainderByZero(op) => RemainderByZero(op.fold_with(folder)), RemainderByZero(op) => RemainderByZero(op.fold_with(folder)),
@ -76,7 +76,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
FalseEdge { real_target, imaginary_target } FalseEdge { real_target, imaginary_target }
} }
FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind }, 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, template,
operands: operands.fold_with(folder), operands: operands.fold_with(folder),
options, options,
@ -140,8 +140,8 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
*self self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> { 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> { 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) } Place { local: self.local.fold_with(folder), projection: self.projection.fold_with(folder) }
} }
@ -161,7 +161,7 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<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 {
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>(); let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
folder.tcx().intern_place_elems(&v) folder.tcx().intern_place_elems(&v)
} }
@ -172,29 +172,25 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
} }
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'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::*; use crate::mir::Rvalue::*;
match *self { match self {
Use(ref op) => Use(op.fold_with(folder)), Use(op) => Use(op.fold_with(folder)),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)), Repeat(op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)), ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
Ref(region, bk, ref place) => { Ref(region, bk, place) => Ref(region.fold_with(folder), bk, place.fold_with(folder)),
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)),
AddressOf(mutability, ref place) => AddressOf(mutability, place.fold_with(folder)), Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
Len(ref place) => Len(place.fold_with(folder)), BinaryOp(op, rhs, lhs) => BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)),
Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)), CheckedBinaryOp(op, rhs, lhs) => {
BinaryOp(op, ref rhs, ref lhs) => {
BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
}
CheckedBinaryOp(op, ref rhs, ref lhs) => {
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)) CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder))
} }
UnaryOp(op, ref val) => UnaryOp(op, val.fold_with(folder)), UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)),
Discriminant(ref place) => Discriminant(place.fold_with(folder)), Discriminant(place) => Discriminant(place.fold_with(folder)),
NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)), NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)),
Aggregate(ref kind, ref fields) => { Aggregate(kind, fields) => {
let kind = box match **kind { let kind = kind.map_id(|kind| match kind {
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)), AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
AggregateKind::Tuple => AggregateKind::Tuple, AggregateKind::Tuple => AggregateKind::Tuple,
AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt( AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt(
@ -210,7 +206,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
AggregateKind::Generator(id, substs, movablity) => { AggregateKind::Generator(id, substs, movablity) => {
AggregateKind::Generator(id, substs.fold_with(folder), movablity) AggregateKind::Generator(id, substs.fold_with(folder), movablity)
} }
}; });
Aggregate(kind, fields.fold_with(folder)) Aggregate(kind, fields.fold_with(folder))
} }
} }
@ -263,11 +259,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { impl<'tcx> TypeFoldable<'tcx> for Operand<'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 { match self {
Operand::Copy(ref place) => Operand::Copy(place.fold_with(folder)), Operand::Copy(place) => Operand::Copy(place.fold_with(folder)),
Operand::Move(ref place) => Operand::Move(place.fold_with(folder)), Operand::Move(place) => Operand::Move(place.fold_with(folder)),
Operand::Constant(ref c) => Operand::Constant(c.fold_with(folder)), Operand::Constant(c) => Operand::Constant(c.fold_with(folder)),
} }
} }
@ -280,10 +276,10 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'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::*; use crate::mir::ProjectionElem::*;
match *self { match self {
Deref => Deref, Deref => Deref,
Field(f, ty) => Field(f, ty.fold_with(folder)), Field(f, ty) => Field(f, ty.fold_with(folder)),
Index(v) => Index(v.fold_with(folder)), Index(v) => Index(v.fold_with(folder)),
@ -307,8 +303,8 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for Field { impl<'tcx> TypeFoldable<'tcx> for Field {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
*self self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
ControlFlow::CONTINUE ControlFlow::CONTINUE
@ -316,8 +312,8 @@ impl<'tcx> TypeFoldable<'tcx> for Field {
} }
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal { impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
*self self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
ControlFlow::CONTINUE ControlFlow::CONTINUE
@ -325,7 +321,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
} }
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> { impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
self.clone() self.clone()
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
@ -334,7 +330,7 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
} }
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> { 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 { Constant {
span: self.span, span: self.span,
user_ty: self.user_ty.fold_with(folder), user_ty: self.user_ty.fold_with(folder),

View file

@ -367,7 +367,7 @@ rustc_queries! {
TypeChecking { TypeChecking {
/// Erases regions from `ty` to yield a new type. /// 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. /// however, which uses this query as a kind of cache.
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> { query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
// This query is not expected to have input -- as a result, it // This query is not expected to have input -- as a result, it

View file

@ -103,9 +103,9 @@ impl<'tcx> ConstKind<'tcx> {
// so that we don't try to invoke this query with // so that we don't try to invoke this query with
// any region variables. // any region variables.
let param_env_and_substs = tcx let param_env_and_substs = tcx
.erase_regions(&param_env) .erase_regions(param_env)
.with_reveal_all_normalized(tcx) .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, // HACK(eddyb) when the query key would contain inference variables,
// attempt using identity substs and `ParamEnv` instead, that will succeed // attempt using identity substs and `ParamEnv` instead, that will succeed

View file

@ -1495,7 +1495,7 @@ impl<'tcx> TyCtxt<'tcx> {
match ret_ty.kind() { match ret_ty.kind() {
ty::FnDef(_, _) => { ty::FnDef(_, _) => {
let sig = ret_ty.fn_sig(self); 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() { if output.is_impl_trait() {
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap(); let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
Some((output, fn_decl.output.span())) Some((output, fn_decl.output.span()))

View file

@ -15,17 +15,17 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns an equivalent value with all free regions removed (note /// Returns an equivalent value with all free regions removed (note
/// that late-bound regions remain, because they are important for /// that late-bound regions remain, because they are important for
/// subtyping, but they are anonymized and normalized as well).. /// 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
// If there's nothing to erase avoid performing the query at all // 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) { 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 }); let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self });
debug!("erase_regions({:?}) = {:?}", value, value1); debug!("erase_regions = {:?}", value1);
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) } 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {

View file

@ -44,8 +44,8 @@ use std::ops::ControlFlow;
/// ///
/// To implement this conveniently, use the derive macro located in librustc_macros. /// To implement this conveniently, use the derive macro located in librustc_macros.
pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn super_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 { fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
self.super_fold_with(folder) self.super_fold_with(folder)
} }
@ -158,8 +158,8 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
} }
impl TypeFoldable<'tcx> for hir::Constness { impl TypeFoldable<'tcx> for hir::Constness {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, _: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
*self self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
ControlFlow::CONTINUE ControlFlow::CONTINUE
@ -174,7 +174,7 @@ impl TypeFoldable<'tcx> for hir::Constness {
pub trait TypeFolder<'tcx>: Sized { pub trait TypeFolder<'tcx>: Sized {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>; 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -266,7 +266,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// and skipped. /// and skipped.
pub fn fold_regions<T>( pub fn fold_regions<T>(
self, self,
value: &T, value: T,
skipped_regions: &mut bool, skipped_regions: &mut bool,
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>, mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
) -> T ) -> T
@ -406,7 +406,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
self.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); self.current_index.shift_in(1);
let t = t.super_fold_with(self); let t = t.super_fold_with(self);
self.current_index.shift_out(1); self.current_index.shift_out(1);
@ -466,7 +466,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
self.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); self.current_index.shift_in(1);
let t = t.super_fold_with(self); let t = t.super_fold_with(self);
self.current_index.shift_out(1); self.current_index.shift_out(1);
@ -549,7 +549,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// contain escaping bound types. /// contain escaping bound types.
pub fn replace_late_bound_regions<T, F>( pub fn replace_late_bound_regions<T, F>(
self, self,
value: &Binder<T>, value: Binder<T>,
fld_r: F, fld_r: F,
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>) ) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
where where
@ -561,7 +561,7 @@ impl<'tcx> TyCtxt<'tcx> {
let fld_c = |bound_ct, ty| { let fld_c = |bound_ct, ty| {
self.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, 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 /// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
@ -569,7 +569,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// closure replaces escaping bound consts. /// closure replaces escaping bound consts.
pub fn replace_escaping_bound_vars<T, F, G, H>( pub fn replace_escaping_bound_vars<T, F, G, H>(
self, self,
value: &T, value: T,
mut fld_r: F, mut fld_r: F,
mut fld_t: G, mut fld_t: G,
mut fld_c: H, mut fld_c: H,
@ -609,7 +609,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// types. /// types.
pub fn replace_bound_vars<T, F, G, H>( pub fn replace_bound_vars<T, F, G, H>(
self, self,
value: &Binder<T>, value: Binder<T>,
fld_r: F, fld_r: F,
fld_t: G, fld_t: G,
fld_c: H, fld_c: H,
@ -620,16 +620,12 @@ impl<'tcx> TyCtxt<'tcx> {
H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>, H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
T: TypeFoldable<'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 /// Replaces any late-bound regions bound in `value` with
/// free variants attached to `all_outlive_scope`. /// free variants attached to `all_outlive_scope`.
pub fn liberate_late_bound_regions<T>( pub fn liberate_late_bound_regions<T>(self, all_outlive_scope: DefId, value: ty::Binder<T>) -> T
self,
all_outlive_scope: DefId,
value: &ty::Binder<T>,
) -> T
where where
T: TypeFoldable<'tcx>, 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 /// 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. /// 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 where
T: TypeFoldable<'tcx>, 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 /// `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 /// 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. /// `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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -740,7 +736,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
self.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); self.current_index.shift_in(1);
let t = t.super_fold_with(self); let t = t.super_fold_with(self);
self.current_index.shift_out(1); 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {

View file

@ -359,15 +359,15 @@ impl<'tcx> Instance<'tcx> {
// HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` // 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 // below is more likely to ignore the bounds in scope (e.g. if the only
// generic parameters mentioned by `substs` were lifetime ones). // 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()`? // FIXME(eddyb) should this always use `param_env.with_reveal_all()`?
if let Some((did, param_did)) = def.as_const_arg() { if let Some((did, param_did)) = def.as_const_arg() {
tcx.resolve_instance_of_const_arg( tcx.resolve_instance_of_const_arg(
tcx.erase_regions(&param_env.and((did, param_did, substs))), tcx.erase_regions(param_env.and((did, param_did, substs))),
) )
} else { } else {
tcx.resolve_instance(tcx.erase_regions(&param_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 self_ty = tcx.mk_closure(closure_did, substs);
let sig = substs.as_closure().sig(); 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); assert_eq!(sig.inputs().len(), 1);
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]); let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
@ -485,7 +485,7 @@ impl<'tcx> Instance<'tcx> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
v: &T, v: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx> + Clone, T: TypeFoldable<'tcx> + Clone,
@ -493,7 +493,7 @@ impl<'tcx> Instance<'tcx> {
if let Some(substs) = self.substs_for_mir_body() { if let Some(substs) = self.substs_for_mir_body() {
tcx.subst_and_normalize_erasing_regions(substs, param_env, v) tcx.subst_and_normalize_erasing_regions(substs, param_env, v)
} else { } else {
tcx.normalize_erasing_regions(param_env, v.clone()) tcx.normalize_erasing_regions(param_env, v)
} }
} }

View file

@ -1756,7 +1756,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
match tail.kind() { match tail.kind() {
ty::Param(_) | ty::Projection(_) => { ty::Param(_) | ty::Projection(_) => {
debug_assert!(tail.has_param_types_or_consts()); 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!( _ => bug!(
"SizeSkeleton::compute({}): layout errored ({}), yet \ "SizeSkeleton::compute({}): layout errored ({}), yet \
@ -2545,7 +2545,7 @@ where
) -> Self { ) -> Self {
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args); 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::*; use rustc_target::spec::abi::Abi::*;
let conv = match cx.tcx().sess.target.adjust_abi(sig.abi) { let conv = match cx.tcx().sess.target.adjust_abi(sig.abi) {

View file

@ -1788,7 +1788,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> 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)) ParamEnv::new(self.caller_bounds().fold_with(folder), self.reveal().fold_with(folder))
} }

View file

@ -30,7 +30,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Erase first before we do the real query -- this keeps the // Erase first before we do the real query -- this keeps the
// cache from being too polluted. // cache from being too polluted.
let value = self.erase_regions(&value); let value = self.erase_regions(value);
if !value.has_projections() { if !value.has_projections() {
value value
} else { } else {
@ -49,7 +49,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn normalize_erasing_late_bound_regions<T>( pub fn normalize_erasing_late_bound_regions<T>(
self, self,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &ty::Binder<T>, value: ty::Binder<T>,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -65,7 +65,7 @@ impl<'tcx> TyCtxt<'tcx> {
self, self,
param_substs: SubstsRef<'tcx>, param_substs: SubstsRef<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,

View file

@ -1750,7 +1750,7 @@ impl<F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
define_scoped_cx!(self); define_scoped_cx!(self);
let mut region_index = self.region_index; 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 _ = start_or_continue(&mut self, "for<", ", ");
let br = match br { let br = match br {
ty::BrNamed(_, name) => { ty::BrNamed(_, name) => {

View file

@ -7,6 +7,7 @@ use crate::mir::ProjectionKind;
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
use crate::ty::{self, InferConst, Lift, Ty, TyCtxt}; use crate::ty::{self, InferConst, Lift, Ty, TyCtxt};
use rustc_data_structures::functor::IdFunctor;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Namespace; use rustc_hir::def::Namespace;
use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_hir::def_id::CRATE_DEF_INDEX;
@ -725,8 +726,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
/// AdtDefs are basically the same as a DefId. /// AdtDefs are basically the same as a DefId.
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
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 self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {
@ -735,7 +736,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
} }
impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) { 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)) (self.0.fold_with(folder), self.1.fold_with(folder))
} }
@ -748,7 +749,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> impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx>
for (A, B, C) 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)) (self.0.fold_with(folder), self.1.fold_with(folder), self.2.fold_with(folder))
} }
@ -774,8 +775,9 @@ EnumTypeFoldableImpl! {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
Rc::new((**self).fold_with(folder)) // FIXME: Reuse the `Rc` here.
Rc::new((*self).clone().fold_with(folder))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -784,8 +786,9 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
Arc::new((**self).fold_with(folder)) // FIXME: Reuse the `Arc` here.
Arc::new((*self).clone().fold_with(folder))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -794,9 +797,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
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 content: T = (**self).fold_with(folder); self.map_id(|value| value.fold_with(folder))
box content
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -805,8 +807,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
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.iter().map(|t| t.fold_with(folder)).collect() self.map_id(|t| t.fold_with(folder))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -815,8 +817,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
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.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice() self.map_id(|t| t.fold_with(folder))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -825,11 +827,11 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
} }
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> { impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
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.map_bound_ref(|ty| ty.fold_with(folder)) 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) folder.fold_binder(self)
} }
@ -843,8 +845,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'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 {
fold_list(*self, folder, |tcx, v| tcx.intern_existential_predicates(v)) fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -853,8 +855,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>>
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'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 {
fold_list(*self, folder, |tcx, v| tcx.intern_type_list(v)) fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -863,8 +865,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
fold_list(*self, folder, |tcx, v| tcx.intern_projs(v)) fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -873,7 +875,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
} }
impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { 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::*; use crate::ty::InstanceDef::*;
Self { Self {
substs: self.substs.fold_with(folder), substs: self.substs.fold_with(folder),
@ -915,7 +917,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'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 } Self { instance: self.instance.fold_with(folder), promoted: self.promoted }
} }
@ -925,7 +927,7 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { impl<'tcx> TypeFoldable<'tcx> for Ty<'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 kind = match self.kind() { let kind = match self.kind() {
ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)), ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)), ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
@ -964,8 +966,8 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) } if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }
} }
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
folder.fold_ty(*self) folder.fold_ty(self)
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -1016,12 +1018,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::Region<'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 self
} }
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
folder.fold_region(*self) folder.fold_region(self)
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {
@ -1034,9 +1036,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'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 new = ty::PredicateKind::super_fold_with(&self.inner.kind, folder); let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder);
folder.tcx().reuse_or_mk_predicate(*self, new) folder.tcx().reuse_or_mk_predicate(self, new)
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -1057,8 +1059,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<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 { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v)) fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -1067,8 +1069,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> { 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 { fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
self.iter().map(|x| x.fold_with(folder)).collect() self.map_id(|x| x.fold_with(folder))
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -1077,18 +1079,18 @@ impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T>
} }
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> { 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 ty = self.ty.fold_with(folder);
let val = self.val.fold_with(folder); let val = self.val.fold_with(folder);
if ty != self.ty || val != self.val { if ty != self.ty || val != self.val {
folder.tcx().mk_const(ty::Const { ty, val }) folder.tcx().mk_const(ty::Const { ty, val })
} else { } else {
*self self
} }
} }
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self { fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
folder.fold_const(*self) folder.fold_const(self)
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@ -1102,8 +1104,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'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 { match self {
ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)), ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)),
ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)), ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)),
ty::ConstKind::Unevaluated(did, substs, promoted) => { ty::ConstKind::Unevaluated(did, substs, promoted) => {
@ -1112,7 +1114,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
ty::ConstKind::Value(_) ty::ConstKind::Value(_)
| ty::ConstKind::Bound(..) | ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(..) | ty::ConstKind::Placeholder(..)
| ty::ConstKind::Error(_) => *self, | ty::ConstKind::Error(_) => self,
} }
} }
@ -1130,8 +1132,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
} }
impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { impl<'tcx> TypeFoldable<'tcx> for InferConst<'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 self
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> { fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<()> {

View file

@ -1001,7 +1001,7 @@ impl<T> Binder<T> {
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
if value.has_escaping_bound_vars() { 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 { } else {
Binder::dummy(value) Binder::dummy(value)
} }

View file

@ -152,7 +152,7 @@ impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
} }
impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> { 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() { match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(), GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(),
GenericArgKind::Type(ty) => ty.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> { 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 // This code is hot enough that it's worth specializing for the most
// common length lists, to avoid the overhead of `SmallVec` creation. // 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 // 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). // there is more information available (for better errors).
pub trait Subst<'tcx>: Sized { 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) self.subst_spanned(tcx, substs, None)
} }
fn subst_spanned( fn subst_spanned(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
substs: &[GenericArg<'tcx>], substs: &[GenericArg<'tcx>],
span: Option<Span>, span: Option<Span>,
@ -419,13 +419,13 @@ pub trait Subst<'tcx>: Sized {
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T { impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
fn subst_spanned( fn subst_spanned(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
substs: &[GenericArg<'tcx>], substs: &[GenericArg<'tcx>],
span: Option<Span>, span: Option<Span>,
) -> T { ) -> T {
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 }; 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 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; self.binders_passed += 1;
let t = t.super_fold_with(self); let t = t.super_fold_with(self);
self.binders_passed -= 1; self.binders_passed -= 1;
@ -634,7 +634,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
return val; 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); debug!("shift_vars: shifted result = {:?}", result);
result result

View file

@ -160,7 +160,7 @@ impl<'tcx> TyCtxt<'tcx> {
// We want the type_id be independent of the types free regions, so we // We want the type_id be independent of the types free regions, so we
// erase them. The erase_regions() call will also anonymize bound // erase them. The erase_regions() call will also anonymize bound
// regions, which is desirable too. // regions, which is desirable too.
let ty = self.erase_regions(&ty); let ty = self.erase_regions(ty);
hcx.while_hashing_spans(false, |hcx| { hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {

View file

@ -876,7 +876,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
// Type-test failed. Report the error. // 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. // Skip duplicate-ish errors.
if deduplicate_errors.insert(( if deduplicate_errors.insert((
@ -1006,7 +1006,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!("try_promote_type_test_subject(ty = {:?})", ty); 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); let region_vid = self.to_region_vid(r);
// The challenge if this. We have some region variable `r` // The challenge if this. We have some region variable `r`
@ -1248,7 +1248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
where where
T: TypeFoldable<'tcx>, 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 vid = self.to_region_vid(r);
let scc = self.constraint_sccs.scc(vid); let scc = self.constraint_sccs.scc(vid);
let repr = self.scc_representatives[scc]; let repr = self.scc_representatives[scc];

View file

@ -63,7 +63,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let mut subst_regions = vec![self.universal_regions.fr_static]; let mut subst_regions = vec![self.universal_regions.fr_static];
let universal_substs = 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) => { ty::ReVar(vid) => {
subst_regions.push(vid); subst_regions.push(vid);
self.definitions[vid].external_name.unwrap_or_else(|| { self.definitions[vid].external_name.unwrap_or_else(|| {
@ -94,7 +94,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
subst_regions.dedup(); subst_regions.dedup();
let universal_concrete_type = 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 ty::ReVar(vid) => subst_regions
.iter() .iter()
.find(|ur_vid| self.eval_equal(vid, **ur_vid)) .find(|ur_vid| self.eval_equal(vid, **ur_vid))
@ -139,7 +139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
tcx.fold_regions(&ty, &mut false, |region, _| match *region { tcx.fold_regions(ty, &mut false, |region, _| match *region {
ty::ReVar(vid) => { ty::ReVar(vid) => {
// Find something that we can name // Find something that we can name
let upper_bound = self.approx_universal_upper_bound(vid); let upper_bound = self.approx_universal_upper_bound(vid);

View file

@ -26,7 +26,7 @@ pub fn renumber_mir<'tcx>(
/// Replaces all regions appearing in `value` with fresh inference /// Replaces all regions appearing in `value` with fresh inference
/// variables. /// 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -43,7 +43,7 @@ struct NLLVisitor<'a, 'tcx> {
} }
impl<'a, 'tcx> 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -70,7 +70,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
_: Location, _: Location,
) -> Option<PlaceElem<'tcx>> { ) -> Option<PlaceElem<'tcx>> {
if let PlaceElem::Field(field, ty) = elem { 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 { if new_ty != ty {
return Some(PlaceElem::Field(field, new_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) { fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
debug!("visit_substs(substs={:?}, location={:?})", substs, location); debug!("visit_substs(substs={:?}, location={:?})", substs, location);
*substs = self.renumber_regions(&{ *substs }); *substs = self.renumber_regions(*substs);
debug!("visit_substs: substs={:?}", substs); debug!("visit_substs: substs={:?}", substs);
} }

View file

@ -59,7 +59,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.replace_bound_vars_with_fresh_vars( .replace_bound_vars_with_fresh_vars(
body.span, body.span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
&poly_sig, poly_sig,
) )
.0, .0,
) )

View file

@ -784,7 +784,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
}; };
if let Some(field) = variant.fields.get(field.index()) { 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 { } else {
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() }) Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
} }
@ -1245,7 +1245,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
anon_owner_def_id, anon_owner_def_id,
dummy_body_id, dummy_body_id,
param_env, param_env,
&anon_ty, anon_ty,
locations.span(body), locations.span(body),
)); ));
debug!( debug!(
@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
); );
for (&opaque_def_id, opaque_decl) in &opaque_type_map { 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() { let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
*def_id == opaque_def_id *def_id == opaque_def_id
} else { } else {
@ -1296,7 +1296,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let subst_opaque_defn_ty = let subst_opaque_defn_ty =
opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs); opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs);
let renumbered_opaque_defn_ty = let renumbered_opaque_defn_ty =
renumber::renumber_regions(infcx, &subst_opaque_defn_ty); renumber::renumber_regions(infcx, subst_opaque_defn_ty);
debug!( debug!(
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}", "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( let (sig, map) = self.infcx.replace_bound_vars_with_fresh_vars(
term.source_info.span, term.source_info.span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
&sig, sig,
); );
let sig = self.normalize(sig, term_location); let sig = self.normalize(sig, term_location);
self.check_call_dest(body, term, &sig, destination, 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 // Erase the regions from `ty` to get a global type. The
// `Sized` bound in no way depends on precise regions, so this // `Sized` bound in no way depends on precise regions, so this
// shouldn't affect `is_sized`. // 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) { if !erased_ty.is_sized(tcx.at(span), self.param_env) {
// in current MIR construction, all non-control-flow rvalue // in current MIR construction, all non-control-flow rvalue
// expressions evaluate through `as_temp` or `into` a return // expressions evaluate through `as_temp` or `into` a return

View file

@ -438,7 +438,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars( let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
FR, FR,
self.mir_def.did, self.mir_def.did,
&bound_inputs_and_output, bound_inputs_and_output,
&mut indices, &mut indices,
); );
// Converse of above, if this is a function then the late-bound regions declared on its // 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); debug!("defining_ty (pre-replacement): {:?}", defining_ty);
let 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() { match *defining_ty.kind() {
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs), 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); 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 identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
let substs = 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) DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
} }
} }
@ -628,7 +628,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
DefiningTy::FnDef(def_id, _) => { DefiningTy::FnDef(def_id, _) => {
let sig = tcx.fn_sig(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() sig.inputs_and_output()
} }
@ -637,7 +637,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// "output" (the type of the constant). // "output" (the type of the constant).
assert_eq!(self.mir_def.did.to_def_id(), def_id); 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 = 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])) ty::Binder::dummy(tcx.intern_type_list(&[ty]))
} }
} }
@ -648,7 +648,7 @@ trait InferCtxtExt<'tcx> {
fn replace_free_regions_with_nll_infer_vars<T>( fn replace_free_regions_with_nll_infer_vars<T>(
&self, &self,
origin: NLLRegionVariableOrigin, origin: NLLRegionVariableOrigin,
value: &T, value: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>; T: TypeFoldable<'tcx>;
@ -657,7 +657,7 @@ trait InferCtxtExt<'tcx> {
&self, &self,
origin: NLLRegionVariableOrigin, origin: NLLRegionVariableOrigin,
all_outlive_scope: LocalDefId, all_outlive_scope: LocalDefId,
value: &ty::Binder<T>, value: ty::Binder<T>,
indices: &mut UniversalRegionIndices<'tcx>, indices: &mut UniversalRegionIndices<'tcx>,
) -> T ) -> T
where where
@ -674,7 +674,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
fn replace_free_regions_with_nll_infer_vars<T>( fn replace_free_regions_with_nll_infer_vars<T>(
&self, &self,
origin: NLLRegionVariableOrigin, origin: NLLRegionVariableOrigin,
value: &T, value: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -686,7 +686,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
&self, &self,
origin: NLLRegionVariableOrigin, origin: NLLRegionVariableOrigin,
all_outlive_scope: LocalDefId, all_outlive_scope: LocalDefId,
value: &ty::Binder<T>, value: ty::Binder<T>,
indices: &mut UniversalRegionIndices<'tcx>, indices: &mut UniversalRegionIndices<'tcx>,
) -> T ) -> T
where where
@ -771,7 +771,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// Replaces all free regions in `value` with region vids, as /// Replaces all free regions in `value` with region vids, as
/// returned by `to_region_vid`. /// 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 where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {

View file

@ -152,7 +152,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>(
let ty = place.ty(body, tcx).ty; let ty = place.ty(body, tcx).ty;
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, 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) { if erased_ty.needs_drop(tcx, ctxt.param_env) {
each_child(child); each_child(child);
} else { } else {

View file

@ -505,7 +505,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
value: T, value: T,
) -> 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). /// The `substs` are assumed to already be in our interpreter "universe" (param_env).

View file

@ -21,7 +21,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, Pointer<M::PointerTag>> { ) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
trace!("get_vtable(trait_ref={:?})", poly_trait_ref); 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. // All vtables must be monomorphic, bail out otherwise.
ensure_monomorphic_enough(*self.tcx, ty)?; 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 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 = 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) self.tcx.vtable_methods(trait_ref)
} else { } 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()?; let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;
trace!("Found drop fn: {:?}", drop_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 = 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. // The drop function takes `*mut T` where `T` is the type being dropped, so get that.
let args = fn_sig.inputs(); let args = fn_sig.inputs();
if args.len() != 1 { if args.len() != 1 {

View file

@ -546,7 +546,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
self.instance.subst_mir_and_normalize_erasing_regions( self.instance.subst_mir_and_normalize_erasing_regions(
self.tcx, self.tcx,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
&value, value,
) )
} }
} }
@ -1118,7 +1118,7 @@ impl RootCollector<'_, 'v> {
// late-bound regions, since late-bound // late-bound regions, since late-bound
// regions must appear in the argument // regions must appear in the argument
// listing. // 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( let start_instance = Instance::resolve(
self.tcx, self.tcx,

View file

@ -304,7 +304,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
let impl_self_ty = tcx.subst_and_normalize_erasing_regions( let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), 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) { if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
return Some(def_id); return Some(def_id);

View file

@ -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 // 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()) { 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(); 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 { 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) InternalSubsts::identity_for_item(tcx, def_id)
}; };
let sig = tcx.fn_sig(def_id).subst(tcx, substs); 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 span = tcx.def_span(def_id);
let source_info = SourceInfo::outermost(span); let source_info = SourceInfo::outermost(span);
@ -338,7 +338,7 @@ impl CloneShimBuilder<'tcx> {
// or access fields of a Place of type TySelf. // or access fields of a Place of type TySelf.
let substs = tcx.mk_substs_trait(self_ty, &[]); let substs = tcx.mk_substs_trait(self_ty, &[]);
let sig = tcx.fn_sig(def_id).subst(tcx, substs); 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 span = tcx.def_span(def_id);
CloneShimBuilder { 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 // 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`). // 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_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(); let untuple_args = sig.inputs();
@ -671,7 +671,7 @@ fn build_call_shim<'tcx>(
let def_id = instance.def_id(); let def_id = instance.def_id();
let sig = tcx.fn_sig(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()); assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
if let Some(sig_substs) = sig_substs { if let Some(sig_substs) = sig_substs {

View file

@ -720,13 +720,13 @@ fn sanitize_witness<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
witness: Ty<'tcx>, witness: Ty<'tcx>,
upvars: &Vec<Ty<'tcx>>, upvars: Vec<Ty<'tcx>>,
saved_locals: &GeneratorSavedLocals, saved_locals: &GeneratorSavedLocals,
) { ) {
let did = body.source.def_id(); let did = body.source.def_id();
let allowed_upvars = tcx.erase_regions(upvars); let allowed_upvars = tcx.erase_regions(upvars);
let allowed = match witness.kind() { 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( tcx.sess.delay_span_bug(
body.span, body.span,
@ -1303,7 +1303,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
let liveness_info = let liveness_info =
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable); 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 { if tcx.sess.opts.debugging_opts.validate_mir {
let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias { let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias {

View file

@ -122,7 +122,7 @@ impl Inliner<'tcx> {
let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions( let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions(
self.tcx, self.tcx,
self.param_env, self.param_env,
callee_body, callee_body.clone(),
); );
let old_blocks = caller_body.basic_blocks().next_index(); let old_blocks = caller_body.basic_blocks().next_index();

View file

@ -240,7 +240,7 @@ fn liberated_closure_env_ty(
}; };
let closure_env_ty = tcx.closure_env_ty(closure_def_id, closure_substs).unwrap(); 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)] #[derive(Debug, PartialEq, Eq)]

View file

@ -51,7 +51,7 @@ pub(super) fn mangle(
// Erase regions because they may not be deterministic when hashed // Erase regions because they may not be deterministic when hashed
// and should not matter anyhow. // 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); let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);

View file

@ -39,7 +39,7 @@ impl SymbolNamesTest<'tcx> {
let def_id = def_id.to_def_id(); let def_id = def_id.to_def_id();
let instance = Instance::new( let instance = Instance::new(
def_id, 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); let mangled = tcx.symbol_name(instance);
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled)); tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));

View file

@ -109,7 +109,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
param_env, param_env,
state: AutoderefSnapshot { state: AutoderefSnapshot {
steps: vec![], steps: vec![],
cur_ty: infcx.resolve_vars_if_possible(&base_ty), cur_ty: infcx.resolve_vars_if_possible(base_ty),
obligations: vec![], obligations: vec![],
at_start: true, at_start: true,
reached_recursion_limit: false, reached_recursion_limit: false,
@ -164,14 +164,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations); debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
self.state.obligations.extend(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 /// Returns the final type we ended up with, which may be an inference
/// variable (we will resolve it first, if we want). /// variable (we will resolve it first, if we want).
pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> { pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> {
if resolve { if resolve {
self.infcx.resolve_vars_if_possible(&self.state.cur_ty) self.infcx.resolve_vars_if_possible(self.state.cur_ty)
} else { } else {
self.state.cur_ty self.state.cur_ty
} }

View file

@ -28,7 +28,7 @@ pub trait InferCtxtExt<'tcx> {
span: Span, span: Span,
body_id: hir::HirId, body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
) -> InferOk<'tcx, T> ) -> InferOk<'tcx, T>
where where
T: TypeFoldable<'tcx>; T: TypeFoldable<'tcx>;
@ -41,7 +41,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
ty: Ty<'tcx>, ty: Ty<'tcx>,
span: Span, span: Span,
) -> bool { ) -> bool {
let ty = self.resolve_vars_if_possible(&ty); let ty = self.resolve_vars_if_possible(ty);
if !(param_env, ty).needs_infer() { if !(param_env, ty).needs_infer() {
return ty.is_copy_modulo_regions(self.tcx.at(span), param_env); 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, span: Span,
body_id: hir::HirId, body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
) -> InferOk<'tcx, T> ) -> InferOk<'tcx, T>
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -173,7 +173,7 @@ impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
debug!("add_implied_bounds()"); debug!("add_implied_bounds()");
for &ty in fn_sig_tys { 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); debug!("add_implied_bounds: ty = {}", ty);
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span); let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
self.add_outlives_bounds(Some(infcx), implied_bounds) self.add_outlives_bounds(Some(infcx), implied_bounds)

View file

@ -112,7 +112,7 @@ pub trait InferCtxtExt<'tcx> {
parent_def_id: LocalDefId, parent_def_id: LocalDefId,
body_id: hir::HirId, body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
value_span: Span, value_span: Span,
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>; ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>;
@ -188,7 +188,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
parent_def_id: LocalDefId, parent_def_id: LocalDefId,
body_id: hir::HirId, body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
value_span: Span, value_span: Span,
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> { ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
debug!( debug!(
@ -402,7 +402,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let tcx = self.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); debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
@ -1001,7 +1001,7 @@ struct Instantiator<'a, 'tcx> {
} }
impl<'a, 'tcx> 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); debug!("instantiate_opaque_types_in_map(value={:?})", value);
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
value.fold_with(&mut BottomUpFolder { value.fold_with(&mut BottomUpFolder {
@ -1125,7 +1125,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let param_env = tcx.param_env(def_id); let param_env = tcx.param_env(def_id);
let InferOk { value: bounds, obligations } = 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); self.obligations.extend(obligations);
debug!("instantiate_opaque_types: bounds={:?}", bounds); 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, // Change the predicate to refer to the type variable,
// which will be the concrete type instead of the opaque type. // which will be the concrete type instead of the opaque type.
// This also instantiates nested instances of `impl Trait`. // 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); let cause = traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);

View file

@ -304,11 +304,8 @@ impl AutoTraitFinder<'tcx> {
// Call `infcx.resolve_vars_if_possible` to see if we can // Call `infcx.resolve_vars_if_possible` to see if we can
// get rid of any inference variables. // get rid of any inference variables.
let obligation = infcx.resolve_vars_if_possible(&Obligation::new( let obligation =
dummy_cause.clone(), infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred));
new_env,
pred,
));
let result = select.select(&obligation); let result = select.select(&obligation);
match &result { match &result {
@ -627,7 +624,7 @@ impl AutoTraitFinder<'tcx> {
fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate)); fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate));
// Resolve any inference variables that we can, to help selection succeed // 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 // We only add a predicate as a user-displayable bound if
// it involves a generic parameter, and doesn't contain // it involves a generic parameter, and doesn't contain

View file

@ -37,7 +37,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
obligation: PredicateObligation<'tcx>, obligation: PredicateObligation<'tcx>,
) { ) {
assert!(!infcx.is_in_snapshot()); 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); 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 // We iterate over all obligations, and record if we are able
// to unambiguously prove at least one obligation. // to unambiguously prove at least one obligation.
for obligation in self.obligations.drain(..) { 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 environment = obligation.param_env.caller_bounds();
let goal = ChalkEnvironmentAndGoal { environment, goal: obligation.predicate }; let goal = ChalkEnvironmentAndGoal { environment, goal: obligation.predicate };
let mut orig_values = OriginalQueryValues::default(); 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) { match infcx.tcx.evaluate_goal(canonical_goal) {
Ok(response) => { Ok(response) => {
@ -100,7 +100,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
Ok(infer_ok) => next_round.extend( Ok(infer_ok) => next_round.extend(
infer_ok.obligations.into_iter().map(|obligation| { infer_ok.obligations.into_iter().map(|obligation| {
assert!(!infcx.is_in_snapshot()); assert!(!infcx.is_in_snapshot());
infcx.resolve_vars_if_possible(&obligation) infcx.resolve_vars_if_possible(obligation)
}), }),
), ),

View file

@ -25,7 +25,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>), (param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
) -> Result<ImplSource<'tcx, ()>, ErrorReported> { ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
// Remove any references to regions; this helps improve caching. // 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. // We expect the input to be fully normalized.
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref)); debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref));
debug!( debug!(
@ -89,7 +89,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate); debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
fulfill_cx.register_predicate_obligation(&infcx, 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); info!("Cache miss: {:?} => {:?}", trait_ref, impl_source);
Ok(impl_source) Ok(impl_source)
@ -110,7 +110,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
fn drain_fulfillment_cx_or_panic<T>( fn drain_fulfillment_cx_or_panic<T>(
infcx: &InferCtxt<'_, 'tcx>, infcx: &InferCtxt<'_, 'tcx>,
fulfill_cx: &mut FulfillmentContext<'tcx>, fulfill_cx: &mut FulfillmentContext<'tcx>,
result: &T, result: T,
) -> T ) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -128,5 +128,5 @@ where
} }
let result = infcx.resolve_vars_if_possible(result); let result = infcx.resolve_vars_if_possible(result);
infcx.tcx.erase_regions(&result) infcx.tcx.erase_regions(result)
} }

View file

@ -103,7 +103,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
}; };
let Normalized { value: mut header, obligations } = 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.predicates.extend(obligations.into_iter().map(|o| o.predicate));
header header
@ -162,7 +162,8 @@ fn overlap_within_probe(
let opt_failing_obligation = a_impl_header let opt_failing_obligation = a_impl_header
.predicates .predicates
.iter() .iter()
.chain(&b_impl_header.predicates) .copied()
.chain(b_impl_header.predicates)
.map(|p| infcx.resolve_vars_if_possible(p)) .map(|p| infcx.resolve_vars_if_possible(p))
.map(|p| Obligation { .map(|p| Obligation {
cause: ObligationCause::dummy(), 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(); let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes();
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes); debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);

View file

@ -182,7 +182,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
where where
T: fmt::Display + TypeFoldable<'tcx>, 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!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
obligation.cause.span, 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 /// we do not suggest increasing the overflow limit, which is not
/// going to help). /// going to help).
fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! { 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()); assert!(!cycle.is_empty());
debug!("report_overflow_error_cycle: cycle={:?}", cycle); 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() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
let trait_predicate = bound_predicate.rebind(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() { if self.tcx.sess.has_errors() && trait_predicate.references_error() {
return; return;
@ -414,17 +414,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
err.span_label(enclosing_scope_span, s.as_str()); err.span_label(enclosing_scope_span, s.as_str());
} }
self.suggest_dereferences(&obligation, &mut err, &trait_ref, points_at_arg); 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_fn_call(&obligation, &mut err, trait_ref, points_at_arg);
self.suggest_remove_reference(&obligation, &mut err, &trait_ref); self.suggest_remove_reference(&obligation, &mut err, trait_ref);
self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref); self.suggest_semicolon_removal(&obligation, &mut err, span, trait_ref);
self.note_version_mismatch(&mut err, &trait_ref); self.note_version_mismatch(&mut err, &trait_ref);
if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() { 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(); err.emit();
return; return;
} }
@ -487,7 +487,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
self.suggest_change_mut( self.suggest_change_mut(
&obligation, &obligation,
&mut err, &mut err,
&trait_ref, trait_ref,
points_at_arg, points_at_arg,
); );
} }
@ -533,7 +533,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::PredicateAtom::RegionOutlives(predicate) => { ty::PredicateAtom::RegionOutlives(predicate) => {
let predicate = bound_predicate.rebind(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 let err = self
.region_outlives_predicate(&obligation.cause, predicate) .region_outlives_predicate(&obligation.cause, predicate)
.err() .err()
@ -549,7 +549,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} }
ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => { 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!( struct_span_err!(
self.tcx.sess, self.tcx.sess,
span, span,
@ -672,8 +672,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} }
OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => { OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => {
let found_trait_ref = self.resolve_vars_if_possible(&*found_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); let expected_trait_ref = self.resolve_vars_if_possible(*expected_trait_ref);
if expected_trait_ref.self_ty().references_error() { if expected_trait_ref.self_ty().references_error() {
return; return;
@ -1035,7 +1035,7 @@ trait InferCtxtPrivExt<'tcx> {
fn mk_trait_obligation_with_new_self_ty( fn mk_trait_obligation_with_new_self_ty(
&self, &self,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
trait_ref: &ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
new_self_ty: Ty<'tcx>, new_self_ty: Ty<'tcx>,
) -> PredicateObligation<'tcx>; ) -> PredicateObligation<'tcx>;
@ -1157,7 +1157,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
error: &MismatchedProjectionTypes<'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() { if predicate.references_error() {
return; return;
@ -1178,7 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let (data, _) = self.replace_bound_vars_with_fresh_vars( let (data, _) = self.replace_bound_vars_with_fresh_vars(
obligation.cause.span, obligation.cause.span,
infer::LateBoundRegionConversionTime::HigherRankedType, infer::LateBoundRegionConversionTime::HigherRankedType,
&bound_predicate.rebind(data), bound_predicate.rebind(data),
); );
let mut obligations = vec![]; let mut obligations = vec![];
let normalized_ty = super::normalize_projection_type( 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. // Sort impl candidates so that ordering is consistent for UI tests.
let mut normalized_impl_candidates = 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, // Sort before taking the `..end` range,
// because the ordering of `impl_candidates` may not be deterministic: // 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>)> { ) -> Option<(String, Option<Span>)> {
match code { match code {
&ObligationCauseCode::BuiltinDerivedObligation(ref data) => { &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) { match self.get_parent_trait_ref(&data.parent_code) {
Some(t) => Some(t), Some(t) => Some(t),
None => { None => {
@ -1414,7 +1414,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
fn mk_trait_obligation_with_new_self_ty( fn mk_trait_obligation_with_new_self_ty(
&self, &self,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
trait_ref: &ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
new_self_ty: Ty<'tcx>, new_self_ty: Ty<'tcx>,
) -> PredicateObligation<'tcx> { ) -> PredicateObligation<'tcx> {
assert!(!new_self_ty.has_escaping_bound_vars()); 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 // ambiguous impls. The latter *ought* to be a
// coherence violation, so we don't report it here. // 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; let span = obligation.cause.span;
debug!( debug!(
@ -1673,7 +1673,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
&mut selcx, &mut selcx,
param_env, param_env,
ObligationCause::dummy(), ObligationCause::dummy(),
&cleaned_pred, cleaned_pred,
) )
.value; .value;
@ -1808,7 +1808,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
cause_code: &ObligationCauseCode<'tcx>, cause_code: &ObligationCauseCode<'tcx>,
) -> bool { ) -> bool {
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code { 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()) { if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) {
return true; return true;

View file

@ -36,7 +36,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) -> Option<DefId> { ) -> Option<DefId> {
let tcx = self.tcx; let tcx = self.tcx;
let param_env = obligation.param_env; 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 trait_self_ty = trait_ref.self_ty();
let mut self_match_impls = vec![]; let mut self_match_impls = vec![];

View file

@ -49,7 +49,7 @@ pub trait InferCtxtExt<'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>, err: &mut DiagnosticBuilder<'tcx>,
trait_ref: &ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
points_at_arg: bool, points_at_arg: bool,
); );
@ -64,7 +64,7 @@ pub trait InferCtxtExt<'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool, points_at_arg: bool,
); );
@ -81,14 +81,14 @@ pub trait InferCtxtExt<'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
); );
fn suggest_change_mut( fn suggest_change_mut(
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool, points_at_arg: bool,
); );
@ -97,7 +97,7 @@ pub trait InferCtxtExt<'tcx> {
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
span: Span, 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>; fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span>;
@ -107,7 +107,7 @@ pub trait InferCtxtExt<'tcx> {
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
span: Span, span: Span,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
) -> bool; ) -> bool;
fn point_at_returns_when_relevant( fn point_at_returns_when_relevant(
@ -168,7 +168,7 @@ pub trait InferCtxtExt<'tcx> {
&self, &self,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
span: Span, span: Span,
); );
} }
@ -462,7 +462,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>, err: &mut DiagnosticBuilder<'tcx>,
trait_ref: &ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
points_at_arg: bool, points_at_arg: bool,
) { ) {
// It only make sense when suggesting dereferences for arguments // 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 { let real_trait_ref = match &obligation.cause.code {
ObligationCauseCode::ImplDerivedObligation(cause) ObligationCauseCode::ImplDerivedObligation(cause)
| ObligationCauseCode::DerivedObligation(cause) | ObligationCauseCode::DerivedObligation(cause)
| ObligationCauseCode::BuiltinDerivedObligation(cause) => &cause.parent_trait_ref, | ObligationCauseCode::BuiltinDerivedObligation(cause) => cause.parent_trait_ref,
_ => trait_ref, _ => trait_ref,
}; };
let real_ty = match real_trait_ref.self_ty().no_bound_vars() { 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, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool, points_at_arg: bool,
) { ) {
let self_ty = match trait_ref.self_ty().no_bound_vars() { 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, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
) { ) {
let span = obligation.cause.span; let span = obligation.cause.span;
@ -797,7 +797,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool, points_at_arg: bool,
) { ) {
let span = obligation.cause.span; 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( let new_obligation = self.mk_trait_obligation_with_new_self_ty(
obligation.param_env, obligation.param_env,
&trait_ref, trait_ref,
suggested_ty, suggested_ty,
); );
let suggested_ty_would_satisfy_obligation = self let suggested_ty_would_satisfy_obligation = self
@ -869,7 +869,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
span: Span, span: Span,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
) { ) {
let is_empty_tuple = let is_empty_tuple =
|ty: ty::Binder<Ty<'_>>| *ty.skip_binder().kind() == ty::Tuple(ty::List::empty()); |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<'_>, err: &mut DiagnosticBuilder<'_>,
span: Span, span: Span,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
) -> bool { ) -> bool {
match obligation.cause.code.peel_derives() { match obligation.cause.code.peel_derives() {
// Only suggest `impl Trait` if the return type is unsized because it is `dyn Trait`. // 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 .returns
.iter() .iter()
.filter_map(|expr| typeck_results.node_type_opt(expr.hir_id)) .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( let (last_ty, all_returns_have_same_type, only_never_return) = ret_types.clone().fold(
(None, true, true), (None, true, true),
|(last_ty, mut same, only_never_return): (std::option::Option<Ty<'_>>, bool, bool), |(last_ty, mut same, only_never_return): (std::option::Option<Ty<'_>>, bool, bool),
ty| { ty| {
let ty = self.resolve_vars_if_possible(&ty); let ty = self.resolve_vars_if_possible(ty);
same &= same &=
!matches!(ty.kind(), ty::Error(_)) !matches!(ty.kind(), ty::Error(_))
&& last_ty.map_or(true, |last_ty| { && 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(); let typeck_results = self.in_progress_typeck_results.map(|t| t.borrow()).unwrap();
for expr in &visitor.returns { for expr in &visitor.returns {
if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) { 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)); 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 // Look for a type inside the generator interior that matches the target type to get
// a span. // 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 { let ty_matches = |ty| -> bool {
// Careful: the regions for types that appear in the // Careful: the regions for types that appear in the
// generator interior are not generally known, so we // 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 // generator frame. Bound regions are preserved by
// `erase_regions` and so we must also call // `erase_regions` and so we must also call
// `erase_late_bound_regions`. // `erase_late_bound_regions`.
let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty)); 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_regions(ty_erased);
let eq = ty::TyS::same_type(ty_erased, target_ty_erased); let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
debug!( debug!(
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \ "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) { if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| { interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
let upvar_ty = typeck_results.node_type(*upvar_id); 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) { if ty_matches(&upvar_ty) {
Some(GeneratorInteriorOrUpvar::Upvar(upvar.span)) Some(GeneratorInteriorOrUpvar::Upvar(upvar.span))
} else { } 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`"); err.note("shared static variables must have a type that implements `Sync`");
} }
ObligationCauseCode::BuiltinDerivedObligation(ref data) => { 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(); let ty = parent_trait_ref.skip_binder().self_ty();
if parent_trait_ref.references_error() { if parent_trait_ref.references_error() {
err.cancel(); err.cancel();
@ -2025,8 +2025,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = if let ObligationCauseCode::BuiltinDerivedObligation(ref data) =
*data.parent_code *data.parent_code
{ {
let parent_trait_ref = let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
self.resolve_vars_if_possible(&data.parent_trait_ref);
let ty = parent_trait_ref.skip_binder().self_ty(); let ty = parent_trait_ref.skip_binder().self_ty();
matches!(ty.kind(), ty::Generator(..)) matches!(ty.kind(), ty::Generator(..))
|| matches!(ty.kind(), ty::Closure(..)) || matches!(ty.kind(), ty::Closure(..))
@ -2056,7 +2055,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} }
} }
ObligationCauseCode::ImplDerivedObligation(ref data) => { 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!( err.note(&format!(
"required because of the requirements on the impl of `{}` for `{}`", "required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref.print_only_trait_path(), parent_trait_ref.print_only_trait_path(),
@ -2074,7 +2073,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}); });
} }
ObligationCauseCode::DerivedObligation(ref data) => { 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); let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx);
// #74711: avoid a stack overflow // #74711: avoid a stack overflow
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
@ -2132,7 +2131,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
&self, &self,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>, trait_ref: ty::Binder<ty::TraitRef<'tcx>>,
span: Span, span: Span,
) { ) {
debug!( debug!(
@ -2150,13 +2149,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind { if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind {
let future_trait = self.tcx.require_lang_item(LangItem::Future, None); 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. // Do not check on infer_types to avoid panic in evaluate_obligation.
if self_ty.has_infer_types() { if self_ty.has_infer_types() {
return; 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(( let impls_future = self.tcx.type_implements_trait((
future_trait, future_trait,
@ -2197,7 +2196,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
debug!( debug!(
"suggest_await_before_try: normalized_projection_type {:?}", "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( let try_obligation = self.mk_trait_obligation_with_new_self_ty(
obligation.param_env, obligation.param_env,

View file

@ -202,7 +202,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
) { ) {
// this helps to reduce duplicate errors, as well as making // this helps to reduce duplicate errors, as well as making
// debug output much nicer to read and so on. // 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"); debug!(?obligation, "register_predicate_obligation");
@ -298,7 +298,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
if !change { if !change {
debug!( debug!(
"process_predicate: pending obligation {:?} still stalled on {:?}", "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 pending_obligation.stalled_on
); );
return ProcessResult::Unchanged; return ProcessResult::Unchanged;
@ -338,14 +338,14 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
if obligation.predicate.has_infer_types_or_consts() { if obligation.predicate.has_infer_types_or_consts() {
obligation.predicate = 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"); debug!(?obligation, ?obligation.cause, "process_obligation");
let infcx = self.selcx.infcx(); let infcx = self.selcx.infcx();
match obligation.predicate.kind() { match *obligation.predicate.kind() {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
// Evaluation will discard candidates using the leak check. // Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our // 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") bug!("TypeWellFormedFromEnv is only used for Chalk")
} }
}, },
&ty::PredicateKind::Atom(atom) => match atom { ty::PredicateKind::Atom(atom) => match atom {
ty::PredicateAtom::Trait(ref data, _) => { ty::PredicateAtom::Trait(data, _) => {
let trait_obligation = obligation.with(Binder::dummy(*data)); let trait_obligation = obligation.with(Binder::dummy(data));
self.process_trait_obligation( self.process_trait_obligation(
obligation, obligation,
@ -639,7 +639,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
debug!( debug!(
"process_predicate: pending obligation {:?} now stalled on {:?}", "process_predicate: pending obligation {:?} now stalled on {:?}",
infcx.resolve_vars_if_possible(obligation), infcx.resolve_vars_if_possible(obligation.clone()),
stalled_on stalled_on
); );
@ -684,7 +684,7 @@ fn trait_ref_infer_vars<'a, 'tcx>(
) -> Vec<TyOrConstInferVar<'tcx>> { ) -> Vec<TyOrConstInferVar<'tcx>> {
selcx selcx
.infcx() .infcx()
.resolve_vars_if_possible(&trait_ref) .resolve_vars_if_possible(trait_ref)
.skip_binder() .skip_binder()
.substs .substs
.iter() .iter()

View file

@ -50,7 +50,7 @@ pub fn can_type_implement_copy(
let span = tcx.def_span(field.did); let span = tcx.def_span(field.did);
let cause = ObligationCause::dummy_with_span(span); let cause = ObligationCause::dummy_with_span(span);
let ctx = traits::FulfillmentContext::new(); 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) => { Ok(ty) => {
if !infcx.type_is_copy_modulo_regions(param_env, ty, span) { if !infcx.type_is_copy_modulo_regions(param_env, ty, span) {
infringing.push(field); infringing.push(field);

View file

@ -223,7 +223,7 @@ fn do_normalize_predicates<'tcx>(
// we move over to lazy normalization *anyway*. // we move over to lazy normalization *anyway*.
let fulfill_cx = FulfillmentContext::new_ignoring_regions(); let fulfill_cx = FulfillmentContext::new_ignoring_regions();
let predicates = let predicates =
match fully_normalize(&infcx, fulfill_cx, cause, elaborated_env, &predicates) { match fully_normalize(&infcx, fulfill_cx, cause, elaborated_env, predicates) {
Ok(predicates) => predicates, Ok(predicates) => predicates,
Err(errors) => { Err(errors) => {
infcx.report_fulfillment_errors(&errors, None, false); infcx.report_fulfillment_errors(&errors, None, false);
@ -243,7 +243,7 @@ fn do_normalize_predicates<'tcx>(
RegionckMode::default(), RegionckMode::default(),
); );
let predicates = match infcx.fully_resolve(&predicates) { let predicates = match infcx.fully_resolve(predicates) {
Ok(predicates) => predicates, Ok(predicates) => predicates,
Err(fixup_err) => { Err(fixup_err) => {
// If we encounter a fixup error, it means that some type // If we encounter a fixup error, it means that some type
@ -384,7 +384,7 @@ pub fn fully_normalize<'a, 'tcx, T>(
mut fulfill_cx: FulfillmentContext<'tcx>, mut fulfill_cx: FulfillmentContext<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
value: &T, value: T,
) -> Result<T, Vec<FulfillmentError<'tcx>>> ) -> Result<T, Vec<FulfillmentError<'tcx>>>
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -404,7 +404,7 @@ where
debug!("fully_normalize: select_all_or_error start"); debug!("fully_normalize: select_all_or_error start");
fulfill_cx.select_all_or_error(infcx)?; fulfill_cx.select_all_or_error(infcx)?;
debug!("fully_normalize: select_all_or_error complete"); debug!("fully_normalize: select_all_or_error complete");
let resolved_value = infcx.resolve_vars_if_possible(&normalized_value); let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
debug!("fully_normalize: resolved_value={:?}", resolved_value); debug!("fully_normalize: resolved_value={:?}", resolved_value);
Ok(resolved_value) Ok(resolved_value)
} }
@ -424,7 +424,7 @@ pub fn impossible_predicates<'tcx>(
let mut fulfill_cx = FulfillmentContext::new(); let mut fulfill_cx = FulfillmentContext::new();
let cause = ObligationCause::dummy(); let cause = ObligationCause::dummy();
let Normalized { value: predicates, obligations } = let Normalized { value: predicates, obligations } =
normalize(&mut selcx, param_env, cause.clone(), &predicates); normalize(&mut selcx, param_env, cause.clone(), predicates);
for obligation in obligations { for obligation in obligations {
fulfill_cx.register_predicate_obligation(&infcx, obligation); fulfill_cx.register_predicate_obligation(&infcx, obligation);
} }
@ -435,7 +435,7 @@ pub fn impossible_predicates<'tcx>(
fulfill_cx.select_all_or_error(&infcx).is_err() fulfill_cx.select_all_or_error(&infcx).is_err()
}); });
debug!("impossible_predicates(predicates={:?}) = {:?}", predicates, result); debug!("impossible_predicates = {:?}", result);
result result
} }
@ -494,7 +494,7 @@ fn vtable_methods<'tcx>(
// erase them if they appear, so that we get the type // erase them if they appear, so that we get the type
// at some particular call site. // at some particular call site.
let substs = let substs =
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &substs); tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), substs);
// It's possible that the method relies on where-clauses that // It's possible that the method relies on where-clauses that
// do not hold for this particular set of type parameters. // do not hold for this particular set of type parameters.

View file

@ -446,7 +446,7 @@ fn virtual_call_violation_for_method<'tcx>(
} }
let receiver_ty = let receiver_ty =
tcx.liberate_late_bound_regions(method.def_id, &sig.map_bound(|sig| sig.inputs()[0])); tcx.liberate_late_bound_regions(method.def_id, sig.map_bound(|sig| sig.inputs()[0]));
// Until `unsized_locals` is fully implemented, `self: Self` can't be dispatched on. // Until `unsized_locals` is fully implemented, `self: Self` can't be dispatched on.
// However, this is already considered object-safe. We allow it as a special case here. // However, this is already considered object-safe. We allow it as a special case here.

View file

@ -168,7 +168,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
let infcx = selcx.infcx(); let infcx = selcx.infcx();
infcx.commit_if_ok(|_snapshot| { infcx.commit_if_ok(|_snapshot| {
let placeholder_predicate = let placeholder_predicate =
infcx.replace_bound_vars_with_placeholders(&obligation.predicate); infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let placeholder_obligation = obligation.with(placeholder_predicate); let placeholder_obligation = obligation.with(placeholder_predicate);
let result = project_and_unify_type(selcx, &placeholder_obligation)?; let result = project_and_unify_type(selcx, &placeholder_obligation)?;
@ -232,7 +232,7 @@ pub fn normalize<'a, 'b, 'tcx, T>(
selcx: &'a mut SelectionContext<'b, 'tcx>, selcx: &'a mut SelectionContext<'b, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
value: &T, value: T,
) -> Normalized<'tcx, T> ) -> Normalized<'tcx, T>
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -246,7 +246,7 @@ pub fn normalize_to<'a, 'b, 'tcx, T>(
selcx: &'a mut SelectionContext<'b, 'tcx>, selcx: &'a mut SelectionContext<'b, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
value: &T, value: T,
obligations: &mut Vec<PredicateObligation<'tcx>>, obligations: &mut Vec<PredicateObligation<'tcx>>,
) -> T ) -> T
where where
@ -261,7 +261,7 @@ pub fn normalize_with_depth<'a, 'b, 'tcx, T>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
depth: usize, depth: usize,
value: &T, value: T,
) -> Normalized<'tcx, T> ) -> Normalized<'tcx, T>
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
@ -277,7 +277,7 @@ pub fn normalize_with_depth_to<'a, 'b, 'tcx, T>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
depth: usize, depth: usize,
value: &T, value: T,
obligations: &mut Vec<PredicateObligation<'tcx>>, obligations: &mut Vec<PredicateObligation<'tcx>>,
) -> T ) -> T
where where
@ -309,7 +309,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
AssocTypeNormalizer { selcx, param_env, cause, obligations, depth } AssocTypeNormalizer { selcx, param_env, cause, obligations, depth }
} }
fn fold<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T { fn fold<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
let value = self.selcx.infcx().resolve_vars_if_possible(value); let value = self.selcx.infcx().resolve_vars_if_possible(value);
if !value.has_projections() { value } else { value.fold_with(self) } if !value.has_projections() { value } else { value.fold_with(self) }
@ -474,7 +474,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
) -> Result<Option<Ty<'tcx>>, InProgress> { ) -> Result<Option<Ty<'tcx>>, InProgress> {
let infcx = selcx.infcx(); let infcx = selcx.infcx();
let projection_ty = infcx.resolve_vars_if_possible(&projection_ty); let projection_ty = infcx.resolve_vars_if_possible(projection_ty);
let cache_key = ProjectionCacheKey::new(projection_ty); let cache_key = ProjectionCacheKey::new(projection_ty);
// FIXME(#20304) For now, I am caching here, which is good, but it // FIXME(#20304) For now, I am caching here, which is good, but it
@ -567,7 +567,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
depth + 1, depth + 1,
&mut projected_obligations, &mut projected_obligations,
); );
let normalized_ty = normalizer.fold(&projected_ty); let normalized_ty = normalizer.fold(projected_ty);
debug!(?normalized_ty, ?depth); debug!(?normalized_ty, ?depth);
@ -1013,8 +1013,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
if obligation.param_env.reveal() == Reveal::All { if obligation.param_env.reveal() == Reveal::All {
// NOTE(eddyb) inference variables can resolve to parameters, so // NOTE(eddyb) inference variables can resolve to parameters, so
// assume `poly_trait_ref` isn't monomorphic, if it contains any. // assume `poly_trait_ref` isn't monomorphic, if it contains any.
let poly_trait_ref = let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(poly_trait_ref);
selcx.infcx().resolve_vars_if_possible(&poly_trait_ref);
!poly_trait_ref.still_further_specializable() !poly_trait_ref.still_further_specializable()
} else { } else {
debug!( debug!(
@ -1192,7 +1191,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&gen_sig, gen_sig,
); );
debug!(?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate"); debug!(?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate");
@ -1263,7 +1262,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>(
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&sig, sig,
); );
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes) confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
@ -1282,7 +1281,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&closure_sig, closure_sig,
); );
debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate"); debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate");
@ -1336,7 +1335,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
let (cache_entry, _) = infcx.replace_bound_vars_with_fresh_vars( let (cache_entry, _) = infcx.replace_bound_vars_with_fresh_vars(
cause.span, cause.span,
LateBoundRegionConversionTime::HigherRankedType, LateBoundRegionConversionTime::HigherRankedType,
&poly_cache_entry, poly_cache_entry,
); );
let cache_trait_ref = cache_entry.projection_ty.trait_ref(infcx.tcx); let cache_trait_ref = cache_entry.projection_ty.trait_ref(infcx.tcx);
@ -1349,7 +1348,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&cache_trait_ref, cache_trait_ref,
&mut nested_obligations, &mut nested_obligations,
) )
}) })
@ -1445,7 +1444,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&predicate, predicate,
nested, nested,
); );
nested.push(Obligation::with_depth( nested.push(Obligation::with_depth(
@ -1526,7 +1525,7 @@ impl<'tcx> ProjectionCacheKeyExt<'tcx> for ProjectionCacheKey<'tcx> {
// from a specific call to `opt_normalize_projection_type` - if // from a specific call to `opt_normalize_projection_type` - if
// there's no precise match, the original cache entry is "stranded" // there's no precise match, the original cache entry is "stranded"
// anyway. // anyway.
infcx.resolve_vars_if_possible(&predicate.projection_ty), infcx.resolve_vars_if_possible(predicate.projection_ty),
) )
}) })
} }

View file

@ -40,7 +40,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
} }
let mut orig_values = OriginalQueryValues::default(); let mut orig_values = OriginalQueryValues::default();
let c_ty = self.infcx.canonicalize_query(&self.param_env.and(ty), &mut orig_values); let c_ty = self.infcx.canonicalize_query(self.param_env.and(ty), &mut orig_values);
let span = self.cause.span; let span = self.cause.span;
debug!("c_ty = {:?}", c_ty); debug!("c_ty = {:?}", c_ty);
if let Ok(result) = &tcx.dropck_outlives(c_ty) { if let Ok(result) = &tcx.dropck_outlives(c_ty) {
@ -53,7 +53,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
result, result,
) )
{ {
let ty = self.infcx.resolve_vars_if_possible(&ty); let ty = self.infcx.resolve_vars_if_possible(ty);
let kinds = value.into_kinds_reporting_overflows(tcx, span, ty); let kinds = value.into_kinds_reporting_overflows(tcx, span, ty);
return InferOk { value: kinds, obligations }; return InferOk { value: kinds, obligations };
} }

View file

@ -65,7 +65,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
) -> Result<EvaluationResult, OverflowError> { ) -> Result<EvaluationResult, OverflowError> {
let mut _orig_values = OriginalQueryValues::default(); let mut _orig_values = OriginalQueryValues::default();
let c_pred = self let c_pred = self
.canonicalize_query(&obligation.param_env.and(obligation.predicate), &mut _orig_values); .canonicalize_query(obligation.param_env.and(obligation.predicate), &mut _orig_values);
// Run canonical query. If overflow occurs, rerun from scratch but this time // Run canonical query. If overflow occurs, rerun from scratch but this time
// in standard trait query mode so that overflow is handled appropriately // in standard trait query mode so that overflow is handled appropriately
// within `SelectionContext`. // within `SelectionContext`.

View file

@ -19,7 +19,7 @@ use super::NoSolution;
pub use rustc_middle::traits::query::NormalizationResult; pub use rustc_middle::traits::query::NormalizationResult;
pub trait AtExt<'tcx> { pub trait AtExt<'tcx> {
fn normalize<T>(&self, value: &T) -> Result<Normalized<'tcx, T>, NoSolution> fn normalize<T>(&self, value: T) -> Result<Normalized<'tcx, T>, NoSolution>
where where
T: TypeFoldable<'tcx>; T: TypeFoldable<'tcx>;
} }
@ -38,7 +38,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
/// normalizing, but for now should be used only when we actually /// normalizing, but for now should be used only when we actually
/// know that normalization will succeed, since error reporting /// know that normalization will succeed, since error reporting
/// and other details are still "under development". /// and other details are still "under development".
fn normalize<T>(&self, value: &T) -> Result<Normalized<'tcx, T>, NoSolution> fn normalize<T>(&self, value: T) -> Result<Normalized<'tcx, T>, NoSolution>
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
@ -165,7 +165,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
// so we cannot canonicalize it. // so we cannot canonicalize it.
let c_data = self let c_data = self
.infcx .infcx
.canonicalize_hr_query_hack(&self.param_env.and(*data), &mut orig_values); .canonicalize_hr_query_hack(self.param_env.and(*data), &mut orig_values);
debug!("QueryNormalizer: c_data = {:#?}", c_data); debug!("QueryNormalizer: c_data = {:#?}", c_data);
debug!("QueryNormalizer: orig_values = {:#?}", orig_values); debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
match tcx.normalize_projection_ty(c_data) { match tcx.normalize_projection_ty(c_data) {

View file

@ -51,7 +51,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
debug!("implied_outlives_bounds(ty = {:?})", ty); debug!("implied_outlives_bounds(ty = {:?})", ty);
let mut orig_values = OriginalQueryValues::default(); let mut orig_values = OriginalQueryValues::default();
let key = self.canonicalize_query(&param_env.and(ty), &mut orig_values); let key = self.canonicalize_query(param_env.and(ty), &mut orig_values);
let result = match self.tcx.implied_outlives_bounds(key) { let result = match self.tcx.implied_outlives_bounds(key) {
Ok(r) => r, Ok(r) => r,
Err(NoSolution) => { Err(NoSolution) => {

View file

@ -96,7 +96,7 @@ fn scrape_region_constraints<'tcx, R>(
region_obligations region_obligations
.iter() .iter()
.map(|(_, r_o)| (r_o.sup_type, r_o.sub_region)) .map(|(_, r_o)| (r_o.sup_type, r_o.sub_region))
.map(|(ty, r)| (infcx.resolve_vars_if_possible(&ty), r)), .map(|(ty, r)| (infcx.resolve_vars_if_possible(ty), r)),
&region_constraint_data, &region_constraint_data,
); );

View file

@ -82,7 +82,7 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
// `'static` otherwise. // `'static` otherwise.
let mut canonical_var_values = OriginalQueryValues::default(); let mut canonical_var_values = OriginalQueryValues::default();
let canonical_self = let canonical_self =
infcx.canonicalize_hr_query_hack(&query_key, &mut canonical_var_values); infcx.canonicalize_hr_query_hack(query_key.clone(), &mut canonical_var_values);
let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?; let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?;
let param_env = query_key.param_env; let param_env = query_key.param_env;

View file

@ -229,7 +229,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env: obligation.param_env, param_env: obligation.param_env,
cause: obligation.cause.clone(), cause: obligation.cause.clone(),
recursion_depth: obligation.recursion_depth, recursion_depth: obligation.recursion_depth,
predicate: self.infcx().resolve_vars_if_possible(&obligation.predicate), predicate: self.infcx().resolve_vars_if_possible(obligation.predicate),
}; };
if obligation.predicate.skip_binder().self_ty().is_ty_var() { if obligation.predicate.skip_binder().self_ty().is_ty_var() {
@ -604,7 +604,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// The code below doesn't care about regions, and the // The code below doesn't care about regions, and the
// self-ty here doesn't escape this probe, so just erase // self-ty here doesn't escape this probe, so just erase
// any LBR. // any LBR.
let self_ty = self.tcx().erase_late_bound_regions(&obligation.self_ty()); let self_ty = self.tcx().erase_late_bound_regions(obligation.self_ty());
let poly_trait_ref = match self_ty.kind() { let poly_trait_ref = match self_ty.kind() {
ty::Dynamic(ref data, ..) => { ty::Dynamic(ref data, ..) => {
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) { if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
@ -639,9 +639,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?poly_trait_ref, "assemble_candidates_from_object_ty"); debug!(?poly_trait_ref, "assemble_candidates_from_object_ty");
let poly_trait_predicate = self.infcx().resolve_vars_if_possible(&obligation.predicate); let poly_trait_predicate = self.infcx().resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(&poly_trait_predicate); self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate);
// Count only those upcast versions that match the trait-ref // Count only those upcast versions that match the trait-ref
// we are looking for. Specifically, do not only check for the // we are looking for. Specifically, do not only check for the

View file

@ -126,7 +126,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let trait_predicate = self.infcx.shallow_resolve(obligation.predicate); let trait_predicate = self.infcx.shallow_resolve(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(&trait_predicate); self.infcx().replace_bound_vars_with_placeholders(trait_predicate);
let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_self_ty = placeholder_trait_predicate.self_ty();
let (def_id, substs) = match *placeholder_self_ty.kind() { let (def_id, substs) = match *placeholder_self_ty.kind() {
ty::Projection(proj) => (proj.item_def_id, proj.substs), ty::Projection(proj) => (proj.item_def_id, proj.substs),
@ -144,7 +144,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&candidate, candidate,
&mut obligations, &mut obligations,
); );
@ -163,7 +163,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&predicate, predicate,
&mut obligations, &mut obligations,
); );
obligations.push(Obligation::with_depth( obligations.push(Obligation::with_depth(
@ -285,8 +285,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let trait_obligations: Vec<PredicateObligation<'_>> = let trait_obligations: Vec<PredicateObligation<'_>> =
self.infcx.commit_unconditionally(|_| { self.infcx.commit_unconditionally(|_| {
let poly_trait_ref = obligation.predicate.to_poly_trait_ref(); let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
let trait_ref = let trait_ref = self.infcx.replace_bound_vars_with_placeholders(poly_trait_ref);
self.infcx.replace_bound_vars_with_placeholders(&poly_trait_ref);
let cause = obligation.derived_cause(ImplDerivedObligation); let cause = obligation.derived_cause(ImplDerivedObligation);
self.impl_or_trait_obligations( self.impl_or_trait_obligations(
cause, cause,
@ -370,11 +369,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
debug!(?obligation, ?index, "confirm_object_candidate"); debug!(?obligation, ?index, "confirm_object_candidate");
let trait_predicate = let trait_predicate = self.infcx.replace_bound_vars_with_placeholders(obligation.predicate);
self.infcx.replace_bound_vars_with_placeholders(&obligation.predicate);
let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty()); let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty());
let obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref); let obligation_trait_ref = ty::Binder::dummy(trait_predicate.trait_ref);
let data = match self_ty.kind() { let data = match *self_ty.kind() {
ty::Dynamic(data, ..) => { ty::Dynamic(data, ..) => {
self.infcx self.infcx
.replace_bound_vars_with_fresh_vars( .replace_bound_vars_with_fresh_vars(
@ -416,7 +414,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&unnormalized_upcast_trait_ref, unnormalized_upcast_trait_ref,
&mut nested, &mut nested,
); );
@ -442,7 +440,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&super_trait, super_trait,
&mut nested, &mut nested,
); );
nested.push(Obligation::new( nested.push(Obligation::new(
@ -480,7 +478,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&subst_bound, subst_bound,
&mut nested, &mut nested,
); );
nested.push(Obligation::new( nested.push(Obligation::new(
@ -520,7 +518,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&trait_ref, trait_ref,
) )
}); });
@ -541,8 +539,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?obligation, ?alias_def_id, "confirm_trait_alias_candidate"); debug!(?obligation, ?alias_def_id, "confirm_trait_alias_candidate");
self.infcx.commit_unconditionally(|_| { self.infcx.commit_unconditionally(|_| {
let predicate = let predicate = self.infcx().replace_bound_vars_with_placeholders(obligation.predicate);
self.infcx().replace_bound_vars_with_placeholders(&obligation.predicate);
let trait_ref = predicate.trait_ref; let trait_ref = predicate.trait_ref;
let trait_def_id = trait_ref.def_id; let trait_def_id = trait_ref.def_id;
let substs = trait_ref.substs; let substs = trait_ref.substs;
@ -584,7 +581,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&trait_ref, trait_ref,
) )
}); });
@ -627,7 +624,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&trait_ref, trait_ref,
) )
}); });

View file

@ -1019,7 +1019,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
let obligation = &stack.obligation; let obligation = &stack.obligation;
let predicate = self.infcx().resolve_vars_if_possible(&obligation.predicate); let predicate = self.infcx().resolve_vars_if_possible(obligation.predicate);
// Okay to skip binder because of the nature of the // Okay to skip binder because of the nature of the
// trait-ref-is-knowable check, which does not care about // trait-ref-is-knowable check, which does not care about
@ -1138,9 +1138,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self, &mut self,
obligation: &TraitObligation<'tcx>, obligation: &TraitObligation<'tcx>,
) -> smallvec::SmallVec<[usize; 2]> { ) -> smallvec::SmallVec<[usize; 2]> {
let poly_trait_predicate = self.infcx().resolve_vars_if_possible(&obligation.predicate); let poly_trait_predicate = self.infcx().resolve_vars_if_possible(obligation.predicate);
let placeholder_trait_predicate = let placeholder_trait_predicate =
self.infcx().replace_bound_vars_with_placeholders(&poly_trait_predicate); self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate);
debug!( debug!(
?placeholder_trait_predicate, ?placeholder_trait_predicate,
"match_projection_obligation_against_definition_bounds" "match_projection_obligation_against_definition_bounds"
@ -1220,7 +1220,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&trait_bound, trait_bound,
) )
}); });
self.infcx self.infcx
@ -1266,12 +1266,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&data.map_bound_ref(|data| data.projection_ty), data.map_bound(|data| data.projection_ty),
&mut nested_obligations, &mut nested_obligations,
) )
}) })
} else { } else {
data.map_bound_ref(|data| data.projection_ty) data.map_bound(|data| data.projection_ty)
}; };
// FIXME(generic_associated_types): Compare the whole projections // FIXME(generic_associated_types): Compare the whole projections
@ -1737,7 +1737,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/ let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
self.infcx.commit_unconditionally(|_| { self.infcx.commit_unconditionally(|_| {
let placeholder_ty = self.infcx.replace_bound_vars_with_placeholders(&ty); let placeholder_ty = self.infcx.replace_bound_vars_with_placeholders(ty);
let Normalized { value: normalized_ty, mut obligations } = let Normalized { value: normalized_ty, mut obligations } =
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
project::normalize_with_depth( project::normalize_with_depth(
@ -1745,7 +1745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env, param_env,
cause.clone(), cause.clone(),
recursion_depth, recursion_depth,
&placeholder_ty, placeholder_ty,
) )
}); });
let placeholder_obligation = predicate_for_trait_def( let placeholder_obligation = predicate_for_trait_def(
@ -1807,7 +1807,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} }
let placeholder_obligation = let placeholder_obligation =
self.infcx().replace_bound_vars_with_placeholders(&obligation.predicate); self.infcx().replace_bound_vars_with_placeholders(obligation.predicate);
let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref; let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id); let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
@ -1821,7 +1821,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
&impl_trait_ref, impl_trait_ref,
) )
}); });
@ -2028,7 +2028,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env, param_env,
cause.clone(), cause.clone(),
recursion_depth, recursion_depth,
&predicate.subst(tcx, substs), predicate.subst(tcx, substs),
&mut obligations, &mut obligations,
); );
obligations.push(Obligation { obligations.push(Obligation {

View file

@ -158,7 +158,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
FulfillmentContext::new(), FulfillmentContext::new(),
ObligationCause::dummy(), ObligationCause::dummy(),
penv, penv,
&impl1_trait_ref, impl1_trait_ref,
) { ) {
Ok(impl1_trait_ref) => impl1_trait_ref, Ok(impl1_trait_ref) => impl1_trait_ref,
Err(err) => { Err(err) => {
@ -247,7 +247,7 @@ fn fulfill_implication<'a, 'tcx>(
// Now resolve the *substitution* we built for the target earlier, replacing // Now resolve the *substitution* we built for the target earlier, replacing
// the inference variables inside with whatever we got from fulfillment. // the inference variables inside with whatever we got from fulfillment.
Ok(infcx.resolve_vars_if_possible(&target_substs)) Ok(infcx.resolve_vars_if_possible(target_substs))
} }
} }
}) })

View file

@ -205,12 +205,12 @@ pub fn impl_trait_ref_and_oblig<'a, 'tcx>(
let impl_trait_ref = selcx.tcx().impl_trait_ref(impl_def_id).unwrap(); let impl_trait_ref = selcx.tcx().impl_trait_ref(impl_def_id).unwrap();
let impl_trait_ref = impl_trait_ref.subst(selcx.tcx(), impl_substs); let impl_trait_ref = impl_trait_ref.subst(selcx.tcx(), impl_substs);
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } = let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
super::normalize(selcx, param_env, ObligationCause::dummy(), &impl_trait_ref); super::normalize(selcx, param_env, ObligationCause::dummy(), impl_trait_ref);
let predicates = selcx.tcx().predicates_of(impl_def_id); let predicates = selcx.tcx().predicates_of(impl_def_id);
let predicates = predicates.instantiate(selcx.tcx(), impl_substs); let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
let Normalized { value: predicates, obligations: normalization_obligations2 } = let Normalized { value: predicates, obligations: normalization_obligations2 } =
super::normalize(selcx, param_env, ObligationCause::dummy(), &predicates); super::normalize(selcx, param_env, ObligationCause::dummy(), predicates);
let impl_obligations = let impl_obligations =
predicates_for_generics(ObligationCause::dummy(), 0, param_env, predicates); predicates_for_generics(ObligationCause::dummy(), 0, param_env, predicates);

View file

@ -269,7 +269,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
param_env, param_env,
cause.clone(), cause.clone(),
self.recursion_depth, self.recursion_depth,
&obligation.predicate, obligation.predicate,
&mut obligations, &mut obligations,
); );
obligation.predicate = normalized_predicate; obligation.predicate = normalized_predicate;

Some files were not shown because too many files have changed in this diff Show more