diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 6737872f203ad..7673dfb744c5a 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -92,7 +92,7 @@ fn make_mir_scope( let callee = cx.tcx.subst_and_normalize_erasing_regions( instance.substs, ty::ParamEnv::reveal_all(), - &callee, + callee, ); let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]); cx.dbg_scope_fn(callee, &callee_fn_abi, None) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 27b81ebcff676..5e8ff14f0aaa6 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -189,7 +189,7 @@ impl TypeMap<'ll, 'tcx> { // something that provides more than the 64 bits of the DefaultHasher. let mut hasher = StableHasher::new(); let mut hcx = cx.tcx.create_stable_hashing_context(); - let type_ = cx.tcx.erase_regions(&type_); + let type_ = cx.tcx.erase_regions(type_); hcx.while_hashing_spans(false, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { type_.hash_stable(hcx, &mut hasher); @@ -427,7 +427,7 @@ fn subroutine_type_metadata( span: Span, ) -> MetadataCreationResult<'ll> { let signature = - cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &signature); + cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), signature); let signature_metadata: Vec<_> = iter::once( // return type diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 5065ff01aed0d..ccbe7325cc6c2 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -501,7 +501,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions( instance.substs, ty::ParamEnv::reveal_all(), - &cx.tcx.type_of(impl_def_id), + cx.tcx.type_of(impl_def_id), ); // Only "class" methods are generally understood by LLVM, diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index d52b3be8cd356..ac423d01bf1fc 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -91,7 +91,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { }; let sig = callee_ty.fn_sig(tcx); - let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); + let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig); let arg_tys = sig.inputs(); let ret_ty = sig.output(); let name = tcx.item_name(def_id); @@ -777,8 +777,8 @@ fn generic_simd_intrinsic( } let tcx = bx.tcx(); - let sig = tcx - .normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &callee_ty.fn_sig(tcx)); + let sig = + tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx)); let arg_tys = sig.inputs(); let name_str = &*name.as_str(); diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index e0754d21df1f0..8ea4768f77dbd 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -252,7 +252,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { // Make sure lifetimes are erased, to avoid generating distinct LLVM // types for Rust types that only differ in the choice of lifetimes. - let normal_ty = cx.tcx.erase_regions(&self.ty); + let normal_ty = cx.tcx.erase_regions(self.ty); let mut defer = None; let llty = if self.ty != normal_ty { diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 5fe26dbf91402..21138f967a273 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -399,7 +399,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // late-bound regions, since late-bound // regions must appear in the argument // listing. - let main_ret_ty = cx.tcx().erase_regions(&main_ret_ty.no_bound_vars().unwrap()); + let main_ret_ty = cx.tcx().erase_regions(main_ret_ty.no_bound_vars().unwrap()); let llfn = match cx.declare_c_main(llfty) { Some(llfn) => llfn, diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 0b49a37907014..896af8a9191c2 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -120,8 +120,8 @@ pub fn push_debuginfo_type_name<'tcx>( } ty::Dynamic(ref trait_data, ..) => { if let Some(principal) = trait_data.principal() { - let principal = tcx - .normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &principal); + let principal = + tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal); push_item_name(tcx, principal.def_id, false, output); push_type_params(tcx, principal.substs, output, visited); } else { @@ -159,7 +159,7 @@ pub fn push_debuginfo_type_name<'tcx>( output.push_str("fn("); - let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); + let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig); if !sig.inputs().is_empty() { for ¶meter_type in sig.inputs() { push_debuginfo_type_name(tcx, parameter_type, true, output, visited); diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index bdde07d3fa9b0..44bb0deeae97f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -24,7 +24,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( analyzer.visit_body(&mir); for (local, decl) in mir.local_decls.iter_enumerated() { - let ty = fx.monomorphize(&decl.ty); + let ty = fx.monomorphize(decl.ty); debug!("local {:?} has type `{}`", local, ty); let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span); if fx.cx.is_backend_immediate(layout) { @@ -121,10 +121,10 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { if is_consume { let base_ty = mir::Place::ty_from(place_ref.local, proj_base, self.fx.mir, cx.tcx()); - let base_ty = self.fx.monomorphize(&base_ty); + let base_ty = self.fx.monomorphize(base_ty); // ZSTs don't require any actual memory access. - let elem_ty = base_ty.projection_ty(cx.tcx(), self.fx.monomorphize(&elem)).ty; + let elem_ty = base_ty.projection_ty(cx.tcx(), self.fx.monomorphize(elem)).ty; let span = self.fx.mir.local_decls[place_ref.local].source_info.span; if cx.spanned_layout_of(elem_ty, span).is_zst() { return; @@ -313,7 +313,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> PlaceContext::MutatingUse(MutatingUseContext::Drop) => { let ty = self.fx.mir.local_decls[local].ty; - let ty = self.fx.monomorphize(&ty); + let ty = self.fx.monomorphize(ty); // Only need the place if we're actually dropping it. if self.fx.cx.type_needs_drop(ty) { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index da4637b1afcfb..ee40095883ded 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -306,7 +306,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { unwind: Option, ) { let ty = location.ty(self.mir, bx.tcx()).ty; - let ty = self.monomorphize(&ty); + let ty = self.monomorphize(ty); let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def { @@ -576,7 +576,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .iter() .map(|op_arg| { let op_ty = op_arg.ty(self.mir, bx.tcx()); - self.monomorphize(&op_ty) + self.monomorphize(op_ty) }) .collect::>(); @@ -900,7 +900,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } mir::InlineAsmOperand::SymFn { ref value } => { - let literal = self.monomorphize(&value.literal); + let literal = self.monomorphize(value.literal); if let ty::FnDef(def_id, substs) = *literal.ty.kind() { let instance = ty::Instance::resolve_for_fn_ptr( bx.tcx(), diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index 4943e279c7e05..c8001b8daf0db 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -16,7 +16,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { constant: &mir::Constant<'tcx>, ) -> Result, ErrorHandled> { let val = self.eval_mir_constant(constant)?; - let ty = self.monomorphize(&constant.literal.ty); + let ty = self.monomorphize(constant.literal.ty); Ok(OperandRef::from_const(bx, val, ty)) } @@ -24,7 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, constant: &mir::Constant<'tcx>, ) -> Result, ErrorHandled> { - match self.monomorphize(&constant.literal).val { + match self.monomorphize(constant.literal).val { ty::ConstKind::Unevaluated(def, substs, promoted) => self .cx .tcx() @@ -83,7 +83,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .unwrap_or_else(|_| { bx.tcx().sess.span_err(span, "could not evaluate shuffle_indices at compile time"); // We've errored, so we don't have to produce working code. - let ty = self.monomorphize(&ty); + let ty = self.monomorphize(ty); let llty = bx.backend_type(bx.layout_of(ty)); (bx.const_undef(llty), ty) }) diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 4e0396a15a646..c4191a4e23d95 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -160,7 +160,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // FIXME(eddyb) is this `+ 1` needed at all? let kind = VariableKind::ArgumentVariable(arg_index + 1); - let arg_ty = self.monomorphize(&decl.ty); + let arg_ty = self.monomorphize(decl.ty); self.cx.create_dbg_var(name, arg_ty, dbg_scope, kind, span) }, diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 2bf1ee43c7366..94340e9204811 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -64,7 +64,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; let sig = callee_ty.fn_sig(bx.tcx()); - let sig = bx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); + let sig = bx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig); let arg_tys = sig.inputs(); let ret_ty = sig.output(); let name = bx.tcx().item_name(def_id); diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 01fd1681593e8..640f805d5e88f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -87,7 +87,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn monomorphize(&self, value: &T) -> T + pub fn monomorphize(&self, value: T) -> T where T: Copy + TypeFoldable<'tcx>, { @@ -208,7 +208,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut allocate_local = |local| { let decl = &mir.local_decls[local]; - let layout = bx.layout_of(fx.monomorphize(&decl.ty)); + let layout = bx.layout_of(fx.monomorphize(decl.ty)); assert!(!layout.ty.has_erasable_regions()); if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() { @@ -364,7 +364,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // to reconstruct it into a tuple local variable, from multiple // individual LLVM function arguments. - let arg_ty = fx.monomorphize(&arg_decl.ty); + let arg_ty = fx.monomorphize(arg_decl.ty); let tupled_arg_tys = match arg_ty.kind() { ty::Tuple(tys) => tys, _ => bug!("spread argument isn't a tuple?!"), @@ -385,7 +385,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } if fx.fn_abi.c_variadic && arg_index == fx.fn_abi.args.len() { - let arg_ty = fx.monomorphize(&arg_decl.ty); + let arg_ty = fx.monomorphize(arg_decl.ty); let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty)); bx.va_start(va_list.llval); diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index bbd004be87521..08a4ae3962bee 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -452,7 +452,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.abort(); // We still have to return an operand but it doesn't matter, // this code is unreachable. - let ty = self.monomorphize(&constant.literal.ty); + let ty = self.monomorphize(constant.literal.ty); let layout = bx.cx().layout_of(ty); bx.load_operand(PlaceRef::new_sized( bx.cx().const_undef(bx.cx().type_ptr_to(bx.cx().backend_type(layout))), diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index e1cc0268723a7..e4f4c884470c7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { cg_base.project_index(bx, bx.cx().const_usize(from as u64)); let projected_ty = PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem).ty; - subslice.layout = bx.cx().layout_of(self.monomorphize(&projected_ty)); + subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty)); if subslice.layout.is_unsized() { assert!(from_end, "slice subslices should be `from_end`"); @@ -515,6 +515,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> { let tcx = self.cx.tcx(); let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, self.mir, tcx); - self.monomorphize(&place_ty.ty) + self.monomorphize(place_ty.ty) } } diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 40ae0a13c7295..2ad470c2693de 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } let count = - self.monomorphize(&count).eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all()); + self.monomorphize(count).eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all()); bx.write_operand_repeatedly(cg_elem, count, dest) } @@ -181,7 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => { let operand = self.codegen_operand(&mut bx, source); debug!("cast operand is {:?}", operand); - let cast = bx.cx().layout_of(self.monomorphize(&mir_cast_ty)); + let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty)); let val = match *kind { mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => { @@ -502,7 +502,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => { - let ty = self.monomorphize(&ty); + let ty = self.monomorphize(ty); assert!(bx.cx().type_is_sized(ty)); let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes()); let tcx = self.cx.tcx(); @@ -516,7 +516,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => { - let content_ty = self.monomorphize(&content_ty); + let content_ty = self.monomorphize(content_ty); let content_layout = bx.cx().layout_of(content_ty); let llsize = bx.cx().const_usize(content_layout.size.bytes()); let llalign = bx.cx().const_usize(content_layout.align.abi.bytes()); @@ -554,7 +554,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // aggregate rvalues are allowed to be operands. let ty = rvalue.ty(self.mir, self.cx.tcx()); let operand = - OperandRef::new_zst(&mut bx, self.cx.layout_of(self.monomorphize(&ty))); + OperandRef::new_zst(&mut bx, self.cx.layout_of(self.monomorphize(ty))); (bx, operand) } } @@ -774,7 +774,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { let ty = rvalue.ty(self.mir, self.cx.tcx()); - let ty = self.monomorphize(&ty); + let ty = self.monomorphize(ty); self.cx.spanned_layout_of(ty, span).is_zst() } } diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 322c7a71160cd..6b952f20dd12b 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -27,6 +27,7 @@ #![feature(extend_one)] #![feature(const_panic)] #![feature(min_const_generics)] +#![feature(new_uninit)] #![feature(once_cell)] #![feature(maybe_uninit_uninit_array)] #![allow(rustc::default_hash_types)] @@ -70,6 +71,7 @@ pub mod box_region; pub mod captures; pub mod const_cstr; pub mod flock; +pub mod functor; pub mod fx; pub mod graph; pub mod jobserver; diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index f554b51800a72..6781fbc95c0ee 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -38,7 +38,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query pub fn canonicalize_query( &self, - value: &V, + value: V, query_state: &mut OriginalQueryValues<'tcx>, ) -> Canonicalized<'tcx, V> where @@ -80,7 +80,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// out the [chapter in the rustc dev guide][c]. /// /// [c]: https://rust-lang.github.io/chalk/book/canonical_queries/canonicalization.html#canonicalizing-the-query-result - pub fn canonicalize_response(&self, value: &V) -> Canonicalized<'tcx, V> + pub fn canonicalize_response(&self, value: V) -> Canonicalized<'tcx, V> where V: TypeFoldable<'tcx>, { @@ -94,7 +94,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { ) } - pub fn canonicalize_user_type_annotation(&self, value: &V) -> Canonicalized<'tcx, V> + pub fn canonicalize_user_type_annotation(&self, value: V) -> Canonicalized<'tcx, V> where V: TypeFoldable<'tcx>, { @@ -123,7 +123,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { // and just use `canonicalize_query`. pub fn canonicalize_hr_query_hack( &self, - value: &V, + value: V, query_state: &mut OriginalQueryValues<'tcx>, ) -> Canonicalized<'tcx, V> where @@ -293,7 +293,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { self.tcx } - fn fold_binder(&mut self, t: &ty::Binder) -> ty::Binder + fn fold_binder(&mut self, t: ty::Binder) -> ty::Binder where T: TypeFoldable<'tcx>, { @@ -479,7 +479,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { /// The main `canonicalize` method, shared impl of /// `canonicalize_query` and `canonicalize_response`. fn canonicalize( - value: &V, + value: V, infcx: Option<&InferCtxt<'_, 'tcx>>, tcx: TyCtxt<'tcx>, canonicalize_region_mode: &dyn CanonicalizeRegionMode, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 93e19521893ef..c8d66cbb695d8 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -59,7 +59,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx>, { let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?; - let canonical_result = self.canonicalize_response(&query_response); + let canonical_result = self.canonicalize_response(query_response); debug!("make_canonicalized_query_response: canonical_result = {:#?}", canonical_result); @@ -83,7 +83,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { where T: Debug + TypeFoldable<'tcx>, { - self.canonicalize_response(&QueryResponse { + self.canonicalize_response(QueryResponse { var_values: inference_vars, region_constraints: QueryRegionConstraints::default(), certainty: Certainty::Proven, // Ambiguities are OK! @@ -176,7 +176,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { )); let user_result: R = - query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value); + query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone()); Ok(InferOk { value: user_result, obligations }) } @@ -238,7 +238,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { for (index, original_value) in original_values.var_values.iter().enumerate() { // ...with the value `v_r` of that variable from the query. let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| { - &v.var_values[BoundVar::new(index)] + v.var_values[BoundVar::new(index)] }); match (original_value.unpack(), result_value.unpack()) { ( @@ -296,7 +296,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { // ...also include the other query region constraints from the query. output_query_region_constraints.outlives.extend( - query_response.value.region_constraints.outlives.iter().filter_map(|r_c| { + query_response.value.region_constraints.outlives.iter().filter_map(|&r_c| { let r_c = substitute_value(self.tcx, &result_subst, r_c); // Screen out `'a: 'a` cases -- we skip the binder here but @@ -314,11 +314,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { .region_constraints .member_constraints .iter() - .map(|p_c| substitute_value(self.tcx, &result_subst, p_c)), + .map(|p_c| substitute_value(self.tcx, &result_subst, p_c.clone())), ); let user_result: R = - query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value); + query_response.substitute_projected(self.tcx, &result_subst, |q_r| q_r.value.clone()); Ok(InferOk { value: user_result, obligations }) } @@ -502,7 +502,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { // `query_response.var_values` after applying the substitution // `result_subst`. let substituted_query_response = |index: BoundVar| -> GenericArg<'tcx> { - query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index]) + query_response.substitute_projected(self.tcx, &result_subst, |v| v.var_values[index]) }; // Unify the original value for each variable with the value @@ -524,7 +524,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { unsubstituted_region_constraints: &'a [QueryOutlivesConstraint<'tcx>], result_subst: &'a CanonicalVarValues<'tcx>, ) -> impl Iterator> + 'a + Captures<'tcx> { - unsubstituted_region_constraints.iter().map(move |constraint| { + unsubstituted_region_constraints.iter().map(move |&constraint| { let ty::OutlivesPredicate(k1, r2) = substitute_value(self.tcx, result_subst, constraint).skip_binder(); diff --git a/compiler/rustc_infer/src/infer/canonical/substitute.rs b/compiler/rustc_infer/src/infer/canonical/substitute.rs index 65791f6fc6523..cd4f1fa3bc30a 100644 --- a/compiler/rustc_infer/src/infer/canonical/substitute.rs +++ b/compiler/rustc_infer/src/infer/canonical/substitute.rs @@ -28,7 +28,7 @@ pub(super) trait CanonicalExt<'tcx, V> { &self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>, - projection_fn: impl FnOnce(&V) -> &T, + projection_fn: impl FnOnce(&V) -> T, ) -> T where T: TypeFoldable<'tcx>; @@ -39,14 +39,14 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> { where V: TypeFoldable<'tcx>, { - self.substitute_projected(tcx, var_values, |value| value) + self.substitute_projected(tcx, var_values, |value| value.clone()) } fn substitute_projected( &self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>, - projection_fn: impl FnOnce(&V) -> &T, + projection_fn: impl FnOnce(&V) -> T, ) -> T where T: TypeFoldable<'tcx>, @@ -60,16 +60,16 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> { /// Substitute the values from `var_values` into `value`. `var_values` /// must be values for the set of canonical variables that appear in /// `value`. -pub(super) fn substitute_value<'a, 'tcx, T>( +pub(super) fn substitute_value<'tcx, T>( tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>, - value: &'a T, + value: T, ) -> T where T: TypeFoldable<'tcx>, { if var_values.var_values.is_empty() { - value.clone() + value } else { let fld_r = |br: ty::BoundRegion| match var_values.var_values[br.assert_bound_var()].unpack() { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 524efd04cfce9..5a164635f4f66 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -389,7 +389,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { member_region, span, } => { - let hidden_ty = self.resolve_vars_if_possible(&hidden_ty); + let hidden_ty = self.resolve_vars_if_possible(hidden_ty); unexpected_hidden_region_diagnostic( self.tcx, span, @@ -590,7 +590,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ) { match cause.code { ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => { - let ty = self.resolve_vars_if_possible(&root_ty); + let ty = self.resolve_vars_if_possible(root_ty); if ty.is_suggestable() { // don't show type `_` err.span_label(span, format!("this expression has type `{}`", ty)); @@ -661,7 +661,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } _ => { // `last_ty` can be `!`, `expected` will have better info when present. - let t = self.resolve_vars_if_possible(&match exp_found { + let t = self.resolve_vars_if_possible(match exp_found { Some(ty::error::ExpectedFound { expected, .. }) => expected, _ => last_ty, }); @@ -1547,7 +1547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")), _ => (false, Mismatch::Fixed("type")), }; - let vals = match self.values_str(&values) { + let vals = match self.values_str(values) { Some((expected, found)) => Some((expected, found)), None => { // Derived error. Cancel the emitter. @@ -1893,32 +1893,32 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn values_str( &self, - values: &ValuePairs<'tcx>, + values: ValuePairs<'tcx>, ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { - match *values { - infer::Types(ref exp_found) => self.expected_found_str_ty(exp_found), - infer::Regions(ref exp_found) => self.expected_found_str(exp_found), - infer::Consts(ref exp_found) => self.expected_found_str(exp_found), - infer::TraitRefs(ref exp_found) => { + match values { + infer::Types(exp_found) => self.expected_found_str_ty(exp_found), + infer::Regions(exp_found) => self.expected_found_str(exp_found), + infer::Consts(exp_found) => self.expected_found_str(exp_found), + infer::TraitRefs(exp_found) => { let pretty_exp_found = ty::error::ExpectedFound { expected: exp_found.expected.print_only_trait_path(), found: exp_found.found.print_only_trait_path(), }; - self.expected_found_str(&pretty_exp_found) + self.expected_found_str(pretty_exp_found) } - infer::PolyTraitRefs(ref exp_found) => { + infer::PolyTraitRefs(exp_found) => { let pretty_exp_found = ty::error::ExpectedFound { expected: exp_found.expected.print_only_trait_path(), found: exp_found.found.print_only_trait_path(), }; - self.expected_found_str(&pretty_exp_found) + self.expected_found_str(pretty_exp_found) } } } fn expected_found_str_ty( &self, - exp_found: &ty::error::ExpectedFound>, + exp_found: ty::error::ExpectedFound>, ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { @@ -1931,7 +1931,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// Returns a string of the form "expected `{}`, found `{}`". fn expected_found_str>( &self, - exp_found: &ty::error::ExpectedFound, + exp_found: ty::error::ExpectedFound, ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { @@ -2180,7 +2180,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { "...", ); if let Some(infer::RelateParamBound(_, t)) = origin { - let t = self.resolve_vars_if_possible(&t); + let t = self.resolve_vars_if_possible(t); match t.kind() { // We've got: // fn get_later(g: G, dest: &mut T) -> impl FnOnce() + '_ @@ -2237,7 +2237,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { debug!("report_sub_sup_conflict: sub_trace.values={:?}", sub_trace.values); if let (Some((sup_expected, sup_found)), Some((sub_expected, sub_found))) = - (self.values_str(&sup_trace.values), self.values_str(&sub_trace.values)) + (self.values_str(sup_trace.values), self.values_str(sub_trace.values)) { if sub_expected == sup_expected && sub_found == sup_found { note_and_explain_region( diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 868989539d4fd..fd8f46a6926c0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> { .and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id)); match ty_opt { Some(ty) => { - let ty = self.infcx.resolve_vars_if_possible(&ty); + let ty = self.infcx.resolve_vars_if_possible(ty); if ty.walk().any(|inner| { inner == self.target || match (inner.unpack(), self.target.unpack()) { @@ -343,7 +343,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { arg: GenericArg<'tcx>, error_code: TypeAnnotationNeeded, ) -> DiagnosticBuilder<'tcx> { - let arg = self.resolve_vars_if_possible(&arg); + let arg = self.resolve_vars_if_possible(arg); let arg_data = self.extract_inference_diagnostics_data(arg, None); let kind_str = match arg.unpack() { GenericArgKind::Type(_) => "type", @@ -686,7 +686,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { span: Span, ty: Ty<'tcx>, ) -> DiagnosticBuilder<'tcx> { - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); let data = self.extract_inference_diagnostics_data(ty.into(), None); let mut err = struct_span_err!( diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 2187064ec5ecf..e8e0326d97865 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -234,14 +234,13 @@ impl NiceRegionError<'me, 'tcx> { false }; - let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { + let expected_trait_ref = self.infcx.resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: expected_substs, }); - let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { - def_id: trait_def_id, - substs: actual_substs, - }); + let actual_trait_ref = self + .infcx + .resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs }); // Search the expected and actual trait references to see (a) // whether the sub/sup placeholders appear in them (sometimes diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index df3dbfca01d7a..ede94c3d9f62d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -414,7 +414,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { tcx, ctxt.param_env, ctxt.assoc_item.def_id, - self.infcx.resolve_vars_if_possible(&ctxt.substs), + self.infcx.resolve_vars_if_possible(ctxt.substs), ) { Ok(Some(instance)) => instance, _ => return false, diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index c061f485c1cf3..4d3217a9c0bd9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -86,7 +86,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { } if let Some((expected, found)) = - self.infcx.expected_found_str_ty(&ExpectedFound { expected, found }) + self.infcx.expected_found_str_ty(ExpectedFound { expected, found }) { // Highlighted the differences when showing the "expected/found" note. err.note_expected_found(&"", expected, &"", found); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs index ca93b2777ab2a..8d0100440a8a5 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs @@ -55,12 +55,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let owner_id = hir.body_owner(body_id); let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); let poly_fn_sig = self.tcx().fn_sig(id); - let fn_sig = self.tcx().liberate_late_bound_regions(id, &poly_fn_sig); + let fn_sig = self.tcx().liberate_late_bound_regions(id, poly_fn_sig); body.params.iter().enumerate().find_map(|(index, param)| { // May return None; sometimes the tables are not yet populated. let ty = fn_sig.inputs()[index]; let mut found_anon_region = false; - let new_param_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| { + let new_param_ty = self.tcx().fold_regions(ty, &mut false, |r, _| { if *r == *anon_region { found_anon_region = true; replace_region diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 9ac27030adeea..7fb94332cad5c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -24,7 +24,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }; match *origin { infer::Subtype(ref trace) => { - if let Some((expected, found)) = self.values_str(&trace.values) { + if let Some((expected, found)) = self.values_str(trace.values) { label_or_note( trace.cause.span, &format!("...so that the {}", trace.cause.as_requirement_str()), diff --git a/compiler/rustc_infer/src/infer/fudge.rs b/compiler/rustc_infer/src/infer/fudge.rs index d7bc636db8f8f..c292b2bdb3040 100644 --- a/compiler/rustc_infer/src/infer/fudge.rs +++ b/compiler/rustc_infer/src/infer/fudge.rs @@ -105,7 +105,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let (mut fudger, value) = self.probe(|_| { match f() { Ok(value) => { - let value = self.resolve_vars_if_possible(&value); + let value = self.resolve_vars_if_possible(value); // At this point, `value` could in principle refer // to inference variables that have been created during diff --git a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs index 4a5fd4b2aa5c8..9d9ecf5b384e7 100644 --- a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs +++ b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs @@ -33,14 +33,14 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> { self.infcx.commit_if_ok(|_| { // First, we instantiate each bound region in the supertype with a // fresh placeholder region. - let b_prime = self.infcx.replace_bound_vars_with_placeholders(&b); + let b_prime = self.infcx.replace_bound_vars_with_placeholders(b); // Next, we instantiate each bound region in the subtype // with a fresh region variable. These region variables -- // but no other pre-existing region variables -- can name // the placeholders. let (a_prime, _) = - self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, &a); + self.infcx.replace_bound_vars_with_fresh_vars(span, HigherRankedType, a); debug!("a_prime={:?}", a_prime); debug!("b_prime={:?}", b_prime); @@ -66,7 +66,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// the [rustc dev guide]. /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html - pub fn replace_bound_vars_with_placeholders(&self, binder: &ty::Binder) -> T + pub fn replace_bound_vars_with_placeholders(&self, binder: ty::Binder) -> T where T: TypeFoldable<'tcx>, { @@ -113,10 +113,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { debug!( "replace_bound_vars_with_placeholders(\ next_universe={:?}, \ - binder={:?}, \ result={:?}, \ map={:?})", - next_universe, binder, result, map, + next_universe, result, map, ); result diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index fcf1949933b11..d7b2ce7ee2083 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -1001,7 +1001,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> { where T: TypeFoldable<'tcx>, { - tcx.fold_regions(&value, &mut false, |r, _db| match r { + tcx.fold_regions(value, &mut false, |r, _db| match r { ty::ReVar(rid) => self.resolve_var(*rid), _ => r, }) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index acded5351f80a..a045378f5027d 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -345,7 +345,7 @@ pub struct InferCtxt<'a, 'tcx> { } /// See the `error_reporting` module for more details. -#[derive(Clone, Debug, PartialEq, Eq, TypeFoldable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)] pub enum ValuePairs<'tcx> { Types(ExpectedFound>), Regions(ExpectedFound>), @@ -955,7 +955,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { Some(self.commit_if_ok(|_snapshot| { let ty::SubtypePredicate { a_is_expected, a, b } = - self.replace_bound_vars_with_placeholders(&predicate); + self.replace_bound_vars_with_placeholders(predicate); let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?; @@ -970,7 +970,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ) -> UnitResult<'tcx> { self.commit_if_ok(|_snapshot| { let ty::OutlivesPredicate(r_a, r_b) = - self.replace_bound_vars_with_placeholders(&predicate); + self.replace_bound_vars_with_placeholders(predicate); let origin = SubregionOrigin::from_obligation_cause(cause, || { RelateRegionParamBound(cause.span) }); @@ -1266,7 +1266,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { - self.resolve_vars_if_possible(&t).to_string() + self.resolve_vars_if_possible(t).to_string() } pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String { @@ -1274,7 +1274,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { format!("({})", tstrs.join(", ")) } - pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String { + pub fn trait_ref_to_string(&self, t: ty::TraitRef<'tcx>) -> String { self.resolve_vars_if_possible(t).print_only_trait_path().to_string() } @@ -1314,7 +1314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// is left as is. This is an idempotent operation that does /// not affect inference state in any way and so you can do it /// at will. - pub fn resolve_vars_if_possible(&self, value: &T) -> T + pub fn resolve_vars_if_possible(&self, value: T) -> T where T: TypeFoldable<'tcx>, { @@ -1349,7 +1349,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } - pub fn fully_resolve>(&self, value: &T) -> FixupResult<'tcx, T> { + pub fn fully_resolve>(&self, value: T) -> FixupResult<'tcx, T> { /*! * Attempts to resolve all type/region/const variables in * `value`. Region inference must have been run already (e.g., @@ -1383,7 +1383,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { where M: FnOnce(String) -> DiagnosticBuilder<'tcx>, { - let actual_ty = self.resolve_vars_if_possible(&actual_ty); + let actual_ty = self.resolve_vars_if_possible(actual_ty); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty); // Don't report an error if actual type is `Error`. @@ -1420,7 +1420,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, span: Span, lbrct: LateBoundRegionConversionTime, - value: &ty::Binder, + value: ty::Binder, ) -> (T, BTreeMap>) where T: TypeFoldable<'tcx>, @@ -1508,7 +1508,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { span: Option, ) -> EvalToConstValueResult<'tcx> { let mut original_values = OriginalQueryValues::default(); - let canonical = self.canonicalize_query(&(param_env, substs), &mut original_values); + let canonical = self.canonicalize_query((param_env, substs), &mut original_values); let (param_env, substs) = canonical.value; // The return value is the evaluated value which doesn't contain any reference to inference diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index eb1a7806256c3..16d86e6243de4 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -167,7 +167,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { sup_type, sub_region, origin ); - let sup_type = self.resolve_vars_if_possible(&sup_type); + let sup_type = self.resolve_vars_if_possible(sup_type); if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) { let outlives = &mut TypeOutlives::new( @@ -205,7 +205,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { implicit_region_bound, param_env, ); - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); outlives.type_must_outlive(origin, ty, region); } } diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 2b827f4f4eddc..f69212c599b62 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -124,10 +124,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { projection_ty: ty::ProjectionTy<'tcx>, ) -> Vec, ty::Region<'tcx>>> { let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx); - let erased_projection_ty = self.tcx.erase_regions(&projection_ty); + let erased_projection_ty = self.tcx.erase_regions(projection_ty); self.declared_generic_bounds_from_env_with_compare_fn(|ty| { if let ty::Projection(..) = ty.kind() { - let erased_ty = self.tcx.erase_regions(&ty); + let erased_ty = self.tcx.erase_regions(ty); erased_ty == erased_projection_ty } else { false diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index fe4ba5aa4e820..d05c90606ccae 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> { /// Full type resolution replaces all type and region variables with /// their concrete results. If any variable cannot be replaced (never unified, etc) /// then an `Err` result is returned. -pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: &T) -> FixupResult<'tcx, T> +pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>, value: T) -> FixupResult<'tcx, T> where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_infer/src/traits/structural_impls.rs b/compiler/rustc_infer/src/traits/structural_impls.rs index 1a1c2637a6fa6..f7ae77d77153a 100644 --- a/compiler/rustc_infer/src/traits/structural_impls.rs +++ b/compiler/rustc_infer/src/traits/structural_impls.rs @@ -60,7 +60,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { // TypeFoldable implementations. impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { traits::Obligation { cause: self.cause.clone(), recursion_depth: self.recursion_depth, diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index f6ef98407887e..b0b0e4372b8cd 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>( tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { - match pred.kind() { + match *pred.kind() { ty::PredicateKind::ForAll(binder) => { let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder)); tcx.reuse_or_mk_predicate(pred, new) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 467a3a425906f..eedb0e31bccad 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -880,7 +880,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { return FfiSafe; } - match ty.kind() { + match *ty.kind() { ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => { FfiSafe } @@ -1044,7 +1044,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { }; } - let sig = tcx.erase_late_bound_regions(&sig); + let sig = tcx.erase_late_bound_regions(sig); if !sig.output().is_unit() { let r = self.check_type_for_ffi(cache, sig.output()); match r { @@ -1218,7 +1218,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl<'_>) { let def_id = self.cx.tcx.hir().local_def_id(id); let sig = self.cx.tcx.fn_sig(def_id); - let sig = self.cx.tcx.erase_late_bound_regions(&sig); + let sig = self.cx.tcx.erase_late_bound_regions(sig); for (input_ty, input_hir) in sig.inputs().iter().zip(decl.inputs) { self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false, false); @@ -1295,7 +1295,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind { let item_def_id = cx.tcx.hir().local_def_id(it.hir_id); let t = cx.tcx.type_of(item_def_id); - let ty = cx.tcx.erase_regions(&t); + let ty = cx.tcx.erase_regions(t); let layout = match cx.layout_of(ty) { Ok(layout) => layout, Err( diff --git a/compiler/rustc_macros/src/type_foldable.rs b/compiler/rustc_macros/src/type_foldable.rs index 8fa6e6a710108..e5d4a2ae9f40a 100644 --- a/compiler/rustc_macros/src/type_foldable.rs +++ b/compiler/rustc_macros/src/type_foldable.rs @@ -6,6 +6,12 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:: } s.add_bounds(synstructure::AddBounds::Generics); + let body_visit = s.each(|bind| { + quote! { + ::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?; + } + }); + s.bind_with(|_| synstructure::BindStyle::Move); let body_fold = s.each_variant(|vi| { let bindings = vi.bindings(); vi.construct(|_, index| { @@ -16,20 +22,14 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:: }) }); - let body_visit = s.each(|bind| { - quote! { - ::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?; - } - }); - s.bound_impl( quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>), quote! { fn super_fold_with<__F: ::rustc_middle::ty::fold::TypeFolder<'tcx>>( - &self, + self, __folder: &mut __F ) -> Self { - match *self { #body_fold } + match self { #body_fold } } fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>( diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 921086366bea2..73aee616e260b 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -53,10 +53,10 @@ macro_rules! CloneTypeFoldableImpls { $( impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty { fn super_fold_with>( - &self, + self, _: &mut F ) -> $ty { - Clone::clone(self) + self } fn super_visit_with>( @@ -96,7 +96,7 @@ macro_rules! EnumTypeFoldableImpl { $(where $($wc)*)* { fn super_fold_with>( - &self, + self, folder: &mut V, ) -> Self { EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output()) diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index f366681bc75e9..0517ec5bb1a8c 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -67,7 +67,7 @@ impl<'tcx> TyCtxt<'tcx> { ) -> EvalToConstValueResult<'tcx> { // Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should // improve caching of queries. - let inputs = self.erase_regions(¶m_env.and(cid)); + let inputs = self.erase_regions(param_env.and(cid)); if let Some(span) = span { self.at(span).eval_to_const_value_raw(inputs) } else { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 5fe7b0f647dcd..c405170aacf6c 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2455,7 +2455,7 @@ impl UserTypeProjection { CloneTypeFoldableAndLiftImpls! { ProjectionKind, } impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { use crate::mir::ProjectionElem::*; let base = self.base.fold_with(folder); diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 0801188b27881..9c66d681ffa90 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -2,6 +2,7 @@ use super::*; use crate::ty; +use rustc_data_structures::functor::IdFunctor; CloneTypeFoldableAndLiftImpls! { BlockTailInfo, @@ -15,34 +16,33 @@ CloneTypeFoldableAndLiftImpls! { } impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { use crate::mir::TerminatorKind::*; let kind = match self.kind { Goto { target } => Goto { target }, - SwitchInt { ref discr, switch_ty, ref targets } => SwitchInt { + SwitchInt { discr, switch_ty, targets } => SwitchInt { discr: discr.fold_with(folder), switch_ty: switch_ty.fold_with(folder), targets: targets.clone(), }, - Drop { ref place, target, unwind } => { + Drop { place, target, unwind } => { Drop { place: place.fold_with(folder), target, unwind } } - DropAndReplace { ref place, ref value, target, unwind } => DropAndReplace { + DropAndReplace { place, value, target, unwind } => DropAndReplace { place: place.fold_with(folder), value: value.fold_with(folder), target, unwind, }, - Yield { ref value, resume, ref resume_arg, drop } => Yield { + Yield { value, resume, resume_arg, drop } => Yield { value: value.fold_with(folder), resume, resume_arg: resume_arg.fold_with(folder), drop, }, - Call { ref func, ref args, ref destination, cleanup, from_hir_call, fn_span } => { - let dest = - destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest)); + Call { func, args, destination, cleanup, from_hir_call, fn_span } => { + let dest = destination.as_ref().map(|&(loc, dest)| (loc.fold_with(folder), dest)); Call { func: func.fold_with(folder), @@ -53,13 +53,13 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { fn_span, } } - Assert { ref cond, expected, ref msg, target, cleanup } => { + Assert { cond, expected, msg, target, cleanup } => { use AssertKind::*; let msg = match msg { BoundsCheck { len, index } => { BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) } } - Overflow(op, l, r) => Overflow(*op, l.fold_with(folder), r.fold_with(folder)), + Overflow(op, l, r) => Overflow(op, l.fold_with(folder), r.fold_with(folder)), OverflowNeg(op) => OverflowNeg(op.fold_with(folder)), DivisionByZero(op) => DivisionByZero(op.fold_with(folder)), RemainderByZero(op) => RemainderByZero(op.fold_with(folder)), @@ -76,7 +76,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { FalseEdge { real_target, imaginary_target } } FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind }, - InlineAsm { template, ref operands, options, line_spans, destination } => InlineAsm { + InlineAsm { template, operands, options, line_spans, destination } => InlineAsm { template, operands: operands.fold_with(folder), options, @@ -140,8 +140,8 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { - fn super_fold_with>(&self, _: &mut F) -> Self { - *self + fn super_fold_with>(self, _: &mut F) -> Self { + self } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { @@ -150,7 +150,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { } impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { 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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { let v = self.iter().map(|t| t.fold_with(folder)).collect::>(); folder.tcx().intern_place_elems(&v) } @@ -172,29 +172,25 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { use crate::mir::Rvalue::*; - match *self { - Use(ref op) => Use(op.fold_with(folder)), - Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)), + match self { + Use(op) => Use(op.fold_with(folder)), + Repeat(op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)), ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)), - Ref(region, bk, ref place) => { - Ref(region.fold_with(folder), bk, place.fold_with(folder)) - } - AddressOf(mutability, ref place) => AddressOf(mutability, place.fold_with(folder)), - Len(ref place) => Len(place.fold_with(folder)), - Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)), - BinaryOp(op, ref rhs, ref lhs) => { - BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)) - } - CheckedBinaryOp(op, ref rhs, ref lhs) => { + Ref(region, bk, place) => Ref(region.fold_with(folder), bk, place.fold_with(folder)), + AddressOf(mutability, place) => AddressOf(mutability, place.fold_with(folder)), + Len(place) => Len(place.fold_with(folder)), + Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)), + BinaryOp(op, rhs, lhs) => BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)), + CheckedBinaryOp(op, rhs, lhs) => { CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)) } - UnaryOp(op, ref val) => UnaryOp(op, val.fold_with(folder)), - Discriminant(ref place) => Discriminant(place.fold_with(folder)), + UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)), + Discriminant(place) => Discriminant(place.fold_with(folder)), NullaryOp(op, ty) => NullaryOp(op, ty.fold_with(folder)), - Aggregate(ref kind, ref fields) => { - let kind = box match **kind { + Aggregate(kind, fields) => { + let kind = kind.map_id(|kind| match kind { AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)), AggregateKind::Tuple => AggregateKind::Tuple, AggregateKind::Adt(def, v, substs, user_ty, n) => AggregateKind::Adt( @@ -210,7 +206,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { AggregateKind::Generator(id, substs, movablity) => { AggregateKind::Generator(id, substs.fold_with(folder), movablity) } - }; + }); Aggregate(kind, fields.fold_with(folder)) } } @@ -263,11 +259,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - match *self { - Operand::Copy(ref place) => Operand::Copy(place.fold_with(folder)), - Operand::Move(ref place) => Operand::Move(place.fold_with(folder)), - Operand::Constant(ref c) => Operand::Constant(c.fold_with(folder)), + fn super_fold_with>(self, folder: &mut F) -> Self { + match self { + Operand::Copy(place) => Operand::Copy(place.fold_with(folder)), + Operand::Move(place) => Operand::Move(place.fold_with(folder)), + Operand::Constant(c) => Operand::Constant(c.fold_with(folder)), } } @@ -280,10 +276,10 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { use crate::mir::ProjectionElem::*; - match *self { + match self { Deref => Deref, Field(f, ty) => Field(f, ty.fold_with(folder)), Index(v) => Index(v.fold_with(folder)), @@ -307,8 +303,8 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for Field { - fn super_fold_with>(&self, _: &mut F) -> Self { - *self + fn super_fold_with>(self, _: &mut F) -> Self { + self } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { ControlFlow::CONTINUE @@ -316,8 +312,8 @@ impl<'tcx> TypeFoldable<'tcx> for Field { } impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal { - fn super_fold_with>(&self, _: &mut F) -> Self { - *self + fn super_fold_with>(self, _: &mut F) -> Self { + self } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { ControlFlow::CONTINUE @@ -325,7 +321,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal { } impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix { - fn super_fold_with>(&self, _: &mut F) -> Self { + fn super_fold_with>(self, _: &mut F) -> Self { self.clone() } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { @@ -334,7 +330,7 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix { } impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { Constant { span: self.span, user_ty: self.user_ty.fold_with(folder), diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 72360e219ecbd..634d50368bd88 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -367,7 +367,7 @@ rustc_queries! { TypeChecking { /// Erases regions from `ty` to yield a new type. - /// Normally you would just use `tcx.erase_regions(&value)`, + /// Normally you would just use `tcx.erase_regions(value)`, /// however, which uses this query as a kind of cache. query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> { // This query is not expected to have input -- as a result, it diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index ca51f2a941174..ecf2837b3e423 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -103,9 +103,9 @@ impl<'tcx> ConstKind<'tcx> { // so that we don't try to invoke this query with // any region variables. let param_env_and_substs = tcx - .erase_regions(¶m_env) + .erase_regions(param_env) .with_reveal_all_normalized(tcx) - .and(tcx.erase_regions(&substs)); + .and(tcx.erase_regions(substs)); // HACK(eddyb) when the query key would contain inference variables, // attempt using identity substs and `ParamEnv` instead, that will succeed diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b29e6d4a96705..b8819b8051d59 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1495,7 +1495,7 @@ impl<'tcx> TyCtxt<'tcx> { match ret_ty.kind() { ty::FnDef(_, _) => { let sig = ret_ty.fn_sig(self); - let output = self.erase_late_bound_regions(&sig.output()); + let output = self.erase_late_bound_regions(sig.output()); if output.is_impl_trait() { let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap(); Some((output, fn_decl.output.span())) diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs index 48d0fc1839e2f..4412ba9408c6c 100644 --- a/compiler/rustc_middle/src/ty/erase_regions.rs +++ b/compiler/rustc_middle/src/ty/erase_regions.rs @@ -15,17 +15,17 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns an equivalent value with all free regions removed (note /// that late-bound regions remain, because they are important for /// subtyping, but they are anonymized and normalized as well).. - pub fn erase_regions(self, value: &T) -> T + pub fn erase_regions(self, value: T) -> T where T: TypeFoldable<'tcx>, { // If there's nothing to erase avoid performing the query at all if !value.has_type_flags(TypeFlags::HAS_RE_LATE_BOUND | TypeFlags::HAS_FREE_REGIONS) { - return value.clone(); + return value; } - + debug!("erase_regions({:?})", value); let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self }); - debug!("erase_regions({:?}) = {:?}", value, value1); + debug!("erase_regions = {:?}", value1); value1 } } @@ -43,7 +43,7 @@ impl TypeFolder<'tcx> for RegionEraserVisitor<'tcx> { if ty.needs_infer() { ty.super_fold_with(self) } else { self.tcx.erase_regions_ty(ty) } } - fn fold_binder(&mut self, t: &ty::Binder) -> ty::Binder + fn fold_binder(&mut self, t: ty::Binder) -> ty::Binder where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 70a8157c04ac7..ee5c7a5473a9f 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -44,8 +44,8 @@ use std::ops::ControlFlow; /// /// To implement this conveniently, use the derive macro located in librustc_macros. pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { - fn super_fold_with>(&self, folder: &mut F) -> Self; - fn fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self; + fn fold_with>(self, folder: &mut F) -> Self { self.super_fold_with(folder) } @@ -158,8 +158,8 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { } impl TypeFoldable<'tcx> for hir::Constness { - fn super_fold_with>(&self, _: &mut F) -> Self { - *self + fn super_fold_with>(self, _: &mut F) -> Self { + self } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { ControlFlow::CONTINUE @@ -174,7 +174,7 @@ impl TypeFoldable<'tcx> for hir::Constness { pub trait TypeFolder<'tcx>: Sized { fn tcx<'a>(&'a self) -> TyCtxt<'tcx>; - fn fold_binder(&mut self, t: &Binder) -> Binder + fn fold_binder(&mut self, t: Binder) -> Binder where T: TypeFoldable<'tcx>, { @@ -266,7 +266,7 @@ impl<'tcx> TyCtxt<'tcx> { /// and skipped. pub fn fold_regions( self, - value: &T, + value: T, skipped_regions: &mut bool, mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>, ) -> T @@ -406,7 +406,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { + fn fold_binder>(&mut self, t: ty::Binder) -> ty::Binder { self.current_index.shift_in(1); let t = t.super_fold_with(self); self.current_index.shift_out(1); @@ -466,7 +466,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { + fn fold_binder>(&mut self, t: ty::Binder) -> ty::Binder { self.current_index.shift_in(1); let t = t.super_fold_with(self); self.current_index.shift_out(1); @@ -549,7 +549,7 @@ impl<'tcx> TyCtxt<'tcx> { /// contain escaping bound types. pub fn replace_late_bound_regions( self, - value: &Binder, + value: Binder, fld_r: F, ) -> (T, BTreeMap>) where @@ -561,7 +561,7 @@ impl<'tcx> TyCtxt<'tcx> { let fld_c = |bound_ct, ty| { self.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, bound_ct), ty }) }; - self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c) + self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c) } /// Replaces all escaping bound vars. The `fld_r` closure replaces escaping @@ -569,7 +569,7 @@ impl<'tcx> TyCtxt<'tcx> { /// closure replaces escaping bound consts. pub fn replace_escaping_bound_vars( self, - value: &T, + value: T, mut fld_r: F, mut fld_t: G, mut fld_c: H, @@ -609,7 +609,7 @@ impl<'tcx> TyCtxt<'tcx> { /// types. pub fn replace_bound_vars( self, - value: &Binder, + value: Binder, fld_r: F, fld_t: G, fld_c: H, @@ -620,16 +620,12 @@ impl<'tcx> TyCtxt<'tcx> { H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>, T: TypeFoldable<'tcx>, { - self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c) + self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c) } /// Replaces any late-bound regions bound in `value` with /// free variants attached to `all_outlive_scope`. - pub fn liberate_late_bound_regions( - self, - all_outlive_scope: DefId, - value: &ty::Binder, - ) -> T + pub fn liberate_late_bound_regions(self, all_outlive_scope: DefId, value: ty::Binder) -> T where T: TypeFoldable<'tcx>, { @@ -683,7 +679,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Replaces any late-bound regions bound in `value` with `'erased`. Useful in codegen but also /// method lookup and a few other places where precise region relationships are not required. - pub fn erase_late_bound_regions(self, value: &Binder) -> T + pub fn erase_late_bound_regions(self, value: Binder) -> T where T: TypeFoldable<'tcx>, { @@ -698,7 +694,7 @@ impl<'tcx> TyCtxt<'tcx> { /// `FnSig`s or `TraitRef`s which are equivalent up to region naming will become /// structurally identical. For example, `for<'a, 'b> fn(&'a isize, &'b isize)` and /// `for<'a, 'b> fn(&'b isize, &'a isize)` will become identical after anonymization. - pub fn anonymize_late_bound_regions(self, sig: &Binder) -> Binder + pub fn anonymize_late_bound_regions(self, sig: Binder) -> Binder where T: TypeFoldable<'tcx>, { @@ -740,7 +736,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { + fn fold_binder>(&mut self, t: ty::Binder) -> ty::Binder { self.current_index.shift_in(1); let t = t.super_fold_with(self); self.current_index.shift_out(1); @@ -804,7 +800,7 @@ pub fn shift_region<'tcx>( } } -pub fn shift_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: &T, amount: u32) -> T +pub fn shift_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: T, amount: u32) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 306cebd9cb722..f52466d85f890 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -359,15 +359,15 @@ impl<'tcx> Instance<'tcx> { // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` // below is more likely to ignore the bounds in scope (e.g. if the only // generic parameters mentioned by `substs` were lifetime ones). - let substs = tcx.erase_regions(&substs); + let substs = tcx.erase_regions(substs); // FIXME(eddyb) should this always use `param_env.with_reveal_all()`? if let Some((did, param_did)) = def.as_const_arg() { tcx.resolve_instance_of_const_arg( - tcx.erase_regions(¶m_env.and((did, param_did, substs))), + tcx.erase_regions(param_env.and((did, param_did, substs))), ) } else { - tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def.did, substs)))) + tcx.resolve_instance(tcx.erase_regions(param_env.and((def.did, substs)))) } } @@ -452,7 +452,7 @@ impl<'tcx> Instance<'tcx> { let self_ty = tcx.mk_closure(closure_did, substs); let sig = substs.as_closure().sig(); - let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); + let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig); assert_eq!(sig.inputs().len(), 1); let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]); @@ -485,7 +485,7 @@ impl<'tcx> Instance<'tcx> { &self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - v: &T, + v: T, ) -> T where T: TypeFoldable<'tcx> + Clone, @@ -493,7 +493,7 @@ impl<'tcx> Instance<'tcx> { if let Some(substs) = self.substs_for_mir_body() { tcx.subst_and_normalize_erasing_regions(substs, param_env, v) } else { - tcx.normalize_erasing_regions(param_env, v.clone()) + tcx.normalize_erasing_regions(param_env, v) } } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 1e93c3650b890..acc7d3c4960e8 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1756,7 +1756,7 @@ impl<'tcx> SizeSkeleton<'tcx> { match tail.kind() { ty::Param(_) | ty::Projection(_) => { debug_assert!(tail.has_param_types_or_consts()); - Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(&tail) }) + Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) }) } _ => bug!( "SizeSkeleton::compute({}): layout errored ({}), yet \ @@ -2545,7 +2545,7 @@ where ) -> Self { debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args); - let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig); + let sig = cx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig); use rustc_target::spec::abi::Abi::*; let conv = match cx.tcx().sess.target.adjust_abi(sig.abi) { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 5e8a4a56db32c..8fcf19ea48ad2 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1788,7 +1788,7 @@ impl<'a, 'tcx> HashStable> for ParamEnv<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { ParamEnv::new(self.caller_bounds().fold_with(folder), self.reveal().fold_with(folder)) } diff --git a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs index a594a8ad51240..9d97815a5f1b7 100644 --- a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs +++ b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs @@ -30,7 +30,7 @@ impl<'tcx> TyCtxt<'tcx> { // Erase first before we do the real query -- this keeps the // cache from being too polluted. - let value = self.erase_regions(&value); + let value = self.erase_regions(value); if !value.has_projections() { value } else { @@ -49,7 +49,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn normalize_erasing_late_bound_regions( self, param_env: ty::ParamEnv<'tcx>, - value: &ty::Binder, + value: ty::Binder, ) -> T where T: TypeFoldable<'tcx>, @@ -65,7 +65,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_substs: SubstsRef<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, ) -> T where T: TypeFoldable<'tcx>, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 1e4fd0921ee0f..42952ac2cd2ae 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1750,7 +1750,7 @@ impl FmtPrinter<'_, 'tcx, F> { define_scoped_cx!(self); let mut region_index = self.region_index; - let new_value = self.tcx.replace_late_bound_regions(value, |br| { + let new_value = self.tcx.replace_late_bound_regions(value.clone(), |br| { let _ = start_or_continue(&mut self, "for<", ", "); let br = match br { ty::BrNamed(_, name) => { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 89fd803fe5140..afafc6f2a07c8 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -7,6 +7,7 @@ use crate::mir::ProjectionKind; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::{self, InferConst, Lift, Ty, TyCtxt}; +use rustc_data_structures::functor::IdFunctor; use rustc_hir as hir; use rustc_hir::def::Namespace; use rustc_hir::def_id::CRATE_DEF_INDEX; @@ -725,8 +726,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> { /// AdtDefs are basically the same as a DefId. impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef { - fn super_fold_with>(&self, _folder: &mut F) -> Self { - *self + fn super_fold_with>(self, _folder: &mut F) -> Self { + self } fn super_visit_with>(&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) { - fn super_fold_with>(&self, folder: &mut F) -> (T, U) { + fn super_fold_with>(self, folder: &mut F) -> (T, U) { (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> for (A, B, C) { - fn super_fold_with>(&self, folder: &mut F) -> (A, B, C) { + fn super_fold_with>(self, folder: &mut F) -> (A, B, C) { (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 { - fn super_fold_with>(&self, folder: &mut F) -> Self { - Rc::new((**self).fold_with(folder)) + fn super_fold_with>(self, folder: &mut F) -> Self { + // FIXME: Reuse the `Rc` here. + Rc::new((*self).clone().fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -784,8 +786,9 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc { } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc { - fn super_fold_with>(&self, folder: &mut F) -> Self { - Arc::new((**self).fold_with(folder)) + fn super_fold_with>(self, folder: &mut F) -> Self { + // FIXME: Reuse the `Arc` here. + Arc::new((*self).clone().fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -794,9 +797,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc { } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box { - fn super_fold_with>(&self, folder: &mut F) -> Self { - let content: T = (**self).fold_with(folder); - box content + fn super_fold_with>(self, folder: &mut F) -> Self { + self.map_id(|value| value.fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -805,8 +807,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box { } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec { - fn super_fold_with>(&self, folder: &mut F) -> Self { - self.iter().map(|t| t.fold_with(folder)).collect() + fn super_fold_with>(self, folder: &mut F) -> Self { + self.map_id(|t| t.fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -815,8 +817,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec { } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - self.iter().map(|t| t.fold_with(folder)).collect::>().into_boxed_slice() + fn super_fold_with>(self, folder: &mut F) -> Self { + self.map_id(|t| t.fold_with(folder)) } fn super_visit_with>(&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 { - fn super_fold_with>(&self, folder: &mut F) -> Self { - self.map_bound_ref(|ty| ty.fold_with(folder)) + fn super_fold_with>(self, folder: &mut F) -> Self { + self.map_bound(|ty| ty.fold_with(folder)) } - fn fold_with>(&self, folder: &mut F) -> Self { + fn fold_with>(self, folder: &mut F) -> Self { folder.fold_binder(self) } @@ -843,8 +845,8 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder { } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - fold_list(*self, folder, |tcx, v| tcx.intern_existential_predicates(v)) + fn super_fold_with>(self, folder: &mut F) -> Self { + fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -853,8 +855,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - fold_list(*self, folder, |tcx, v| tcx.intern_type_list(v)) + fn super_fold_with>(self, folder: &mut F) -> Self { + fold_list(self, folder, |tcx, v| tcx.intern_type_list(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -863,8 +865,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List { - fn super_fold_with>(&self, folder: &mut F) -> Self { - fold_list(*self, folder, |tcx, v| tcx.intern_projs(v)) + fn super_fold_with>(self, folder: &mut F) -> Self { + fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -873,7 +875,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List { } impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { use crate::ty::InstanceDef::*; Self { 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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { 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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { let kind = match self.kind() { ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)), ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)), @@ -964,8 +966,8 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) } } - fn fold_with>(&self, folder: &mut F) -> Self { - folder.fold_ty(*self) + fn fold_with>(self, folder: &mut F) -> Self { + folder.fold_ty(self) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -1016,12 +1018,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { - fn super_fold_with>(&self, _folder: &mut F) -> Self { - *self + fn super_fold_with>(self, _folder: &mut F) -> Self { + self } - fn fold_with>(&self, folder: &mut F) -> Self { - folder.fold_region(*self) + fn fold_with>(self, folder: &mut F) -> Self { + folder.fold_region(self) } fn super_visit_with>(&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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - let new = ty::PredicateKind::super_fold_with(&self.inner.kind, folder); - folder.tcx().reuse_or_mk_predicate(*self, new) + fn super_fold_with>(self, folder: &mut F) -> Self { + let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder); + folder.tcx().reuse_or_mk_predicate(self, new) } fn super_visit_with>(&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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v)) + fn super_fold_with>(self, folder: &mut F) -> Self { + fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -1067,8 +1069,8 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec { - fn super_fold_with>(&self, folder: &mut F) -> Self { - self.iter().map(|x| x.fold_with(folder)).collect() + fn super_fold_with>(self, folder: &mut F) -> Self { + self.map_id(|x| x.fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -1077,18 +1079,18 @@ impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { let ty = self.ty.fold_with(folder); let val = self.val.fold_with(folder); if ty != self.ty || val != self.val { folder.tcx().mk_const(ty::Const { ty, val }) } else { - *self + self } } - fn fold_with>(&self, folder: &mut F) -> Self { - folder.fold_const(*self) + fn fold_with>(self, folder: &mut F) -> Self { + folder.fold_const(self) } fn super_visit_with>(&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> { - fn super_fold_with>(&self, folder: &mut F) -> Self { - match *self { + fn super_fold_with>(self, folder: &mut F) -> Self { + match self { ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)), ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)), ty::ConstKind::Unevaluated(did, substs, promoted) => { @@ -1112,7 +1114,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { ty::ConstKind::Value(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(..) - | ty::ConstKind::Error(_) => *self, + | ty::ConstKind::Error(_) => self, } } @@ -1130,8 +1132,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { - fn super_fold_with>(&self, _folder: &mut F) -> Self { - *self + fn super_fold_with>(self, _folder: &mut F) -> Self { + self } fn super_visit_with>(&self, _visitor: &mut V) -> ControlFlow<()> { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 384d08f83485c..4bf16436855f4 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1001,7 +1001,7 @@ impl Binder { T: TypeFoldable<'tcx>, { if value.has_escaping_bound_vars() { - Binder::bind(super::fold::shift_vars(tcx, &value, 1)) + Binder::bind(super::fold::shift_vars(tcx, value, 1)) } else { Binder::dummy(value) } diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 07f775cf8b1e5..5aa312d7c29a4 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -152,7 +152,7 @@ impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> { } impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { match self.unpack() { GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(), GenericArgKind::Type(ty) => ty.fold_with(folder).into(), @@ -363,7 +363,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { - fn super_fold_with>(&self, folder: &mut F) -> Self { + fn super_fold_with>(self, folder: &mut F) -> Self { // This code is hot enough that it's worth specializing for the most // common length lists, to avoid the overhead of `SmallVec` creation. // The match arms are in order of frequency. The 1, 2, and 0 cases are @@ -405,12 +405,12 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { // there is more information available (for better errors). pub trait Subst<'tcx>: Sized { - fn subst(&self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self { + fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self { self.subst_spanned(tcx, substs, None) } fn subst_spanned( - &self, + self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>], span: Option, @@ -419,13 +419,13 @@ pub trait Subst<'tcx>: Sized { impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T { fn subst_spanned( - &self, + self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>], span: Option, ) -> T { let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 }; - (*self).fold_with(&mut folder) + self.fold_with(&mut folder) } } @@ -448,7 +448,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &ty::Binder) -> ty::Binder { + fn fold_binder>(&mut self, t: ty::Binder) -> ty::Binder { self.binders_passed += 1; let t = t.super_fold_with(self); self.binders_passed -= 1; @@ -634,7 +634,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { return val; } - let result = ty::fold::shift_vars(self.tcx(), &val, self.binders_passed); + let result = ty::fold::shift_vars(self.tcx(), val, self.binders_passed); debug!("shift_vars: shifted result = {:?}", result); result diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 5f117e19eca27..6e12694f5a61f 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -160,7 +160,7 @@ impl<'tcx> TyCtxt<'tcx> { // We want the type_id be independent of the types free regions, so we // erase them. The erase_regions() call will also anonymize bound // regions, which is desirable too. - let ty = self.erase_regions(&ty); + let ty = self.erase_regions(ty); hcx.while_hashing_spans(false, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs b/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs index a5a7012852d71..3586be2804d6a 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs @@ -876,7 +876,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } // Type-test failed. Report the error. - let erased_generic_kind = infcx.tcx.erase_regions(&type_test.generic_kind); + let erased_generic_kind = infcx.tcx.erase_regions(type_test.generic_kind); // Skip duplicate-ish errors. if deduplicate_errors.insert(( @@ -1006,7 +1006,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("try_promote_type_test_subject(ty = {:?})", ty); - let ty = tcx.fold_regions(&ty, &mut false, |r, _depth| { + let ty = tcx.fold_regions(ty, &mut false, |r, _depth| { let region_vid = self.to_region_vid(r); // The challenge if this. We have some region variable `r` @@ -1248,7 +1248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { where T: TypeFoldable<'tcx>, { - tcx.fold_regions(&value, &mut false, |r, _db| { + tcx.fold_regions(value, &mut false, |r, _db| { let vid = self.to_region_vid(r); let scc = self.constraint_sccs.scc(vid); let repr = self.scc_representatives[scc]; diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs index 325dca8c8ca99..f7c902355cb50 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs +++ b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs @@ -63,7 +63,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let mut subst_regions = vec![self.universal_regions.fr_static]; let universal_substs = - infcx.tcx.fold_regions(&substs, &mut false, |region, _| match *region { + infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region { ty::ReVar(vid) => { subst_regions.push(vid); self.definitions[vid].external_name.unwrap_or_else(|| { @@ -94,7 +94,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { subst_regions.dedup(); let universal_concrete_type = - infcx.tcx.fold_regions(&concrete_type, &mut false, |region, _| match *region { + infcx.tcx.fold_regions(concrete_type, &mut false, |region, _| match *region { ty::ReVar(vid) => subst_regions .iter() .find(|ur_vid| self.eval_equal(vid, **ur_vid)) @@ -139,7 +139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { where T: TypeFoldable<'tcx>, { - tcx.fold_regions(&ty, &mut false, |region, _| match *region { + tcx.fold_regions(ty, &mut false, |region, _| match *region { ty::ReVar(vid) => { // Find something that we can name let upper_bound = self.approx_universal_upper_bound(vid); diff --git a/compiler/rustc_mir/src/borrow_check/renumber.rs b/compiler/rustc_mir/src/borrow_check/renumber.rs index 5df033b48c1f9..e563e37adc22b 100644 --- a/compiler/rustc_mir/src/borrow_check/renumber.rs +++ b/compiler/rustc_mir/src/borrow_check/renumber.rs @@ -26,7 +26,7 @@ pub fn renumber_mir<'tcx>( /// Replaces all regions appearing in `value` with fresh inference /// variables. -pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: &T) -> T +pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T where T: TypeFoldable<'tcx>, { @@ -43,7 +43,7 @@ struct NLLVisitor<'a, 'tcx> { } impl<'a, 'tcx> NLLVisitor<'a, 'tcx> { - fn renumber_regions(&mut self, value: &T) -> T + fn renumber_regions(&mut self, value: T) -> T where T: TypeFoldable<'tcx>, { @@ -70,7 +70,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> { _: Location, ) -> Option> { if let PlaceElem::Field(field, ty) = elem { - let new_ty = self.renumber_regions(&ty); + let new_ty = self.renumber_regions(ty); if new_ty != ty { return Some(PlaceElem::Field(field, new_ty)); @@ -83,7 +83,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> { fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) { debug!("visit_substs(substs={:?}, location={:?})", substs, location); - *substs = self.renumber_regions(&{ *substs }); + *substs = self.renumber_regions(*substs); debug!("visit_substs: substs={:?}", substs); } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index 444f9fe8d0a68..b7d22fab3dde6 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { .replace_bound_vars_with_fresh_vars( body.span, LateBoundRegionConversionTime::FnCall, - &poly_sig, + poly_sig, ) .0, ) diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 409399094e849..a5c45452dec85 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -784,7 +784,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { }; if let Some(field) = variant.fields.get(field.index()) { - Ok(self.cx.normalize(&field.ty(tcx, substs), location)) + Ok(self.cx.normalize(field.ty(tcx, substs), location)) } else { Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() }) } @@ -1245,7 +1245,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { anon_owner_def_id, dummy_body_id, param_env, - &anon_ty, + anon_ty, locations.span(body), )); debug!( @@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); for (&opaque_def_id, opaque_decl) in &opaque_type_map { - let resolved_ty = infcx.resolve_vars_if_possible(&opaque_decl.concrete_ty); + let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty); let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() { *def_id == opaque_def_id } else { @@ -1296,7 +1296,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let subst_opaque_defn_ty = opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs); let renumbered_opaque_defn_ty = - renumber::renumber_regions(infcx, &subst_opaque_defn_ty); + renumber::renumber_regions(infcx, subst_opaque_defn_ty); debug!( "eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}", @@ -1601,7 +1601,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let (sig, map) = self.infcx.replace_bound_vars_with_fresh_vars( term.source_info.span, LateBoundRegionConversionTime::FnCall, - &sig, + sig, ); let sig = self.normalize(sig, term_location); self.check_call_dest(body, term, &sig, destination, term_location); @@ -1900,7 +1900,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // Erase the regions from `ty` to get a global type. The // `Sized` bound in no way depends on precise regions, so this // shouldn't affect `is_sized`. - let erased_ty = tcx.erase_regions(&ty); + let erased_ty = tcx.erase_regions(ty); if !erased_ty.is_sized(tcx.at(span), self.param_env) { // in current MIR construction, all non-control-flow rvalue // expressions evaluate through `as_temp` or `into` a return diff --git a/compiler/rustc_mir/src/borrow_check/universal_regions.rs b/compiler/rustc_mir/src/borrow_check/universal_regions.rs index 4742113b1a552..7ad38a1f82cd4 100644 --- a/compiler/rustc_mir/src/borrow_check/universal_regions.rs +++ b/compiler/rustc_mir/src/borrow_check/universal_regions.rs @@ -438,7 +438,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars( FR, self.mir_def.did, - &bound_inputs_and_output, + bound_inputs_and_output, &mut indices, ); // Converse of above, if this is a function then the late-bound regions declared on its @@ -522,7 +522,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { debug!("defining_ty (pre-replacement): {:?}", defining_ty); let defining_ty = - self.infcx.replace_free_regions_with_nll_infer_vars(FR, &defining_ty); + self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty); match *defining_ty.kind() { ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs), @@ -543,7 +543,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let substs = - self.infcx.replace_free_regions_with_nll_infer_vars(FR, &identity_substs); + self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs); DefiningTy::Const(self.mir_def.did.to_def_id(), substs) } } @@ -628,7 +628,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { DefiningTy::FnDef(def_id, _) => { let sig = tcx.fn_sig(def_id); - let sig = indices.fold_to_region_vids(tcx, &sig); + let sig = indices.fold_to_region_vids(tcx, sig); sig.inputs_and_output() } @@ -637,7 +637,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { // "output" (the type of the constant). assert_eq!(self.mir_def.did.to_def_id(), def_id); let ty = tcx.type_of(self.mir_def.def_id_for_type_of()); - let ty = indices.fold_to_region_vids(tcx, &ty); + let ty = indices.fold_to_region_vids(tcx, ty); ty::Binder::dummy(tcx.intern_type_list(&[ty])) } } @@ -648,7 +648,7 @@ trait InferCtxtExt<'tcx> { fn replace_free_regions_with_nll_infer_vars( &self, origin: NLLRegionVariableOrigin, - value: &T, + value: T, ) -> T where T: TypeFoldable<'tcx>; @@ -657,7 +657,7 @@ trait InferCtxtExt<'tcx> { &self, origin: NLLRegionVariableOrigin, all_outlive_scope: LocalDefId, - value: &ty::Binder, + value: ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, ) -> T where @@ -674,7 +674,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { fn replace_free_regions_with_nll_infer_vars( &self, origin: NLLRegionVariableOrigin, - value: &T, + value: T, ) -> T where T: TypeFoldable<'tcx>, @@ -686,7 +686,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { &self, origin: NLLRegionVariableOrigin, all_outlive_scope: LocalDefId, - value: &ty::Binder, + value: ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, ) -> T where @@ -771,7 +771,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> { /// Replaces all free regions in `value` with region vids, as /// returned by `to_region_vid`. - pub fn fold_to_region_vids(&self, tcx: TyCtxt<'tcx>, value: &T) -> T + pub fn fold_to_region_vids(&self, tcx: TyCtxt<'tcx>, value: T) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs index d1d507e54ef5f..d16366fded900 100644 --- a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs +++ b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs @@ -152,7 +152,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>( let ty = place.ty(body, tcx).ty; debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty); - let erased_ty = tcx.erase_regions(&ty); + let erased_ty = tcx.erase_regions(ty); if erased_ty.needs_drop(tcx, ctxt.param_env) { each_child(child); } else { diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 0f86a181a55f7..05b4d1c410d18 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -505,7 +505,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, value: T, ) -> T { - frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, &value) + frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value) } /// The `substs` are assumed to already be in our interpreter "universe" (param_env). diff --git a/compiler/rustc_mir/src/interpret/traits.rs b/compiler/rustc_mir/src/interpret/traits.rs index 77f4593fa162c..fa7036f4e5b02 100644 --- a/compiler/rustc_mir/src/interpret/traits.rs +++ b/compiler/rustc_mir/src/interpret/traits.rs @@ -21,7 +21,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx, Pointer> { trace!("get_vtable(trait_ref={:?})", poly_trait_ref); - let (ty, poly_trait_ref) = self.tcx.erase_regions(&(ty, poly_trait_ref)); + let (ty, poly_trait_ref) = self.tcx.erase_regions((ty, poly_trait_ref)); // All vtables must be monomorphic, bail out otherwise. ensure_monomorphic_enough(*self.tcx, ty)?; @@ -37,7 +37,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let methods = if let Some(poly_trait_ref) = poly_trait_ref { let trait_ref = poly_trait_ref.with_self_ty(*self.tcx, ty); - let trait_ref = self.tcx.erase_regions(&trait_ref); + let trait_ref = self.tcx.erase_regions(trait_ref); self.tcx.vtable_methods(trait_ref) } else { @@ -143,7 +143,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?; trace!("Found drop fn: {:?}", drop_instance); let fn_sig = drop_instance.ty(*self.tcx, self.param_env).fn_sig(*self.tcx); - let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, &fn_sig); + let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig); // The drop function takes `*mut T` where `T` is the type being dropped, so get that. let args = fn_sig.inputs(); if args.len() != 1 { diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 938181abff244..a6f9099217253 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -546,7 +546,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - &value, + value, ) } } @@ -1118,7 +1118,7 @@ impl RootCollector<'_, 'v> { // late-bound regions, since late-bound // regions must appear in the argument // listing. - let main_ret_ty = self.tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap()); + let main_ret_ty = self.tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap()); let start_instance = Instance::resolve( self.tcx, diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs index 037b80e4bf2bb..d5a845dd76fb8 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs @@ -304,7 +304,7 @@ fn characteristic_def_id_of_mono_item<'tcx>( let impl_self_ty = tcx.subst_and_normalize_erasing_regions( instance.substs, ty::ParamEnv::reveal_all(), - &tcx.type_of(impl_def_id), + tcx.type_of(impl_def_id), ); if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) { return Some(def_id); diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir/src/shim.rs index b2fa4b11f3658..3a1fa0018c104 100644 --- a/compiler/rustc_mir/src/shim.rs +++ b/compiler/rustc_mir/src/shim.rs @@ -135,7 +135,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) // Check if this is a generator, if so, return the drop glue for it if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) { let body = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap(); - return body.subst(tcx, substs); + return body.clone().subst(tcx, substs); } let substs = if let Some(ty) = ty { @@ -144,7 +144,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) InternalSubsts::identity_for_item(tcx, def_id) }; let sig = tcx.fn_sig(def_id).subst(tcx, substs); - let sig = tcx.erase_late_bound_regions(&sig); + let sig = tcx.erase_late_bound_regions(sig); let span = tcx.def_span(def_id); let source_info = SourceInfo::outermost(span); @@ -338,7 +338,7 @@ impl CloneShimBuilder<'tcx> { // or access fields of a Place of type TySelf. let substs = tcx.mk_substs_trait(self_ty, &[]); let sig = tcx.fn_sig(def_id).subst(tcx, substs); - let sig = tcx.erase_late_bound_regions(&sig); + let sig = tcx.erase_late_bound_regions(sig); let span = tcx.def_span(def_id); CloneShimBuilder { @@ -656,7 +656,7 @@ fn build_call_shim<'tcx>( // to substitute into the signature of the shim. It is not necessary for users of this // MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`). let (sig_substs, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance { - let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx)); + let sig = tcx.erase_late_bound_regions(ty.fn_sig(tcx)); let untuple_args = sig.inputs(); @@ -671,7 +671,7 @@ fn build_call_shim<'tcx>( let def_id = instance.def_id(); let sig = tcx.fn_sig(def_id); - let mut sig = tcx.erase_late_bound_regions(&sig); + let mut sig = tcx.erase_late_bound_regions(sig); assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body()); if let Some(sig_substs) = sig_substs { diff --git a/compiler/rustc_mir/src/transform/generator.rs b/compiler/rustc_mir/src/transform/generator.rs index 039d4753a8c2d..dc413f8dd2dc5 100644 --- a/compiler/rustc_mir/src/transform/generator.rs +++ b/compiler/rustc_mir/src/transform/generator.rs @@ -720,13 +720,13 @@ fn sanitize_witness<'tcx>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, witness: Ty<'tcx>, - upvars: &Vec>, + upvars: Vec>, saved_locals: &GeneratorSavedLocals, ) { let did = body.source.def_id(); let allowed_upvars = tcx.erase_regions(upvars); let allowed = match witness.kind() { - ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s), + &ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s), _ => { tcx.sess.delay_span_bug( body.span, @@ -1303,7 +1303,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { let liveness_info = locals_live_across_suspend_points(tcx, body, &always_live_locals, movable); - sanitize_witness(tcx, body, interior, &upvars, &liveness_info.saved_locals); + sanitize_witness(tcx, body, interior, upvars, &liveness_info.saved_locals); if tcx.sess.opts.debugging_opts.validate_mir { let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias { diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index aae98f5b6d8d6..7ba0fc5be678b 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -122,7 +122,7 @@ impl Inliner<'tcx> { let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions( self.tcx, self.param_env, - callee_body, + callee_body.clone(), ); let old_blocks = caller_body.basic_blocks().next_index(); diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 6982cdccd5205..c50389a850ec6 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -240,7 +240,7 @@ fn liberated_closure_env_ty( }; let closure_env_ty = tcx.closure_env_ty(closure_def_id, closure_substs).unwrap(); - tcx.erase_late_bound_regions(&closure_env_ty) + tcx.erase_late_bound_regions(closure_env_ty) } #[derive(Debug, PartialEq, Eq)] diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index ac91fcf62937a..eba8e1a0613fb 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -51,7 +51,7 @@ pub(super) fn mangle( // Erase regions because they may not be deterministic when hashed // and should not matter anyhow. - let instance_ty = tcx.erase_regions(&instance_ty); + let instance_ty = tcx.erase_regions(instance_ty); let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate); diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs index 822a835293474..a28c8cac72810 100644 --- a/compiler/rustc_symbol_mangling/src/test.rs +++ b/compiler/rustc_symbol_mangling/src/test.rs @@ -39,7 +39,7 @@ impl SymbolNamesTest<'tcx> { let def_id = def_id.to_def_id(); let instance = Instance::new( def_id, - tcx.erase_regions(&InternalSubsts::identity_for_item(tcx, def_id)), + tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)), ); let mangled = tcx.symbol_name(instance); tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled)); diff --git a/compiler/rustc_trait_selection/src/autoderef.rs b/compiler/rustc_trait_selection/src/autoderef.rs index b9c5123e49a0e..05b6c4a48de1e 100644 --- a/compiler/rustc_trait_selection/src/autoderef.rs +++ b/compiler/rustc_trait_selection/src/autoderef.rs @@ -109,7 +109,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { param_env, state: AutoderefSnapshot { steps: vec![], - cur_ty: infcx.resolve_vars_if_possible(&base_ty), + cur_ty: infcx.resolve_vars_if_possible(base_ty), obligations: vec![], at_start: true, reached_recursion_limit: false, @@ -164,14 +164,14 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations); self.state.obligations.extend(obligations); - Some(self.infcx.resolve_vars_if_possible(&normalized_ty)) + Some(self.infcx.resolve_vars_if_possible(normalized_ty)) } /// Returns the final type we ended up with, which may be an inference /// variable (we will resolve it first, if we want). pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> { if resolve { - self.infcx.resolve_vars_if_possible(&self.state.cur_ty) + self.infcx.resolve_vars_if_possible(self.state.cur_ty) } else { self.state.cur_ty } diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 4ec1b29bca4f1..41184ce211686 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -28,7 +28,7 @@ pub trait InferCtxtExt<'tcx> { span: Span, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, ) -> InferOk<'tcx, T> where T: TypeFoldable<'tcx>; @@ -41,7 +41,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { ty: Ty<'tcx>, span: Span, ) -> bool { - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); if !(param_env, ty).needs_infer() { return ty.is_copy_modulo_regions(self.tcx.at(span), param_env); @@ -63,7 +63,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { span: Span, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, ) -> InferOk<'tcx, T> where T: TypeFoldable<'tcx>, @@ -173,7 +173,7 @@ impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> { debug!("add_implied_bounds()"); for &ty in fn_sig_tys { - let ty = infcx.resolve_vars_if_possible(&ty); + let ty = infcx.resolve_vars_if_possible(ty); debug!("add_implied_bounds: ty = {}", ty); let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span); self.add_outlives_bounds(Some(infcx), implied_bounds) diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 37538e7aac495..82bce182d406f 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -112,7 +112,7 @@ pub trait InferCtxtExt<'tcx> { parent_def_id: LocalDefId, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, value_span: Span, ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>; @@ -188,7 +188,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { parent_def_id: LocalDefId, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, value_span: Span, ) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> { debug!( @@ -402,7 +402,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let tcx = self.tcx; - let concrete_ty = self.resolve_vars_if_possible(&opaque_defn.concrete_ty); + let concrete_ty = self.resolve_vars_if_possible(opaque_defn.concrete_ty); debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty); @@ -1001,7 +1001,7 @@ struct Instantiator<'a, 'tcx> { } impl<'a, 'tcx> Instantiator<'a, 'tcx> { - fn instantiate_opaque_types_in_map>(&mut self, value: &T) -> T { + fn instantiate_opaque_types_in_map>(&mut self, value: T) -> T { debug!("instantiate_opaque_types_in_map(value={:?})", value); let tcx = self.infcx.tcx; value.fold_with(&mut BottomUpFolder { @@ -1125,7 +1125,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { let param_env = tcx.param_env(def_id); let InferOk { value: bounds, obligations } = - infcx.partially_normalize_associated_types_in(span, self.body_id, param_env, &bounds); + infcx.partially_normalize_associated_types_in(span, self.body_id, param_env, bounds); self.obligations.extend(obligations); debug!("instantiate_opaque_types: bounds={:?}", bounds); @@ -1173,7 +1173,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { // Change the predicate to refer to the type variable, // which will be the concrete type instead of the opaque type. // This also instantiates nested instances of `impl Trait`. - let predicate = self.instantiate_opaque_types_in_map(&predicate); + let predicate = self.instantiate_opaque_types_in_map(predicate); let cause = traits::ObligationCause::new(span, self.body_id, traits::MiscObligation); diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 93a0073588ec7..6ab16886ed237 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -304,11 +304,8 @@ impl AutoTraitFinder<'tcx> { // Call `infcx.resolve_vars_if_possible` to see if we can // get rid of any inference variables. - let obligation = infcx.resolve_vars_if_possible(&Obligation::new( - dummy_cause.clone(), - new_env, - pred, - )); + let obligation = + infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred)); let result = select.select(&obligation); match &result { @@ -627,7 +624,7 @@ impl AutoTraitFinder<'tcx> { fresh_preds.insert(self.clean_pred(select.infcx(), obligation.predicate)); // Resolve any inference variables that we can, to help selection succeed - let predicate = select.infcx().resolve_vars_if_possible(&obligation.predicate); + let predicate = select.infcx().resolve_vars_if_possible(obligation.predicate); // We only add a predicate as a user-displayable bound if // it involves a generic parameter, and doesn't contain diff --git a/compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs b/compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs index adc8ae5908656..026ab414443a8 100644 --- a/compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs @@ -37,7 +37,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { obligation: PredicateObligation<'tcx>, ) { assert!(!infcx.is_in_snapshot()); - let obligation = infcx.resolve_vars_if_possible(&obligation); + let obligation = infcx.resolve_vars_if_possible(obligation); self.obligations.insert(obligation); } @@ -80,11 +80,11 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { // We iterate over all obligations, and record if we are able // to unambiguously prove at least one obligation. for obligation in self.obligations.drain(..) { - let obligation = infcx.resolve_vars_if_possible(&obligation); + let obligation = infcx.resolve_vars_if_possible(obligation); let environment = obligation.param_env.caller_bounds(); let goal = ChalkEnvironmentAndGoal { environment, goal: obligation.predicate }; let mut orig_values = OriginalQueryValues::default(); - let canonical_goal = infcx.canonicalize_query(&goal, &mut orig_values); + let canonical_goal = infcx.canonicalize_query(goal, &mut orig_values); match infcx.tcx.evaluate_goal(canonical_goal) { Ok(response) => { @@ -100,7 +100,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> { Ok(infer_ok) => next_round.extend( infer_ok.obligations.into_iter().map(|obligation| { assert!(!infcx.is_in_snapshot()); - infcx.resolve_vars_if_possible(&obligation) + infcx.resolve_vars_if_possible(obligation) }), ), diff --git a/compiler/rustc_trait_selection/src/traits/codegen.rs b/compiler/rustc_trait_selection/src/traits/codegen.rs index 3cb6ec8626186..657d5c123e8e4 100644 --- a/compiler/rustc_trait_selection/src/traits/codegen.rs +++ b/compiler/rustc_trait_selection/src/traits/codegen.rs @@ -25,7 +25,7 @@ pub fn codegen_fulfill_obligation<'tcx>( (param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>), ) -> Result, ErrorReported> { // Remove any references to regions; this helps improve caching. - let trait_ref = tcx.erase_regions(&trait_ref); + let trait_ref = tcx.erase_regions(trait_ref); // We expect the input to be fully normalized. debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref)); debug!( @@ -89,7 +89,7 @@ pub fn codegen_fulfill_obligation<'tcx>( debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate); fulfill_cx.register_predicate_obligation(&infcx, predicate); }); - let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, &impl_source); + let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, impl_source); info!("Cache miss: {:?} => {:?}", trait_ref, impl_source); Ok(impl_source) @@ -110,7 +110,7 @@ pub fn codegen_fulfill_obligation<'tcx>( fn drain_fulfillment_cx_or_panic( infcx: &InferCtxt<'_, 'tcx>, fulfill_cx: &mut FulfillmentContext<'tcx>, - result: &T, + result: T, ) -> T where T: TypeFoldable<'tcx>, @@ -128,5 +128,5 @@ where } let result = infcx.resolve_vars_if_possible(result); - infcx.tcx.erase_regions(&result) + infcx.tcx.erase_regions(result) } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index c53c65c00b769..9324d55ac1b2d 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -103,7 +103,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>( }; let Normalized { value: mut header, obligations } = - traits::normalize(selcx, param_env, ObligationCause::dummy(), &header); + traits::normalize(selcx, param_env, ObligationCause::dummy(), header); header.predicates.extend(obligations.into_iter().map(|o| o.predicate)); header @@ -162,7 +162,8 @@ fn overlap_within_probe( let opt_failing_obligation = a_impl_header .predicates .iter() - .chain(&b_impl_header.predicates) + .copied() + .chain(b_impl_header.predicates) .map(|p| infcx.resolve_vars_if_possible(p)) .map(|p| Obligation { cause: ObligationCause::dummy(), @@ -188,7 +189,7 @@ fn overlap_within_probe( } } - let impl_header = selcx.infcx().resolve_vars_if_possible(&a_impl_header); + let impl_header = selcx.infcx().resolve_vars_if_possible(a_impl_header); let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes(); debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2d57c39f7c7e1..11c99c7a18470 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -182,7 +182,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { where T: fmt::Display + TypeFoldable<'tcx>, { - let predicate = self.resolve_vars_if_possible(&obligation.predicate); + let predicate = self.resolve_vars_if_possible(obligation.predicate.clone()); let mut err = struct_span_err!( self.tcx.sess, obligation.cause.span, @@ -213,7 +213,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// we do not suggest increasing the overflow limit, which is not /// going to help). fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! { - let cycle = self.resolve_vars_if_possible(&cycle.to_owned()); + let cycle = self.resolve_vars_if_possible(cycle.to_owned()); assert!(!cycle.is_empty()); debug!("report_overflow_error_cycle: cycle={:?}", cycle); @@ -259,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { match bound_predicate.skip_binder() { ty::PredicateAtom::Trait(trait_predicate, _) => { let trait_predicate = bound_predicate.rebind(trait_predicate); - let trait_predicate = self.resolve_vars_if_possible(&trait_predicate); + let trait_predicate = self.resolve_vars_if_possible(trait_predicate); if self.tcx.sess.has_errors() && trait_predicate.references_error() { return; @@ -414,17 +414,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.span_label(enclosing_scope_span, s.as_str()); } - self.suggest_dereferences(&obligation, &mut err, &trait_ref, points_at_arg); - self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg); - self.suggest_remove_reference(&obligation, &mut err, &trait_ref); - self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref); + self.suggest_dereferences(&obligation, &mut err, trait_ref, points_at_arg); + self.suggest_fn_call(&obligation, &mut err, trait_ref, points_at_arg); + self.suggest_remove_reference(&obligation, &mut err, trait_ref); + self.suggest_semicolon_removal(&obligation, &mut err, span, trait_ref); self.note_version_mismatch(&mut err, &trait_ref); if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() { - self.suggest_await_before_try(&mut err, &obligation, &trait_ref, span); + self.suggest_await_before_try(&mut err, &obligation, trait_ref, span); } - if self.suggest_impl_trait(&mut err, span, &obligation, &trait_ref) { + if self.suggest_impl_trait(&mut err, span, &obligation, trait_ref) { err.emit(); return; } @@ -487,7 +487,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { self.suggest_change_mut( &obligation, &mut err, - &trait_ref, + trait_ref, points_at_arg, ); } @@ -533,7 +533,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ty::PredicateAtom::RegionOutlives(predicate) => { let predicate = bound_predicate.rebind(predicate); - let predicate = self.resolve_vars_if_possible(&predicate); + let predicate = self.resolve_vars_if_possible(predicate); let err = self .region_outlives_predicate(&obligation.cause, predicate) .err() @@ -549,7 +549,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => { - let predicate = self.resolve_vars_if_possible(&obligation.predicate); + let predicate = self.resolve_vars_if_possible(obligation.predicate); struct_span_err!( self.tcx.sess, span, @@ -672,8 +672,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => { - let found_trait_ref = self.resolve_vars_if_possible(&*found_trait_ref); - let expected_trait_ref = self.resolve_vars_if_possible(&*expected_trait_ref); + let found_trait_ref = self.resolve_vars_if_possible(*found_trait_ref); + let expected_trait_ref = self.resolve_vars_if_possible(*expected_trait_ref); if expected_trait_ref.self_ty().references_error() { return; @@ -1035,7 +1035,7 @@ trait InferCtxtPrivExt<'tcx> { fn mk_trait_obligation_with_new_self_ty( &self, param_env: ty::ParamEnv<'tcx>, - trait_ref: &ty::PolyTraitRef<'tcx>, + trait_ref: ty::PolyTraitRef<'tcx>, new_self_ty: Ty<'tcx>, ) -> PredicateObligation<'tcx>; @@ -1157,7 +1157,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { obligation: &PredicateObligation<'tcx>, error: &MismatchedProjectionTypes<'tcx>, ) { - let predicate = self.resolve_vars_if_possible(&obligation.predicate); + let predicate = self.resolve_vars_if_possible(obligation.predicate); if predicate.references_error() { return; @@ -1178,7 +1178,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, infer::LateBoundRegionConversionTime::HigherRankedType, - &bound_predicate.rebind(data), + bound_predicate.rebind(data), ); let mut obligations = vec![]; let normalized_ty = super::normalize_projection_type( @@ -1343,7 +1343,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // Sort impl candidates so that ordering is consistent for UI tests. let mut normalized_impl_candidates = - impl_candidates.iter().map(normalize).collect::>(); + impl_candidates.iter().copied().map(normalize).collect::>(); // Sort before taking the `..end` range, // because the ordering of `impl_candidates` may not be deterministic: @@ -1364,7 +1364,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { ) -> Option<(String, Option)> { match code { &ObligationCauseCode::BuiltinDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); match self.get_parent_trait_ref(&data.parent_code) { Some(t) => Some(t), None => { @@ -1414,7 +1414,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { fn mk_trait_obligation_with_new_self_ty( &self, param_env: ty::ParamEnv<'tcx>, - trait_ref: &ty::PolyTraitRef<'tcx>, + trait_ref: ty::PolyTraitRef<'tcx>, new_self_ty: Ty<'tcx>, ) -> PredicateObligation<'tcx> { assert!(!new_self_ty.has_escaping_bound_vars()); @@ -1441,7 +1441,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // ambiguous impls. The latter *ought* to be a // coherence violation, so we don't report it here. - let predicate = self.resolve_vars_if_possible(&obligation.predicate); + let predicate = self.resolve_vars_if_possible(obligation.predicate); let span = obligation.cause.span; debug!( @@ -1673,7 +1673,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { &mut selcx, param_env, ObligationCause::dummy(), - &cleaned_pred, + cleaned_pred, ) .value; @@ -1808,7 +1808,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { cause_code: &ObligationCauseCode<'tcx>, ) -> bool { if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code { - let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) { return true; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 0f5aad5af1229..1b5375938af6d 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -36,7 +36,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) -> Option { let tcx = self.tcx; let param_env = obligation.param_env; - let trait_ref = tcx.erase_late_bound_regions(&trait_ref); + let trait_ref = tcx.erase_late_bound_regions(trait_ref); let trait_self_ty = trait_ref.self_ty(); let mut self_match_impls = vec![]; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 1c6e661782f4b..7e92df28ca27e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -49,7 +49,7 @@ pub trait InferCtxtExt<'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'tcx>, - trait_ref: &ty::PolyTraitRef<'tcx>, + trait_ref: ty::PolyTraitRef<'tcx>, points_at_arg: bool, ); @@ -64,7 +64,7 @@ pub trait InferCtxtExt<'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, points_at_arg: bool, ); @@ -81,14 +81,14 @@ pub trait InferCtxtExt<'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ); fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, points_at_arg: bool, ); @@ -97,7 +97,7 @@ pub trait InferCtxtExt<'tcx> { obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, span: Span, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ); fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option; @@ -107,7 +107,7 @@ pub trait InferCtxtExt<'tcx> { err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ) -> bool; fn point_at_returns_when_relevant( @@ -168,7 +168,7 @@ pub trait InferCtxtExt<'tcx> { &self, err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, span: Span, ); } @@ -462,7 +462,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'tcx>, - trait_ref: &ty::PolyTraitRef<'tcx>, + trait_ref: ty::PolyTraitRef<'tcx>, points_at_arg: bool, ) { // It only make sense when suggesting dereferences for arguments @@ -475,7 +475,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let real_trait_ref = match &obligation.cause.code { ObligationCauseCode::ImplDerivedObligation(cause) | ObligationCauseCode::DerivedObligation(cause) - | ObligationCauseCode::BuiltinDerivedObligation(cause) => &cause.parent_trait_ref, + | ObligationCauseCode::BuiltinDerivedObligation(cause) => cause.parent_trait_ref, _ => trait_ref, }; let real_ty = match real_trait_ref.self_ty().no_bound_vars() { @@ -556,7 +556,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, points_at_arg: bool, ) { let self_ty = match trait_ref.self_ty().no_bound_vars() { @@ -734,7 +734,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ) { let span = obligation.cause.span; @@ -797,7 +797,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, points_at_arg: bool, ) { let span = obligation.cause.span; @@ -832,7 +832,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let new_obligation = self.mk_trait_obligation_with_new_self_ty( obligation.param_env, - &trait_ref, + trait_ref, suggested_ty, ); let suggested_ty_would_satisfy_obligation = self @@ -869,7 +869,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, span: Span, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ) { let is_empty_tuple = |ty: ty::Binder>| *ty.skip_binder().kind() == ty::Tuple(ty::List::empty()); @@ -919,7 +919,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, ) -> bool { match obligation.cause.code.peel_derives() { // Only suggest `impl Trait` if the return type is unsized because it is `dyn Trait`. @@ -976,12 +976,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { .returns .iter() .filter_map(|expr| typeck_results.node_type_opt(expr.hir_id)) - .map(|ty| self.resolve_vars_if_possible(&ty)); + .map(|ty| self.resolve_vars_if_possible(ty)); let (last_ty, all_returns_have_same_type, only_never_return) = ret_types.clone().fold( (None, true, true), |(last_ty, mut same, only_never_return): (std::option::Option>, bool, bool), ty| { - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); same &= !matches!(ty.kind(), ty::Error(_)) && last_ty.map_or(true, |last_ty| { @@ -1133,7 +1133,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let typeck_results = self.in_progress_typeck_results.map(|t| t.borrow()).unwrap(); for expr in &visitor.returns { if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) { - let ty = self.resolve_vars_if_possible(&returned_ty); + let ty = self.resolve_vars_if_possible(returned_ty); err.span_label(expr.span, &format!("this returned value is of type `{}`", ty)); } } @@ -1406,7 +1406,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // Look for a type inside the generator interior that matches the target type to get // a span. - let target_ty_erased = self.tcx.erase_regions(&target_ty); + let target_ty_erased = self.tcx.erase_regions(target_ty); let ty_matches = |ty| -> bool { // Careful: the regions for types that appear in the // generator interior are not generally known, so we @@ -1420,8 +1420,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // generator frame. Bound regions are preserved by // `erase_regions` and so we must also call // `erase_late_bound_regions`. - let ty_erased = self.tcx.erase_late_bound_regions(&ty::Binder::bind(ty)); - let ty_erased = self.tcx.erase_regions(&ty_erased); + let ty_erased = self.tcx.erase_late_bound_regions(ty::Binder::bind(ty)); + let ty_erased = self.tcx.erase_regions(ty_erased); let eq = ty::TyS::same_type(ty_erased, target_ty_erased); debug!( "maybe_note_obligation_cause_for_async_await: ty_erased={:?} \ @@ -1437,7 +1437,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) { interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| { let upvar_ty = typeck_results.node_type(*upvar_id); - let upvar_ty = self.resolve_vars_if_possible(&upvar_ty); + let upvar_ty = self.resolve_vars_if_possible(upvar_ty); if ty_matches(&upvar_ty) { Some(GeneratorInteriorOrUpvar::Upvar(upvar.span)) } else { @@ -2010,7 +2010,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.note("shared static variables must have a type that implements `Sync`"); } ObligationCauseCode::BuiltinDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); let ty = parent_trait_ref.skip_binder().self_ty(); if parent_trait_ref.references_error() { err.cancel(); @@ -2025,8 +2025,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = *data.parent_code { - let parent_trait_ref = - self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); let ty = parent_trait_ref.skip_binder().self_ty(); matches!(ty.kind(), ty::Generator(..)) || matches!(ty.kind(), ty::Closure(..)) @@ -2056,7 +2055,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } ObligationCauseCode::ImplDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); err.note(&format!( "required because of the requirements on the impl of `{}` for `{}`", parent_trait_ref.print_only_trait_path(), @@ -2074,7 +2073,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { }); } ObligationCauseCode::DerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref); let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); // #74711: avoid a stack overflow ensure_sufficient_stack(|| { @@ -2132,7 +2131,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, - trait_ref: &ty::Binder>, + trait_ref: ty::Binder>, span: Span, ) { debug!( @@ -2150,13 +2149,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let Some(hir::GeneratorKind::Async(_)) = body.generator_kind { let future_trait = self.tcx.require_lang_item(LangItem::Future, None); - let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty()); + let self_ty = self.resolve_vars_if_possible(trait_ref.self_ty()); // Do not check on infer_types to avoid panic in evaluate_obligation. if self_ty.has_infer_types() { return; } - let self_ty = self.tcx.erase_regions(&self_ty); + let self_ty = self.tcx.erase_regions(self_ty); let impls_future = self.tcx.type_implements_trait(( future_trait, @@ -2197,7 +2196,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { debug!( "suggest_await_before_try: normalized_projection_type {:?}", - self.resolve_vars_if_possible(&normalized_ty) + self.resolve_vars_if_possible(normalized_ty) ); let try_obligation = self.mk_trait_obligation_with_new_self_ty( obligation.param_env, diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 538c14c6b720e..a04f816b0f8a0 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -202,7 +202,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> { ) { // this helps to reduce duplicate errors, as well as making // debug output much nicer to read and so on. - let obligation = infcx.resolve_vars_if_possible(&obligation); + let obligation = infcx.resolve_vars_if_possible(obligation); debug!(?obligation, "register_predicate_obligation"); @@ -298,7 +298,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { if !change { debug!( "process_predicate: pending obligation {:?} still stalled on {:?}", - self.selcx.infcx().resolve_vars_if_possible(&pending_obligation.obligation), + self.selcx.infcx().resolve_vars_if_possible(pending_obligation.obligation.clone()), pending_obligation.stalled_on ); return ProcessResult::Unchanged; @@ -338,14 +338,14 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { if obligation.predicate.has_infer_types_or_consts() { obligation.predicate = - self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate); + self.selcx.infcx().resolve_vars_if_possible(obligation.predicate); } debug!(?obligation, ?obligation.cause, "process_obligation"); let infcx = self.selcx.infcx(); - match obligation.predicate.kind() { + match *obligation.predicate.kind() { ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { // Evaluation will discard candidates using the leak check. // This means we need to pass it the bound version of our @@ -384,9 +384,9 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { bug!("TypeWellFormedFromEnv is only used for Chalk") } }, - &ty::PredicateKind::Atom(atom) => match atom { - ty::PredicateAtom::Trait(ref data, _) => { - let trait_obligation = obligation.with(Binder::dummy(*data)); + ty::PredicateKind::Atom(atom) => match atom { + ty::PredicateAtom::Trait(data, _) => { + let trait_obligation = obligation.with(Binder::dummy(data)); self.process_trait_obligation( obligation, @@ -639,7 +639,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { debug!( "process_predicate: pending obligation {:?} now stalled on {:?}", - infcx.resolve_vars_if_possible(obligation), + infcx.resolve_vars_if_possible(obligation.clone()), stalled_on ); @@ -684,7 +684,7 @@ fn trait_ref_infer_vars<'a, 'tcx>( ) -> Vec> { selcx .infcx() - .resolve_vars_if_possible(&trait_ref) + .resolve_vars_if_possible(trait_ref) .skip_binder() .substs .iter() diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index e23f5a583b23b..cedd1aa54b876 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -50,7 +50,7 @@ pub fn can_type_implement_copy( let span = tcx.def_span(field.did); let cause = ObligationCause::dummy_with_span(span); let ctx = traits::FulfillmentContext::new(); - match traits::fully_normalize(&infcx, ctx, cause, param_env, &ty) { + match traits::fully_normalize(&infcx, ctx, cause, param_env, ty) { Ok(ty) => { if !infcx.type_is_copy_modulo_regions(param_env, ty, span) { infringing.push(field); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index c93087a18cf04..2d7df2ddd119d 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -223,7 +223,7 @@ fn do_normalize_predicates<'tcx>( // we move over to lazy normalization *anyway*. let fulfill_cx = FulfillmentContext::new_ignoring_regions(); 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, Err(errors) => { infcx.report_fulfillment_errors(&errors, None, false); @@ -243,7 +243,7 @@ fn do_normalize_predicates<'tcx>( RegionckMode::default(), ); - let predicates = match infcx.fully_resolve(&predicates) { + let predicates = match infcx.fully_resolve(predicates) { Ok(predicates) => predicates, Err(fixup_err) => { // 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>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, ) -> Result>> where T: TypeFoldable<'tcx>, @@ -404,7 +404,7 @@ where debug!("fully_normalize: select_all_or_error start"); fulfill_cx.select_all_or_error(infcx)?; 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); Ok(resolved_value) } @@ -424,7 +424,7 @@ pub fn impossible_predicates<'tcx>( let mut fulfill_cx = FulfillmentContext::new(); let cause = ObligationCause::dummy(); 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 { 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() }); - debug!("impossible_predicates(predicates={:?}) = {:?}", predicates, result); + debug!("impossible_predicates = {:?}", result); result } @@ -494,7 +494,7 @@ fn vtable_methods<'tcx>( // erase them if they appear, so that we get the type // at some particular call site. 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 // do not hold for this particular set of type parameters. diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 32e0991733bd9..cc31f6b2c2e56 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -446,7 +446,7 @@ fn virtual_call_violation_for_method<'tcx>( } 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. // However, this is already considered object-safe. We allow it as a special case here. diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index a85ffd3c961b7..de700e4a422ef 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -168,7 +168,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>( let infcx = selcx.infcx(); infcx.commit_if_ok(|_snapshot| { 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 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>, param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, - value: &T, + value: T, ) -> Normalized<'tcx, T> where T: TypeFoldable<'tcx>, @@ -246,7 +246,7 @@ pub fn normalize_to<'a, 'b, 'tcx, T>( selcx: &'a mut SelectionContext<'b, 'tcx>, param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, - value: &T, + value: T, obligations: &mut Vec>, ) -> T where @@ -261,7 +261,7 @@ pub fn normalize_with_depth<'a, 'b, 'tcx, T>( param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, depth: usize, - value: &T, + value: T, ) -> Normalized<'tcx, T> where T: TypeFoldable<'tcx>, @@ -277,7 +277,7 @@ pub fn normalize_with_depth_to<'a, 'b, 'tcx, T>( param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, depth: usize, - value: &T, + value: T, obligations: &mut Vec>, ) -> T where @@ -309,7 +309,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { AssocTypeNormalizer { selcx, param_env, cause, obligations, depth } } - fn fold>(&mut self, value: &T) -> T { + fn fold>(&mut self, value: T) -> T { let value = self.selcx.infcx().resolve_vars_if_possible(value); if !value.has_projections() { value } else { value.fold_with(self) } @@ -474,7 +474,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>( ) -> Result>, InProgress> { 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); // 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, &mut projected_obligations, ); - let normalized_ty = normalizer.fold(&projected_ty); + let normalized_ty = normalizer.fold(projected_ty); debug!(?normalized_ty, ?depth); @@ -1013,8 +1013,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( if obligation.param_env.reveal() == Reveal::All { // NOTE(eddyb) inference variables can resolve to parameters, so // assume `poly_trait_ref` isn't monomorphic, if it contains any. - let poly_trait_ref = - selcx.infcx().resolve_vars_if_possible(&poly_trait_ref); + let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(poly_trait_ref); !poly_trait_ref.still_further_specializable() } else { debug!( @@ -1192,7 +1191,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &gen_sig, + gen_sig, ); debug!(?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate"); @@ -1263,7 +1262,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>( obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &sig, + sig, ); confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes) @@ -1282,7 +1281,7 @@ fn confirm_closure_candidate<'cx, 'tcx>( obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &closure_sig, + closure_sig, ); 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( cause.span, LateBoundRegionConversionTime::HigherRankedType, - &poly_cache_entry, + poly_cache_entry, ); 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.cause.clone(), obligation.recursion_depth + 1, - &cache_trait_ref, + cache_trait_ref, &mut nested_obligations, ) }) @@ -1445,7 +1444,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>( obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &predicate, + predicate, nested, ); 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 // there's no precise match, the original cache entry is "stranded" // anyway. - infcx.resolve_vars_if_possible(&predicate.projection_ty), + infcx.resolve_vars_if_possible(predicate.projection_ty), ) }) } diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 8212823a6dbc7..caafd0c5035eb 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -40,7 +40,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { } 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; debug!("c_ty = {:?}", 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, ) { - 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); return InferOk { value: kinds, obligations }; } diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs index 0569f6217da65..b83a4cd1e5775 100644 --- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs +++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs @@ -65,7 +65,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { ) -> Result { let mut _orig_values = OriginalQueryValues::default(); 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 // in standard trait query mode so that overflow is handled appropriately // within `SelectionContext`. diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 42a598ce3a008..58ab109c491b0 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -19,7 +19,7 @@ use super::NoSolution; pub use rustc_middle::traits::query::NormalizationResult; pub trait AtExt<'tcx> { - fn normalize(&self, value: &T) -> Result, NoSolution> + fn normalize(&self, value: T) -> Result, NoSolution> where 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 /// know that normalization will succeed, since error reporting /// and other details are still "under development". - fn normalize(&self, value: &T) -> Result, NoSolution> + fn normalize(&self, value: T) -> Result, NoSolution> where T: TypeFoldable<'tcx>, { @@ -165,7 +165,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // so we cannot canonicalize it. let c_data = self .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: orig_values = {:#?}", orig_values); match tcx.normalize_projection_ty(c_data) { diff --git a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs index a42409515db1e..8896d0a456940 100644 --- a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs @@ -51,7 +51,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { debug!("implied_outlives_bounds(ty = {:?})", ty); let mut orig_values = OriginalQueryValues::default(); - let key = self.canonicalize_query(¶m_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) { Ok(r) => r, Err(NoSolution) => { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index 915e8ae4a7ad6..1688539165ab5 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -96,7 +96,7 @@ fn scrape_region_constraints<'tcx, R>( region_obligations .iter() .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)), ®ion_constraint_data, ); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs index ed6c6d0cc0a98..e90f61322933f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs @@ -82,7 +82,7 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx { // `'static` otherwise. let mut canonical_var_values = OriginalQueryValues::default(); 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 param_env = query_key.param_env; diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index ea18a689065e3..d2556c44fb453 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -229,7 +229,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { param_env: obligation.param_env, cause: obligation.cause.clone(), 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() { @@ -604,7 +604,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // The code below doesn't care about regions, and the // self-ty here doesn't escape this probe, so just erase // 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() { ty::Dynamic(ref data, ..) => { 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"); - 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 = - 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 // we are looking for. Specifically, do not only check for the diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 872b8e85f563f..7c155c7684ec2 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -126,7 +126,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let trait_predicate = self.infcx.shallow_resolve(obligation.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 (def_id, substs) = match *placeholder_self_ty.kind() { ty::Projection(proj) => (proj.item_def_id, proj.substs), @@ -144,7 +144,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &candidate, + candidate, &mut obligations, ); @@ -163,7 +163,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &predicate, + predicate, &mut obligations, ); obligations.push(Obligation::with_depth( @@ -285,8 +285,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let trait_obligations: Vec> = self.infcx.commit_unconditionally(|_| { let poly_trait_ref = obligation.predicate.to_poly_trait_ref(); - let trait_ref = - self.infcx.replace_bound_vars_with_placeholders(&poly_trait_ref); + let trait_ref = self.infcx.replace_bound_vars_with_placeholders(poly_trait_ref); let cause = obligation.derived_cause(ImplDerivedObligation); self.impl_or_trait_obligations( cause, @@ -370,11 +369,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.tcx(); debug!(?obligation, ?index, "confirm_object_candidate"); - let trait_predicate = - self.infcx.replace_bound_vars_with_placeholders(&obligation.predicate); + let trait_predicate = self.infcx.replace_bound_vars_with_placeholders(obligation.predicate); let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty()); 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, ..) => { self.infcx .replace_bound_vars_with_fresh_vars( @@ -416,7 +414,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &unnormalized_upcast_trait_ref, + unnormalized_upcast_trait_ref, &mut nested, ); @@ -442,7 +440,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &super_trait, + super_trait, &mut nested, ); nested.push(Obligation::new( @@ -480,7 +478,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &subst_bound, + subst_bound, &mut nested, ); nested.push(Obligation::new( @@ -520,7 +518,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), 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"); self.infcx.commit_unconditionally(|_| { - let predicate = - self.infcx().replace_bound_vars_with_placeholders(&obligation.predicate); + let predicate = self.infcx().replace_bound_vars_with_placeholders(obligation.predicate); let trait_ref = predicate.trait_ref; let trait_def_id = trait_ref.def_id; let substs = trait_ref.substs; @@ -584,7 +581,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &trait_ref, + trait_ref, ) }); @@ -627,7 +624,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &trait_ref, + trait_ref, ) }); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index a91f693f17596..05ff9a6fb9ca6 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1019,7 +1019,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } 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 // trait-ref-is-knowable check, which does not care about @@ -1138,9 +1138,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &mut self, obligation: &TraitObligation<'tcx>, ) -> 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 = - self.infcx().replace_bound_vars_with_placeholders(&poly_trait_predicate); + self.infcx().replace_bound_vars_with_placeholders(poly_trait_predicate); debug!( ?placeholder_trait_predicate, "match_projection_obligation_against_definition_bounds" @@ -1220,7 +1220,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &trait_bound, + trait_bound, ) }); self.infcx @@ -1266,12 +1266,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - &data.map_bound_ref(|data| data.projection_ty), + data.map_bound(|data| data.projection_ty), &mut nested_obligations, ) }) } else { - data.map_bound_ref(|data| data.projection_ty) + data.map_bound(|data| data.projection_ty) }; // FIXME(generic_associated_types): Compare the whole projections @@ -1737,7 +1737,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let ty: ty::Binder> = ty::Binder::bind(ty); // <----/ 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 } = ensure_sufficient_stack(|| { project::normalize_with_depth( @@ -1745,7 +1745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { param_env, cause.clone(), recursion_depth, - &placeholder_ty, + placeholder_ty, ) }); let placeholder_obligation = predicate_for_trait_def( @@ -1807,7 +1807,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } 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 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.cause.clone(), obligation.recursion_depth + 1, - &impl_trait_ref, + impl_trait_ref, ) }); @@ -2028,7 +2028,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { param_env, cause.clone(), recursion_depth, - &predicate.subst(tcx, substs), + predicate.subst(tcx, substs), &mut obligations, ); obligations.push(Obligation { diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 4d81a3baa0edc..512591960f551 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -158,7 +158,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, FulfillmentContext::new(), ObligationCause::dummy(), penv, - &impl1_trait_ref, + impl1_trait_ref, ) { Ok(impl1_trait_ref) => impl1_trait_ref, Err(err) => { @@ -247,7 +247,7 @@ fn fulfill_implication<'a, 'tcx>( // Now resolve the *substitution* we built for the target earlier, replacing // 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)) } } }) diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index f626bb0b7e365..2430620323f72 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -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 = impl_trait_ref.subst(selcx.tcx(), impl_substs); 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 = predicates.instantiate(selcx.tcx(), impl_substs); 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 = predicates_for_generics(ObligationCause::dummy(), 0, param_env, predicates); diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 496dff6c5b2cf..e5a792f229d19 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -269,7 +269,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { param_env, cause.clone(), self.recursion_depth, - &obligation.predicate, + obligation.predicate, &mut obligations, ); obligation.predicate = normalized_predicate; diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index c5a46b1003dfa..b1b9ef343d5a1 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -227,7 +227,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars( &self.interner, self.interner.tcx, - &sig.inputs_and_output().subst(self.interner.tcx, bound_vars), + sig.inputs_and_output().subst(self.interner.tcx, bound_vars), ); let argument_types = inputs_and_output[..inputs_and_output.len() - 1] @@ -461,7 +461,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t ) -> Arc>> { let bound_vars = ty::fold::shift_vars( self.interner.tcx, - &bound_vars_for_item(self.interner.tcx, opaque_ty_id.0), + bound_vars_for_item(self.interner.tcx, opaque_ty_id.0), 1, ); let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index c4e2c7f839d70..6a5d7f96c824d 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -86,7 +86,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment { @@ -141,7 +141,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi let (predicate, binders, _named_regions) = collect_bound_vars( interner, interner.tcx, - &self.bound_atom_with_opt_escaping(interner.tcx), + self.bound_atom_with_opt_escaping(interner.tcx), ); let value = match predicate { @@ -293,7 +293,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { } ty::FnPtr(sig) => { let (inputs_and_outputs, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output()); + collect_bound_vars(interner, interner.tcx, sig.inputs_and_output()); chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: binders.len(interner), sig: sig.lower_into(interner), @@ -578,7 +578,7 @@ impl<'tcx> LowerInto<'tcx, Option { @@ -627,10 +627,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders>]> // This means that any variables that are escaping `self` need to be // shifted in by one so that they are still escaping. - let shifted_predicates = ty::fold::shift_vars(interner.tcx, &self, 1); + let shifted_predicates = ty::fold::shift_vars(interner.tcx, self, 1); let (predicates, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, &shifted_predicates); + collect_bound_vars(interner, interner.tcx, shifted_predicates); let self_ty = interner.tcx.mk_ty(ty::Bound( // This is going to be wrapped in a binder ty::DebruijnIndex::from_usize(1), @@ -707,7 +707,7 @@ impl<'tcx> LowerInto<'tcx, Option Some(chalk_ir::Binders::new( @@ -808,10 +808,10 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound /// It's important to note that because of prior substitution, we may have /// late-bound regions, even outside of fn contexts, since this is the best way /// to prep types for chalk lowering. -crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>( +crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( interner: &RustInterner<'tcx>, tcx: TyCtxt<'tcx>, - ty: &'a Binder, + ty: Binder, ) -> (T, chalk_ir::VariableKinds>, BTreeMap) { let mut bound_vars_collector = BoundVarsCollector::new(); ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector); @@ -824,7 +824,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>( .collect(); let mut bound_var_substitutor = NamedBoundVarSubstitutor::new(tcx, &named_parameters); - let new_ty = ty.as_ref().skip_binder().fold_with(&mut bound_var_substitutor); + let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor); for var in named_parameters.values() { parameters.insert(*var, chalk_ir::VariableKind::Lifetime); @@ -833,7 +833,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>( (0..parameters.len()).for_each(|i| { parameters .get(&(i as u32)) - .or_else(|| bug!("Skipped bound var index: ty={:?}, parameters={:?}", ty, parameters)); + .or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters)); }); let binders = @@ -941,7 +941,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &Binder) -> Binder { + fn fold_binder>(&mut self, t: Binder) -> Binder { self.binder_index.shift_in(1); let result = t.super_fold_with(self); self.binder_index.shift_out(1); @@ -1001,7 +1001,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> { self.tcx } - fn fold_binder>(&mut self, t: &Binder) -> Binder { + fn fold_binder>(&mut self, t: Binder) -> Binder { self.binder_index.shift_in(1); let result = t.super_fold_with(self); self.binder_index.shift_out(1); diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index 6cffa6d02a4e3..2827163d854d5 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -106,7 +106,7 @@ fn dropck_outlives<'tcx>( // do not themselves define a destructor", more or less. We have // to push them onto the stack to be expanded. for ty in constraints.dtorck_types.drain(..) { - match infcx.at(&cause, param_env).normalize(&ty) { + match infcx.at(&cause, param_env).normalize(ty) { Ok(Normalized { value: ty, obligations }) => { fulfill_cx.register_predicate_obligations(infcx, obligations); diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index c44fd1d58593f..97017fbf2e56a 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -115,7 +115,7 @@ fn compute_implied_outlives_bounds<'tcx>( } ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => { - let ty_a = infcx.resolve_vars_if_possible(&ty_a); + let ty_a = infcx.resolve_vars_if_possible(ty_a); let mut components = smallvec![]; tcx.push_outlives_components(ty_a, &mut components); implied_bounds_from_components(r_b, components) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 3e7c9ac62eb8e..750a0922be4d1 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -21,7 +21,7 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( tcx.sess.perf_stats.normalize_generic_arg_after_erasing_regions.fetch_add(1, Ordering::Relaxed); tcx.infer_ctxt().enter(|infcx| { let cause = ObligationCause::dummy(); - match infcx.at(&cause, param_env).normalize(&value) { + match infcx.at(&cause, param_env).normalize(value) { Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => { // We don't care about the `obligations`; they are // always only region relations, and we are about to @@ -31,8 +31,8 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( None, ); - let normalized_value = infcx.resolve_vars_if_possible(&normalized_value); - infcx.tcx.erase_regions(&normalized_value) + let normalized_value = infcx.resolve_vars_if_possible(normalized_value); + infcx.tcx.erase_regions(normalized_value) } Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), } diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 139ed6dcd350c..0addde5c44c89 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -70,7 +70,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { DUMMY_SP, hir::CRATE_HIR_ID, self.param_env, - &value, + value, ) .into_value_registering_obligations(self.infcx, self.fulfill_cx) } @@ -184,7 +184,7 @@ where { let (param_env, Normalize { value }) = key.into_parts(); let Normalized { value, obligations } = - infcx.at(&ObligationCause::dummy(), param_env).normalize(&value)?; + infcx.at(&ObligationCause::dummy(), param_env).normalize(value)?; fulfill_cx.register_predicate_obligations(infcx, obligations); Ok(value) } diff --git a/compiler/rustc_ty/src/instance.rs b/compiler/rustc_ty/src/instance.rs index 220f4cec742f1..cf2c6efb4711f 100644 --- a/compiler/rustc_ty/src/instance.rs +++ b/compiler/rustc_ty/src/instance.rs @@ -51,7 +51,7 @@ fn inner_resolve_instance<'tcx>( resolve_associated_item(tcx, &item, param_env, trait_def_id, substs) } else { let ty = tcx.type_of(def.def_id_for_type_of()); - let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, &ty); + let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, ty); let def = match *item_type.kind() { ty::FnDef(..) @@ -146,7 +146,7 @@ fn resolve_associated_item<'tcx>( substs, leaf_def.defining_node, ); - infcx.tcx.erase_regions(&substs) + infcx.tcx.erase_regions(substs) }); // Since this is a trait item, we need to see if the item is either a trait default item @@ -172,7 +172,7 @@ fn resolve_associated_item<'tcx>( return Ok(None); } - let substs = tcx.erase_regions(&substs); + let substs = tcx.erase_regions(substs); // Check if we just resolved an associated `const` declaration from // a `trait` to an associated `const` definition in an `impl`, where @@ -192,7 +192,7 @@ fn resolve_associated_item<'tcx>( && leaf_def.item.def_id.is_local() { let normalized_type_of = |def_id, substs| { - tcx.subst_and_normalize_erasing_regions(substs, param_env, &tcx.type_of(def_id)) + tcx.subst_and_normalize_erasing_regions(substs, param_env, tcx.type_of(def_id)) }; let original_ty = normalized_type_of(trait_item.def_id, rcvr_substs); @@ -264,7 +264,7 @@ fn resolve_associated_item<'tcx>( assert_eq!(name, sym::clone_from); // Use the default `fn clone_from` from `trait Clone`. - let substs = tcx.erase_regions(&rcvr_substs); + let substs = tcx.erase_regions(rcvr_substs); Some(ty::Instance::new(def_id, substs)) } } else { diff --git a/compiler/rustc_ty/src/needs_drop.rs b/compiler/rustc_ty/src/needs_drop.rs index 0356bcec5498b..d62fc764c76d7 100644 --- a/compiler/rustc_ty/src/needs_drop.rs +++ b/compiler/rustc_ty/src/needs_drop.rs @@ -107,7 +107,7 @@ where let witness = substs.witness(); let interior_tys = match witness.kind() { - ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys), + &ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys), _ => { tcx.sess.delay_span_bug( tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP), diff --git a/compiler/rustc_ty/src/ty.rs b/compiler/rustc_ty/src/ty.rs index 2562140bb5d7e..720ad42da2aaa 100644 --- a/compiler/rustc_ty/src/ty.rs +++ b/compiler/rustc_ty/src/ty.rs @@ -363,7 +363,7 @@ fn well_formed_types_in_env<'tcx>( // well-formed. NodeKind::Fn => { let fn_sig = tcx.fn_sig(def_id); - let fn_sig = tcx.liberate_late_bound_regions(def_id, &fn_sig); + let fn_sig = tcx.liberate_late_bound_regions(def_id, fn_sig); inputs.extend(fn_sig.inputs().iter().flat_map(|ty| ty.walk())); } diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index e8eea65137ff7..3a5eeb5381bec 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -131,7 +131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { id, self.body_id, self.param_env, - &ty, + ty, arm.body.span, ); let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty(); diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index a38fb9642b92e..ebfb401fcf3ad 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .replace_bound_vars_with_fresh_vars( call_expr.span, infer::FnCall, - &closure_sig, + closure_sig, ) .0; let adjustments = self.adjust_steps(autoderef); @@ -407,8 +407,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // previously appeared within a `Binder<>` and hence would not // have been normalized before. let fn_sig = - self.replace_bound_vars_with_fresh_vars(call_expr.span, infer::FnCall, &fn_sig).0; - let fn_sig = self.normalize_associated_types_in(call_expr.span, &fn_sig); + self.replace_bound_vars_with_fresh_vars(call_expr.span, infer::FnCall, fn_sig).0; + let fn_sig = self.normalize_associated_types_in(call_expr.span, fn_sig); // Call the generic checker. let expected_arg_tys = self.expected_inputs_for_expected_output( diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 5c2bdb86f76c9..36240a9b41e7d 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -87,7 +87,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Result>, ErrorReported> { debug!("pointer_kind({:?}, {:?})", t, span); - let t = self.resolve_vars_if_possible(&t); + let t = self.resolve_vars_if_possible(t); if t.references_error() { return Err(ErrorReported); @@ -377,12 +377,12 @@ impl<'a, 'tcx> CastCheck<'tcx> { // Check `impl From for self.cast_ty {}` for accurate suggestion: if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) { if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::from_trait) { - let ty = fcx.resolve_vars_if_possible(&self.cast_ty); + let ty = fcx.resolve_vars_if_possible(self.cast_ty); // Erase regions to avoid panic in `prove_value` when calling // `type_implements_trait`. - let ty = fcx.tcx.erase_regions(&ty); - let expr_ty = fcx.resolve_vars_if_possible(&self.expr_ty); - let expr_ty = fcx.tcx.erase_regions(&expr_ty); + let ty = fcx.tcx.erase_regions(ty); + let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); + let expr_ty = fcx.tcx.erase_regions(expr_ty); let ty_params = fcx.tcx.mk_substs_trait(expr_ty, &[]); // Check for infer types because cases like `Option<{integer}>` would // panic otherwise. @@ -471,7 +471,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { self.expr_ty, E0620, "cast to unsized type: `{}` as `{}`", - fcx.resolve_vars_if_possible(&self.expr_ty), + fcx.resolve_vars_if_possible(self.expr_ty), tstr ); match self.expr_ty.kind() { @@ -607,7 +607,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // Attempt a coercion to a fn pointer type. let f = fcx.normalize_associated_types_in( self.expr.span, - &self.expr_ty.fn_sig(fcx.tcx), + self.expr_ty.fn_sig(fcx.tcx), ); let res = fcx.try_coerce( self.expr, diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 70d94ef869d05..631d4bb34f8fe 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -75,7 +75,7 @@ pub(super) fn check_fn<'a, 'tcx>( let declared_ret_ty = fn_sig.output(); let revealed_ret_ty = - fcx.instantiate_opaque_types_from_value(fn_id, &declared_ret_ty, decl.output.span()); + fcx.instantiate_opaque_types_from_value(fn_id, declared_ret_ty, decl.output.span()); debug!("check_fn: declared_ret_ty: {}, revealed_ret_ty: {}", declared_ret_ty, revealed_ret_ty); fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty))); fcx.ret_type_span = Some(decl.output.span()); @@ -601,7 +601,7 @@ fn check_opaque_meets_bounds<'tcx>( let misc_cause = traits::ObligationCause::misc(span, hir_id); let (_, opaque_type_map) = inh.register_infer_ok_obligations( - infcx.instantiate_opaque_types(def_id, hir_id, param_env, &opaque_ty, span), + infcx.instantiate_opaque_types(def_id, hir_id, param_env, opaque_ty, span), ); for (def_id, opaque_defn) in opaque_type_map { diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index 2ba05071c0500..8082a230216e2 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -257,7 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let input_tys = if is_fn { let arg_param_ty = trait_ref.skip_binder().substs.type_at(1); - let arg_param_ty = self.resolve_vars_if_possible(&arg_param_ty); + let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty); debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty); match arg_param_ty.kind() { @@ -271,7 +271,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let ret_param_ty = projection.skip_binder().ty; - let ret_param_ty = self.resolve_vars_if_possible(&ret_param_ty); + let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty); debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty); let sig = self.tcx.mk_fn_sig( @@ -400,7 +400,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `deduce_expectations_from_expected_type` introduces // late-bound lifetimes defined elsewhere, which we now // anonymize away, so as not to confuse the user. - let bound_sig = self.tcx.anonymize_late_bound_regions(&bound_sig); + let bound_sig = self.tcx.anonymize_late_bound_regions(bound_sig); let closure_sigs = self.closure_sigs(expr_def_id, body, bound_sig); @@ -500,7 +500,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (supplied_ty, _) = self.infcx.replace_bound_vars_with_fresh_vars( hir_ty.span, LateBoundRegionConversionTime::FnCall, - &ty::Binder::bind(supplied_ty), + ty::Binder::bind(supplied_ty), ); // recreated from (*) above // Check that E' = S'. @@ -513,7 +513,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (supplied_output_ty, _) = self.infcx.replace_bound_vars_with_fresh_vars( decl.output.span(), LateBoundRegionConversionTime::FnCall, - &supplied_sig.output(), + supplied_sig.output(), ); let cause = &self.misc(decl.output.span()); let InferOk { value: (), obligations } = self @@ -578,7 +578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("supplied_sig_of_closure: result={:?}", result); - let c_result = self.inh.infcx.canonicalize_response(&result); + let c_result = self.inh.infcx.canonicalize_response(result); self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result); result @@ -683,7 +683,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Extract the type from the projection. Note that there can // be no bound variables in this type because the "self type" // does not have any regions in it. - let output_ty = self.resolve_vars_if_possible(&predicate.ty); + let output_ty = self.resolve_vars_if_possible(predicate.ty); debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty); Some(output_ty) } @@ -723,12 +723,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { body: &hir::Body<'_>, bound_sig: ty::PolyFnSig<'tcx>, ) -> ClosureSignatures<'tcx> { - let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, &bound_sig); + let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, bound_sig); let liberated_sig = self.inh.normalize_associated_types_in( body.value.span, body.value.hir_id, self.param_env, - &liberated_sig, + liberated_sig, ); ClosureSignatures { bound_sig, liberated_sig } } diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 6da3ecde329cf..0f5f0ab026087 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -606,7 +606,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // Uncertain or unimplemented. Ok(None) => { if trait_pred.def_id() == unsize_did { - let trait_pred = self.resolve_vars_if_possible(&trait_pred); + let trait_pred = self.resolve_vars_if_possible(trait_pred); let self_ty = trait_pred.skip_binder().self_ty(); let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty(); debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred); @@ -732,7 +732,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } let InferOk { value: a_sig, mut obligations } = - self.normalize_associated_types_in_as_infer_ok(self.cause.span, &a_sig); + self.normalize_associated_types_in_as_infer_ok(self.cause.span, a_sig); let a_fn_pointer = self.tcx.mk_fn_ptr(a_sig); let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn( @@ -973,8 +973,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; if let (Some(a_sig), Some(b_sig)) = (a_sig, b_sig) { // The signature must match. - let a_sig = self.normalize_associated_types_in(new.span, &a_sig); - let b_sig = self.normalize_associated_types_in(new.span, &b_sig); + let a_sig = self.normalize_associated_types_in(new.span, a_sig); + let b_sig = self.normalize_associated_types_in(new.span, b_sig); let sig = self .at(cause, self.param_env) .trace(prev_ty, new_ty) @@ -1490,7 +1490,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { *sp, &format!( "return type inferred to be `{}` here", - fcx.resolve_vars_if_possible(&expected) + fcx.resolve_vars_if_possible(expected) ), ); } diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 4acc7451a2131..20090d3760600 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -224,11 +224,11 @@ fn compare_predicate_entailment<'tcx>( let (impl_m_own_bounds, _) = infcx.replace_bound_vars_with_fresh_vars( impl_m_span, infer::HigherRankedType, - &ty::Binder::bind(impl_m_own_bounds.predicates), + ty::Binder::bind(impl_m_own_bounds.predicates), ); for predicate in impl_m_own_bounds { let traits::Normalized { value: predicate, obligations } = - traits::normalize(&mut selcx, param_env, normalize_cause.clone(), &predicate); + traits::normalize(&mut selcx, param_env, normalize_cause.clone(), predicate); inh.register_predicates(obligations); inh.register_predicate(traits::Obligation::new(cause.clone(), param_env, predicate)); @@ -253,17 +253,17 @@ fn compare_predicate_entailment<'tcx>( let (impl_sig, _) = infcx.replace_bound_vars_with_fresh_vars( impl_m_span, infer::HigherRankedType, - &tcx.fn_sig(impl_m.def_id), + tcx.fn_sig(impl_m.def_id), ); let impl_sig = - inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, &impl_sig); + inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, impl_sig); let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig)); debug!("compare_impl_method: impl_fty={:?}", impl_fty); - let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, &tcx.fn_sig(trait_m.def_id)); + let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id)); let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs); let trait_sig = - inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, &trait_sig); + inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig); let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig)); debug!("compare_impl_method: trait_fty={:?}", trait_fty); @@ -499,7 +499,7 @@ fn compare_self_type<'tcx>( tcx.infer_ctxt().enter(|infcx| { let self_arg_ty = - tcx.liberate_late_bound_regions(method.def_id, &ty::Binder::bind(self_arg_ty)); + tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(self_arg_ty)); let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty).is_ok(); match ExplicitSelf::determine(self_arg_ty, can_eq_self) { ExplicitSelf::ByValue => "self".to_owned(), @@ -968,12 +968,12 @@ crate fn compare_const_impl<'tcx>( // There is no "body" here, so just pass dummy id. let impl_ty = - inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, &impl_ty); + inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, impl_ty); debug!("compare_const_impl: impl_ty={:?}", impl_ty); let trait_ty = - inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, &trait_ty); + inh.normalize_associated_types_in(impl_c_span, impl_c_hir_id, param_env, trait_ty); debug!("compare_const_impl: trait_ty={:?}", trait_ty); @@ -1136,7 +1136,7 @@ fn compare_type_predicate_entailment<'tcx>( for predicate in impl_ty_own_bounds.predicates { let traits::Normalized { value: predicate, obligations } = - traits::normalize(&mut selcx, param_env, normalize_cause.clone(), &predicate); + traits::normalize(&mut selcx, param_env, normalize_cause.clone(), predicate); inh.register_predicates(obligations); inh.register_predicate(traits::Obligation::new(cause.clone(), param_env, predicate)); @@ -1261,7 +1261,7 @@ pub fn check_type_bounds<'tcx>( &mut selcx, normalize_param_env, normalize_cause.clone(), - &obligation.predicate, + obligation.predicate, ); debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate); obligation.predicate = normalized_predicate; diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index 5650b2cdd3c98..ad675f1e3833e 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -366,8 +366,8 @@ impl TypeRelation<'tcx> for SimpleEqRelation<'tcx> { // Anonymizing the LBRs is necessary to solve (Issue #59497). // After we do so, it should be totally fine to skip the binders. - let anon_a = self.tcx.anonymize_late_bound_regions(&a); - let anon_b = self.tcx.anonymize_late_bound_regions(&b); + let anon_a = self.tcx.anonymize_late_bound_regions(a); + let anon_b = self.tcx.anonymize_late_bound_regions(b); self.relate(anon_a.skip_binder(), anon_b.skip_binder())?; Ok(a) diff --git a/compiler/rustc_typeck/src/check/expectation.rs b/compiler/rustc_typeck/src/check/expectation.rs index fd6fe1406c840..5a5fc893d6588 100644 --- a/compiler/rustc_typeck/src/check/expectation.rs +++ b/compiler/rustc_typeck/src/check/expectation.rs @@ -83,9 +83,9 @@ impl<'a, 'tcx> Expectation<'tcx> { fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> { match self { NoExpectation => NoExpectation, - ExpectCastableToType(t) => ExpectCastableToType(fcx.resolve_vars_if_possible(&t)), - ExpectHasType(t) => ExpectHasType(fcx.resolve_vars_if_possible(&t)), - ExpectRvalueLikeUnsized(t) => ExpectRvalueLikeUnsized(fcx.resolve_vars_if_possible(&t)), + ExpectCastableToType(t) => ExpectCastableToType(fcx.resolve_vars_if_possible(t)), + ExpectHasType(t) => ExpectHasType(fcx.resolve_vars_if_possible(t)), + ExpectRvalueLikeUnsized(t) => ExpectRvalueLikeUnsized(fcx.resolve_vars_if_possible(t)), } } diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index af19ad08c1d08..f7f9e607a7441 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -494,7 +494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .replace_bound_vars_with_fresh_vars( expr.span, infer::LateBoundRegionConversionTime::FnCall, - &fn_sig.input(i), + fn_sig.input(i), ) .0; self.require_type_is_sized_deferred( @@ -514,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .replace_bound_vars_with_fresh_vars( expr.span, infer::LateBoundRegionConversionTime::FnCall, - &fn_sig.output(), + fn_sig.output(), ) .0; self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType); @@ -963,9 +963,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Find the type of `e`. Supply hints based on the type we are casting to, // if appropriate. let t_cast = self.to_ty_saving_user_provided_ty(t); - let t_cast = self.resolve_vars_if_possible(&t_cast); + let t_cast = self.resolve_vars_if_possible(t_cast); let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast)); - let t_cast = self.resolve_vars_if_possible(&t_cast); + let t_cast = self.resolve_vars_if_possible(t_cast); // Eagerly check for some obvious errors. if t_expr.references_error() || t_cast.references_error() { @@ -1139,7 +1139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .map(|f| { self.normalize_associated_types_in( expr.span, - &f.ty(self.tcx, substs), + f.ty(self.tcx, substs), ) }) .collect(); @@ -1571,7 +1571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty: Ty<'tcx>, ) { let output_ty = match self.infcx.get_impl_future_output_ty(ty) { - Some(output_ty) => self.resolve_vars_if_possible(&output_ty), + Some(output_ty) => self.resolve_vars_if_possible(output_ty), _ => return, }; let mut add_label = true; diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 300ee8f85f8dd..e1a2f593b8d9b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -88,7 +88,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // If `ty` is a type variable, see whether we already know what it is. - ty = self.resolve_vars_if_possible(&ty); + ty = self.resolve_vars_if_possible(ty); if !ty.has_infer_types_or_consts() { debug!("resolve_vars_with_obligations: ty={:?}", ty); return ty; @@ -99,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // indirect dependencies that don't seem worth tracking // precisely. self.select_obligations_where_possible(false, |_| {}); - ty = self.resolve_vars_if_possible(&ty); + ty = self.resolve_vars_if_possible(ty); debug!("resolve_vars_with_obligations: ty={:?}", ty); ty @@ -134,12 +134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[inline] pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) { - debug!( - "write_ty({:?}, {:?}) in fcx {}", - id, - self.resolve_vars_if_possible(&ty), - self.tag() - ); + debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); self.typeck_results.borrow_mut().node_types_mut().insert(id, ty); if ty.references_error() { @@ -195,7 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { user_self_ty: None, // not relevant here }; - self.infcx.canonicalize_user_type_annotation(&UserType::TypeOf( + self.infcx.canonicalize_user_type_annotation(UserType::TypeOf( method.def_id, user_substs, )) @@ -240,7 +235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); if Self::can_contain_user_lifetime_bounds((substs, user_self_ty)) { - let canonicalized = self.infcx.canonicalize_user_type_annotation(&UserType::TypeOf( + let canonicalized = self.infcx.canonicalize_user_type_annotation(UserType::TypeOf( def_id, UserSubsts { substs, user_self_ty }, )); @@ -326,13 +321,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Basically whenever we are converting from a type scheme into /// the fn body space, we always want to normalize associated /// types as well. This function combines the two. - fn instantiate_type_scheme(&self, span: Span, substs: SubstsRef<'tcx>, value: &T) -> T + fn instantiate_type_scheme(&self, span: Span, substs: SubstsRef<'tcx>, value: T) -> T where T: TypeFoldable<'tcx>, { + debug!("instantiate_type_scheme(value={:?}, substs={:?})", value, substs); let value = value.subst(self.tcx, substs); - let result = self.normalize_associated_types_in(span, &value); - debug!("instantiate_type_scheme(value={:?}, substs={:?}) = {:?}", value, substs, result); + let result = self.normalize_associated_types_in(span, value); + debug!("instantiate_type_scheme = {:?}", result); result } @@ -347,7 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bounds = self.tcx.predicates_of(def_id); let spans: Vec = bounds.predicates.iter().map(|(_, span)| *span).collect(); let result = bounds.instantiate(self.tcx, substs); - let result = self.normalize_associated_types_in(span, &result); + let result = self.normalize_associated_types_in(span, result); debug!( "instantiate_bounds(bounds={:?}, substs={:?}) = {:?}, {:?}", bounds, substs, result, spans, @@ -361,7 +357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn instantiate_opaque_types_from_value>( &self, parent_id: hir::HirId, - value: &T, + value: T, value_span: Span, ) -> T { let parent_def_id = self.tcx.hir().local_def_id(parent_id); @@ -389,7 +385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { value } - pub(in super::super) fn normalize_associated_types_in(&self, span: Span, value: &T) -> T + pub(in super::super) fn normalize_associated_types_in(&self, span: Span, value: T) -> T where T: TypeFoldable<'tcx>, { @@ -399,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn normalize_associated_types_in_as_infer_ok( &self, span: Span, - value: &T, + value: T, ) -> InferOk<'tcx, T> where T: TypeFoldable<'tcx>, @@ -468,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("to_ty_saving_user_provided_ty: ty={:?}", ty); if Self::can_contain_user_lifetime_bounds(ty) { - let c_ty = self.infcx.canonicalize_response(&UserType::Ty(ty)); + let c_ty = self.infcx.canonicalize_response(UserType::Ty(ty)); debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty); self.typeck_results.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty); } @@ -851,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Record all the argument types, with the substitutions // produced from the above subtyping unification. - Ok(formal_args.iter().map(|ty| self.resolve_vars_if_possible(ty)).collect()) + Ok(formal_args.iter().map(|&ty| self.resolve_vars_if_possible(ty)).collect()) }) .unwrap_or_default(); debug!( @@ -1204,7 +1200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Res::Local(hid) = res { let ty = self.local_ty(span, hid).decl_ty; - let ty = self.normalize_associated_types_in(span, &ty); + let ty = self.normalize_associated_types_in(span, ty); self.write_ty(hir_id, ty); return (ty, res); } @@ -1414,7 +1410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Substitute the values for the type parameters into the type of // the referenced item. - let ty_substituted = self.instantiate_type_scheme(span, &substs, &ty); + let ty_substituted = self.instantiate_type_scheme(span, &substs, ty); if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty { // In the case of `Foo::method` and `>::method`, if `method` @@ -1424,7 +1420,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This also occurs for an enum variant on a type alias. let ty = tcx.type_of(impl_def_id); - let impl_ty = self.instantiate_type_scheme(span, &substs, &ty); + let impl_ty = self.instantiate_type_scheme(span, &substs, ty); match self.at(&self.misc(span), self.param_env).sup(impl_ty, self_ty) { Ok(ok) => self.register_infer_ok_obligations(ok), Err(_) => { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index a820661d8432a..333bda00dbe81 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -261,9 +261,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { // is the missing argument of type `()`? let sugg_unit = if expected_arg_tys.len() == 1 && supplied_arg_count == 0 { - self.resolve_vars_if_possible(&expected_arg_tys[0]).is_unit() + self.resolve_vars_if_possible(expected_arg_tys[0]).is_unit() } else if fn_inputs.len() == 1 && supplied_arg_count == 0 { - self.resolve_vars_if_possible(&fn_inputs[0]).is_unit() + self.resolve_vars_if_possible(fn_inputs[0]).is_unit() } else { false }; @@ -384,7 +384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ty::FnDef(..) => { let ptr_ty = self.tcx.mk_fn_ptr(arg_ty.fn_sig(self.tcx)); - let ptr_ty = self.resolve_vars_if_possible(&ptr_ty); + let ptr_ty = self.resolve_vars_if_possible(ptr_ty); variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string()); } _ => {} @@ -927,7 +927,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .map(|&(i, checked_ty, _)| (i, checked_ty)) .chain(final_arg_types.iter().map(|&(i, _, coerced_ty)| (i, coerced_ty))) .flat_map(|(i, ty)| { - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); // We walk the argument type because the argument's type could have // been `Option`, but the `FulfillmentError` references `T`. if ty.walk().any(|arg| arg == predicate.self_ty().into()) { @@ -989,7 +989,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // from `typeck-default-trait-impl-assoc-type.rs`. } else { let ty = AstConv::ast_ty_to_ty(self, hir_ty); - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); if ty == predicate.self_ty() { error.obligation.cause.make_mut().span = hir_ty.span; } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 72c3b233ed934..f635e0b6f931c 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -262,7 +262,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { let (trait_ref, _) = self.replace_bound_vars_with_fresh_vars( span, infer::LateBoundRegionConversionTime::AssocTypeProjection(item_def_id), - &poly_trait_ref, + poly_trait_ref, ); let item_substs = >::create_substs_for_associated_item( diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index a8ad9f4fdf8af..17dbf989d6683 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -73,8 +73,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => return false, }; - let sig = self.replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig).0; - let sig = self.normalize_associated_types_in(expr.span, &sig); + let sig = self.replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, sig).0; + let sig = self.normalize_associated_types_in(expr.span, sig); if self.can_coerce(sig.output(), expected) { let (mut sugg_call, applicability) = if sig.inputs().is_empty() { (String::new(), Applicability::MachineApplicable) diff --git a/compiler/rustc_typeck/src/check/gather_locals.rs b/compiler/rustc_typeck/src/check/gather_locals.rs index af552389de024..825ebc19fa6da 100644 --- a/compiler/rustc_typeck/src/check/gather_locals.rs +++ b/compiler/rustc_typeck/src/check/gather_locals.rs @@ -59,16 +59,13 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { let o_ty = self.fcx.to_ty(&ty); let revealed_ty = if self.fcx.tcx.features().impl_trait_in_bindings { - self.fcx.instantiate_opaque_types_from_value(self.parent_id, &o_ty, ty.span) + self.fcx.instantiate_opaque_types_from_value(self.parent_id, o_ty, ty.span) } else { o_ty }; - let c_ty = self - .fcx - .inh - .infcx - .canonicalize_user_type_annotation(&UserType::Ty(revealed_ty)); + let c_ty = + self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(revealed_ty)); debug!( "visit_local: ty.hir_id={:?} o_ty={:?} revealed_ty={:?} c_ty={:?}", ty.hir_id, o_ty, revealed_ty, c_ty diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 293a995887c26..602b79802b33d 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -80,7 +80,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { }); if let Some(yield_data) = live_across_yield { - let ty = self.fcx.resolve_vars_if_possible(&ty); + let ty = self.fcx.resolve_vars_if_possible(ty); debug!( "type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}", expr, scope, ty, self.expr_count, yield_data.span @@ -120,7 +120,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { self.expr_count, expr.map(|e| e.span) ); - let ty = self.fcx.resolve_vars_if_possible(&ty); + let ty = self.fcx.resolve_vars_if_possible(ty); if let Some((unresolved_type, unresolved_type_span)) = self.fcx.unresolved_type_vars(&ty) { @@ -179,13 +179,13 @@ pub fn resolve_interior<'a, 'tcx>( .filter_map(|mut cause| { // Erase regions and canonicalize late-bound regions to deduplicate as many types as we // can. - let erased = fcx.tcx.erase_regions(&cause.ty); + let erased = fcx.tcx.erase_regions(cause.ty); if captured_tys.insert(erased) { // Replace all regions inside the generator interior with late bound regions. // Note that each region slot in the types gets a new fresh late bound region, // which means that none of the regions inside relate to any other, even if // typeck had previously found constraints that would cause them to be related. - let folded = fcx.tcx.fold_regions(&erased, &mut false, |_, current_depth| { + let folded = fcx.tcx.fold_regions(erased, &mut false, |_, current_depth| { let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter))); counter += 1; r diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index 7e580485c3de4..0011a3fc71b59 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -156,7 +156,7 @@ impl Inherited<'a, 'tcx> { span: Span, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - value: &T, + value: T, ) -> T where T: TypeFoldable<'tcx>, diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index fb048abc0e9cd..8ef723d590285 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -90,8 +90,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // traits, no trait system method can be called before this point because they // could alter our Self-type, except for normalizing the receiver from the // signature (which is also done during probing). - let method_sig_rcvr = - self.normalize_associated_types_in(self.span, &method_sig.inputs()[0]); + let method_sig_rcvr = self.normalize_associated_types_in(self.span, method_sig.inputs()[0]); debug!( "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?} method_predicates={:?}", self_ty, method_sig_rcvr, method_sig, method_predicates @@ -99,7 +98,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self.unify_receivers(self_ty, method_sig_rcvr, &pick, all_substs); let (method_sig, method_predicates) = - self.normalize_associated_types_in(self.span, &(method_sig, method_predicates)); + self.normalize_associated_types_in(self.span, (method_sig, method_predicates)); // Make sure nobody calls `drop()` explicitly. self.enforce_illegal_method_limitations(&pick); @@ -229,7 +228,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty); let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id); let upcast_trait_ref = - this.replace_bound_vars_with_fresh_vars(&upcast_poly_trait_ref); + this.replace_bound_vars_with_fresh_vars(upcast_poly_trait_ref); debug!( "original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}", original_poly_trait_ref, upcast_trait_ref, trait_def_id @@ -249,10 +248,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self.fresh_substs_for_item(self.span, trait_def_id) } - probe::WhereClausePick(ref poly_trait_ref) => { + probe::WhereClausePick(poly_trait_ref) => { // Where clauses can have bound regions in them. We need to instantiate // those to convert from a poly-trait-ref to a trait-ref. - self.replace_bound_vars_with_fresh_vars(&poly_trait_ref).substs + self.replace_bound_vars_with_fresh_vars(poly_trait_ref).substs } } } @@ -424,7 +423,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // N.B., instantiate late-bound regions first so that // `instantiate_type_scheme` can normalize associated types that // may reference those regions. - let method_sig = self.replace_bound_vars_with_fresh_vars(&sig); + let method_sig = self.replace_bound_vars_with_fresh_vars(sig); debug!("late-bound lifetimes from method instantiated, method_sig={:?}", method_sig); let method_sig = method_sig.subst(self.tcx, all_substs); @@ -530,7 +529,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { upcast_trait_refs.into_iter().next().unwrap() } - fn replace_bound_vars_with_fresh_vars(&self, value: &ty::Binder) -> T + fn replace_bound_vars_with_fresh_vars(&self, value: ty::Binder) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 84bc3979e1229..8e13b3746992a 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -265,7 +265,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { scope: ProbeScope, ) -> probe::PickResult<'tcx> { let mode = probe::Mode::MethodCall; - let self_ty = self.resolve_vars_if_possible(&self_ty); + let self_ty = self.resolve_vars_if_possible(self_ty); self.probe_for_name( span, mode, @@ -358,11 +358,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `instantiate_type_scheme` can normalize associated types that // may reference those regions. let fn_sig = tcx.fn_sig(def_id); - let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, &fn_sig).0; + let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0; let fn_sig = fn_sig.subst(self.tcx, substs); let InferOk { value, obligations: o } = - self.normalize_associated_types_in_as_infer_ok(span, &fn_sig); + self.normalize_associated_types_in_as_infer_ok(span, fn_sig); let fn_sig = { obligations.extend(o); value @@ -379,7 +379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, substs); let InferOk { value, obligations: o } = - self.normalize_associated_types_in_as_infer_ok(span, &bounds); + self.normalize_associated_types_in_as_infer_ok(span, bounds); let bounds = { obligations.extend(o); value diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 84efae694db6f..ed8e4aafb9965 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { let mut orig_values = OriginalQueryValues::default(); let param_env_and_self_ty = self.infcx.canonicalize_query( - &ParamEnvAnd { param_env: self.param_env, value: self_ty }, + ParamEnvAnd { param_env: self.param_env, value: self_ty }, &mut orig_values, ); @@ -730,7 +730,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let cause = traits::ObligationCause::misc(self.span, self.body_id); let selcx = &mut traits::SelectionContext::new(self.fcx); let traits::Normalized { value: (xform_self_ty, xform_ret_ty), obligations } = - traits::normalize(selcx, self.param_env, cause, &xform_tys); + traits::normalize(selcx, self.param_env, cause, xform_tys); debug!( "assemble_inherent_impl_probe: xform_self_ty = {:?}/{:?}", xform_self_ty, xform_ret_ty @@ -774,7 +774,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // argument type like `&Trait`. let trait_ref = principal.with_self_ty(self.tcx, self_ty); self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| { - let new_trait_ref = this.erase_late_bound_regions(&new_trait_ref); + let new_trait_ref = this.erase_late_bound_regions(new_trait_ref); let (xform_self_ty, xform_ret_ty) = this.xform_self_ty(&item, new_trait_ref.self_ty(), new_trait_ref.substs); @@ -820,7 +820,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }); self.elaborate_bounds(bounds, |this, poly_trait_ref, item| { - let trait_ref = this.erase_late_bound_regions(&poly_trait_ref); + let trait_ref = this.erase_late_bound_regions(poly_trait_ref); let (xform_self_ty, xform_ret_ty) = this.xform_self_ty(&item, trait_ref.self_ty(), trait_ref.substs); @@ -911,7 +911,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let substs = self.fresh_substs_for_item(self.span, method.def_id); let fty = fty.subst(self.tcx, substs); let (fty, _) = - self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, &fty); + self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty); if let Some(self_ty) = self_ty { if self @@ -942,7 +942,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // For trait aliases, assume all super-traits are relevant. let bounds = iter::once(trait_ref.to_poly_trait_ref()); self.elaborate_bounds(bounds, |this, new_trait_ref, item| { - let new_trait_ref = this.erase_late_bound_regions(&new_trait_ref); + let new_trait_ref = this.erase_late_bound_regions(new_trait_ref); let (xform_self_ty, xform_ret_ty) = this.xform_self_ty(&item, new_trait_ref.self_ty(), new_trait_ref.substs); @@ -1355,7 +1355,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let impl_bounds = self.tcx.predicates_of(impl_def_id); let impl_bounds = impl_bounds.instantiate(self.tcx, substs); let traits::Normalized { value: impl_bounds, obligations: norm_obligations } = - traits::normalize(selcx, self.param_env, cause.clone(), &impl_bounds); + traits::normalize(selcx, self.param_env, cause.clone(), impl_bounds); // Convert the bounds into obligations. let impl_obligations = @@ -1366,7 +1366,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { .chain(ref_obligations.iter().cloned()); // Evaluate those obligations to see if they might possibly hold. for o in candidate_obligations { - let o = self.resolve_vars_if_possible(&o); + let o = self.resolve_vars_if_possible(o); if !self.predicate_may_hold(&o) { result = ProbeResult::NoMatch; possibly_unsatisfied_predicates.push((o.predicate, None)); @@ -1392,10 +1392,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { for obligation in impl_source.borrow_nested_obligations() { // Determine exactly which obligation wasn't met, so // that we can give more context in the error. - if !self.predicate_may_hold(&obligation) { - let o = self.resolve_vars_if_possible(obligation); + if !self.predicate_may_hold(obligation) { + let o = + self.resolve_vars_if_possible(obligation.clone()); let predicate = - self.resolve_vars_if_possible(&predicate); + self.resolve_vars_if_possible(predicate); let p = if predicate == o.predicate { // Avoid "`MyStruct: Foo` which is required by // `MyStruct: Foo`" in E0599. @@ -1410,7 +1411,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { _ => { // Some nested subobligation of this predicate // failed. - let predicate = self.resolve_vars_if_possible(&predicate); + let predicate = self.resolve_vars_if_possible(predicate); possibly_unsatisfied_predicates.push((predicate, None)); } } @@ -1427,7 +1428,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // Evaluate those obligations to see if they might possibly hold. for o in sub_obligations { - let o = self.resolve_vars_if_possible(&o); + let o = self.resolve_vars_if_possible(o); if !self.predicate_may_hold(&o) { result = ProbeResult::NoMatch; possibly_unsatisfied_predicates.push((o.predicate, None)); @@ -1438,7 +1439,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { if let (Some(return_ty), Some(xform_ret_ty)) = (self.return_type, probe.xform_ret_ty) { - let xform_ret_ty = self.resolve_vars_if_possible(&xform_ret_ty); + let xform_ret_ty = self.resolve_vars_if_possible(xform_ret_ty); debug!( "comparing return_ty {:?} with xform ret ty {:?}", return_ty, probe.xform_ret_ty @@ -1604,7 +1605,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // Erase any late-bound regions from the method and substitute // in the values from the substitution. - let xform_fn_sig = self.erase_late_bound_regions(&fn_sig); + let xform_fn_sig = self.erase_late_bound_regions(fn_sig); if generics.params.is_empty() { xform_fn_sig.subst(self.tcx, substs) @@ -1672,7 +1673,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { /// region got replaced with the same variable, which requires a bit more coordination /// and/or tracking the substitution and /// so forth. - fn erase_late_bound_regions(&self, value: &ty::Binder) -> T + fn erase_late_bound_regions(&self, value: ty::Binder) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 46afe4892dbd7..3d5ce57a491c5 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) => { let tcx = self.tcx; - let actual = self.resolve_vars_if_possible(&rcvr_ty); + let actual = self.resolve_vars_if_possible(rcvr_ty); let ty_str = self.ty_to_string(actual); let is_method = mode == Mode::MethodCall; let item_kind = if is_method { @@ -870,7 +870,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, ) { let output_ty = match self.infcx.get_impl_future_output_ty(ty) { - Some(output_ty) => self.resolve_vars_if_possible(&output_ty), + Some(output_ty) => self.resolve_vars_if_possible(output_ty), _ => return, }; let method_exists = self.method_exists(item_name, output_ty, call.hir_id, true); diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 169ad0df3a5c9..b242900a1221f 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -362,7 +362,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &FxHashSet(tcx: TyCtxt<'tcx>, val: &T) -> T +fn fixup_opaque_types<'tcx, T>(tcx: TyCtxt<'tcx>, val: T) -> T where T: TypeFoldable<'tcx>, { @@ -510,15 +510,15 @@ fn typeck_with_fallback<'tcx>( check_abi(tcx, span, fn_sig.abi()); // Compute the fty from point of view of inside the fn. - let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), &fn_sig); + let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig); let fn_sig = inh.normalize_associated_types_in( body.value.span, body_id.hir_id, param_env, - &fn_sig, + fn_sig, ); - let fn_sig = fixup_opaque_types(tcx, &fn_sig); + let fn_sig = fixup_opaque_types(tcx, fn_sig); let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None).0; fcx @@ -543,11 +543,11 @@ fn typeck_with_fallback<'tcx>( _ => fallback(), }); - let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type); + let expected_type = fcx.normalize_associated_types_in(body.value.span, expected_type); fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized); let revealed_ty = if tcx.features().impl_trait_in_bindings { - fcx.instantiate_opaque_types_from_value(id, &expected_type, body.value.span) + fcx.instantiate_opaque_types_from_value(id, expected_type, body.value.span) } else { expected_type }; diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 247b525672603..1ce2b2cff0631 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -660,7 +660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { method.sig.output() } Err(()) => { - let actual = self.resolve_vars_if_possible(&operand_ty); + let actual = self.resolve_vars_if_possible(operand_ty); if !actual.references_error() { let mut err = struct_span_err!( self.tcx.sess, diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 6489b7838d63f..dd8f4152c7c9e 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -459,7 +459,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Now that we know the types can be unified we find the unified type // and use it to type the entire expression. - let common_type = self.resolve_vars_if_possible(&lhs_ty.or(rhs_ty).unwrap_or(expected)); + let common_type = self.resolve_vars_if_possible(lhs_ty.or(rhs_ty).unwrap_or(expected)); // Subtyping doesn't matter here, as the value is some kind of scalar. let demand_eqtype = |x, y| { diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index 7b31b9f3915f4..b8b98cef7637a 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -229,7 +229,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { /// of b will be `&.i32` and then `*b` will require that `` be bigger than the let and /// the `*b` expression, so we will effectively resolve `` to be the block B. pub fn resolve_type(&self, unresolved_ty: Ty<'tcx>) -> Ty<'tcx> { - self.resolve_vars_if_possible(&unresolved_ty) + self.resolve_vars_if_possible(unresolved_ty) } /// Try to resolve the type for the given node. diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 1e27357ce4414..21b9b96213c0d 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -403,12 +403,12 @@ fn check_associated_item( match item.kind { ty::AssocKind::Const => { let ty = fcx.tcx.type_of(item.def_id); - let ty = fcx.normalize_associated_types_in(span, &ty); + let ty = fcx.normalize_associated_types_in(span, ty); fcx.register_wf_obligation(ty.into(), span, code.clone()); } ty::AssocKind::Fn => { let sig = fcx.tcx.fn_sig(item.def_id); - let sig = fcx.normalize_associated_types_in(span, &sig); + let sig = fcx.normalize_associated_types_in(span, sig); let hir_sig = sig_if_method.expect("bad signature for method"); check_fn_or_method( tcx, @@ -427,7 +427,7 @@ fn check_associated_item( } if item.defaultness.has_value() { let ty = fcx.tcx.type_of(item.def_id); - let ty = fcx.normalize_associated_types_in(span, &ty); + let ty = fcx.normalize_associated_types_in(span, ty); fcx.register_wf_obligation(ty.into(), span, code.clone()); } } @@ -480,7 +480,7 @@ fn check_type_defn<'tcx, F>( let needs_drop_copy = || { packed && { let ty = variant.fields.last().unwrap().ty; - let ty = fcx.tcx.erase_regions(&ty); + let ty = fcx.tcx.erase_regions(ty); if ty.needs_infer() { fcx_tcx .sess @@ -592,7 +592,7 @@ fn check_associated_type_bounds(fcx: &FnCtxt<'_, '_>, item: &ty::AssocItem, span debug!("check_associated_type_bounds: bounds={:?}", bounds); let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| { - let normalized_bound = fcx.normalize_associated_types_in(span, &bound); + let normalized_bound = fcx.normalize_associated_types_in(span, bound); traits::wf::predicate_obligations( fcx, fcx.param_env, @@ -618,7 +618,7 @@ fn check_item_fn( for_id(tcx, item_id, span).with_fcx(|fcx, tcx| { let def_id = fcx.tcx.hir().local_def_id(item_id); let sig = fcx.tcx.fn_sig(def_id); - let sig = fcx.normalize_associated_types_in(span, &sig); + let sig = fcx.normalize_associated_types_in(span, sig); let mut implied_bounds = vec![]; check_fn_or_method( tcx, @@ -638,7 +638,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo for_id(tcx, item_id, ty_span).with_fcx(|fcx, tcx| { let ty = tcx.type_of(tcx.hir().local_def_id(item_id)); - let item_ty = fcx.normalize_associated_types_in(ty_span, &ty); + let item_ty = fcx.normalize_associated_types_in(ty_span, ty); let mut forbid_unsized = true; if allow_foreign_ty { @@ -680,7 +680,7 @@ fn check_impl<'tcx>( // won't hold). let trait_ref = fcx.tcx.impl_trait_ref(item_def_id).unwrap(); let trait_ref = - fcx.normalize_associated_types_in(ast_trait_ref.path.span, &trait_ref); + fcx.normalize_associated_types_in(ast_trait_ref.path.span, trait_ref); let obligations = traits::wf::trait_obligations( fcx, fcx.param_env, @@ -695,7 +695,7 @@ fn check_impl<'tcx>( } None => { let self_ty = fcx.tcx.type_of(item_def_id); - let self_ty = fcx.normalize_associated_types_in(item.span, &self_ty); + let self_ty = fcx.normalize_associated_types_in(item.span, self_ty); fcx.register_wf_obligation( self_ty.into(), ast_self_ty.span, @@ -845,7 +845,7 @@ fn check_where_clauses<'tcx, 'fcx>( // Note the subtle difference from how we handle `predicates` // below: there, we are not trying to prove those predicates // to be *true* but merely *well-formed*. - let pred = fcx.normalize_associated_types_in(sp, &pred); + let pred = fcx.normalize_associated_types_in(sp, pred); let cause = traits::ObligationCause::new(sp, fcx.body_id, traits::ItemObligation(def_id)); traits::Obligation::new(cause, fcx.param_env, pred) @@ -856,12 +856,12 @@ fn check_where_clauses<'tcx, 'fcx>( if let Some((mut return_ty, span)) = return_ty { if return_ty.has_infer_types_or_consts() { fcx.select_obligations_where_possible(false, |_| {}); - return_ty = fcx.resolve_vars_if_possible(&return_ty); + return_ty = fcx.resolve_vars_if_possible(return_ty); } check_opaque_types(tcx, fcx, def_id.expect_local(), span, return_ty); } - let predicates = fcx.normalize_associated_types_in(span, &predicates); + let predicates = fcx.normalize_associated_types_in(span, predicates); debug!("check_where_clauses: predicates={:?}", predicates.predicates); assert_eq!(predicates.predicates.len(), predicates.spans.len()); @@ -885,8 +885,8 @@ fn check_fn_or_method<'fcx, 'tcx>( def_id: DefId, implied_bounds: &mut Vec>, ) { - let sig = fcx.normalize_associated_types_in(span, &sig); - let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig); + let sig = fcx.normalize_associated_types_in(span, sig); + let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig); for (&input_ty, span) in sig.inputs().iter().zip(hir_decl.inputs.iter().map(|t| t.span)) { fcx.register_wf_obligation(input_ty.into(), span, ObligationCauseCode::MiscObligation); @@ -1063,19 +1063,19 @@ fn check_method_receiver<'fcx, 'tcx>( let span = fn_sig.decl.inputs[0].span; let sig = fcx.tcx.fn_sig(method.def_id); - let sig = fcx.normalize_associated_types_in(span, &sig); - let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &sig); + let sig = fcx.normalize_associated_types_in(span, sig); + let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, sig); debug!("check_method_receiver: sig={:?}", sig); - let self_ty = fcx.normalize_associated_types_in(span, &self_ty); - let self_ty = fcx.tcx.liberate_late_bound_regions(method.def_id, &ty::Binder::bind(self_ty)); + let self_ty = fcx.normalize_associated_types_in(span, self_ty); + let self_ty = fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(self_ty)); let receiver_ty = sig.inputs()[0]; - let receiver_ty = fcx.normalize_associated_types_in(span, &receiver_ty); + let receiver_ty = fcx.normalize_associated_types_in(span, receiver_ty); let receiver_ty = - fcx.tcx.liberate_late_bound_regions(method.def_id, &ty::Binder::bind(receiver_ty)); + fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(receiver_ty)); if fcx.tcx.features().arbitrary_self_types { if !receiver_is_valid(fcx, span, receiver_ty, self_ty, true) { @@ -1307,7 +1307,7 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, span: Span, id: hir::HirId) { let pred = obligation.predicate; // Match the existing behavior. if pred.is_global() && !pred.has_late_bound_regions() { - let pred = fcx.normalize_associated_types_in(span, &pred); + let pred = fcx.normalize_associated_types_in(span, pred); let obligation = traits::Obligation::new( traits::ObligationCause::new(span, id, traits::TrivialBound), empty_env, @@ -1405,8 +1405,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .iter() .map(|field| { let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id)); - let field_ty = self.normalize_associated_types_in(field.ty.span, &field_ty); - let field_ty = self.resolve_vars_if_possible(&field_ty); + let field_ty = self.normalize_associated_types_in(field.ty.span, field_ty); + let field_ty = self.resolve_vars_if_possible(field_ty); debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty); AdtField { ty: field_ty, span: field.ty.span } }) @@ -1429,7 +1429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(super) fn impl_implied_bounds(&self, impl_def_id: DefId, span: Span) -> Vec> { match self.tcx.impl_trait_ref(impl_def_id) { - Some(ref trait_ref) => { + Some(trait_ref) => { // Trait impl: take implied bounds from all types that // appear in the trait reference. let trait_ref = self.normalize_associated_types_in(span, trait_ref); @@ -1439,7 +1439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None => { // Inherent impl: take implied bounds from the `self` type. let self_ty = self.tcx.type_of(impl_def_id); - let self_ty = self.normalize_associated_types_in(span, &self_ty); + let self_ty = self.normalize_associated_types_in(span, self_ty); vec![self_ty] } } diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 5363702a5be6d..e54e00864831c 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -136,7 +136,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { match e.kind { hir::ExprKind::Unary(hir::UnOp::UnNeg | hir::UnOp::UnNot, ref inner) => { let inner_ty = self.fcx.node_ty(inner.hir_id); - let inner_ty = self.fcx.resolve_vars_if_possible(&inner_ty); + let inner_ty = self.fcx.resolve_vars_if_possible(inner_ty); if inner_ty.is_scalar() { let mut typeck_results = self.fcx.typeck_results.borrow_mut(); @@ -147,10 +147,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { hir::ExprKind::Binary(ref op, ref lhs, ref rhs) | hir::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => { let lhs_ty = self.fcx.node_ty(lhs.hir_id); - let lhs_ty = self.fcx.resolve_vars_if_possible(&lhs_ty); + let lhs_ty = self.fcx.resolve_vars_if_possible(lhs_ty); let rhs_ty = self.fcx.node_ty(rhs.hir_id); - let rhs_ty = self.fcx.resolve_vars_if_possible(&rhs_ty); + let rhs_ty = self.fcx.resolve_vars_if_possible(rhs_ty); if lhs_ty.is_scalar() && rhs_ty.is_scalar() { let mut typeck_results = self.fcx.typeck_results.borrow_mut(); @@ -209,7 +209,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { &format!("bad index {:?} for base: `{:?}`", index, base), ) }); - let index_ty = self.fcx.resolve_vars_if_possible(&index_ty); + let index_ty = self.fcx.resolve_vars_if_possible(index_ty); if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize { // Remove the method call record @@ -313,14 +313,14 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { intravisit::walk_local(self, l); let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty; - let var_ty = self.resolve(&var_ty, &l.span); + let var_ty = self.resolve(var_ty, &l.span); self.write_ty_to_typeck_results(l.hir_id, var_ty); } fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) { intravisit::walk_ty(self, hir_ty); let ty = self.fcx.node_ty(hir_ty.hir_id); - let ty = self.resolve(&ty, &hir_ty.span); + let ty = self.resolve(ty, &hir_ty.span); self.write_ty_to_typeck_results(hir_ty.hir_id, ty); } } @@ -432,7 +432,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { let hir_id = self.tcx().hir().local_def_id_to_hir_id(def_id.expect_local()); - let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id); + let instantiated_ty = self.resolve(opaque_defn.concrete_ty, &hir_id); debug_assert!(!instantiated_ty.has_escaping_bound_vars()); @@ -522,13 +522,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // Resolve the type of the node with id `node_id` let n_ty = self.fcx.node_ty(hir_id); - let n_ty = self.resolve(&n_ty, &span); + let n_ty = self.resolve(n_ty, &span); self.write_ty_to_typeck_results(hir_id, n_ty); debug!("node {:?} has type {:?}", hir_id, n_ty); // Resolve any substitutions if let Some(substs) = self.fcx.typeck_results.borrow().node_substs_opt(hir_id) { - let substs = self.resolve(&substs, &span); + let substs = self.resolve(substs, &span); debug!("write_substs_to_tcx({:?}, {:?})", hir_id, substs); assert!(!substs.needs_infer() && !substs.has_placeholders()); self.typeck_results.node_substs_mut().insert(hir_id, substs); @@ -543,7 +543,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } Some(adjustment) => { - let resolved_adjustment = self.resolve(&adjustment, &span); + let resolved_adjustment = self.resolve(adjustment, &span); debug!("adjustments for node {:?}: {:?}", hir_id, resolved_adjustment); self.typeck_results.adjustments_mut().insert(hir_id, resolved_adjustment); } @@ -558,7 +558,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } Some(adjustment) => { - let resolved_adjustment = self.resolve(&adjustment, &span); + let resolved_adjustment = self.resolve(adjustment, &span); debug!("pat_adjustments for node {:?}: {:?}", hir_id, resolved_adjustment); self.typeck_results.pat_adjustments_mut().insert(hir_id, resolved_adjustment); } @@ -570,7 +570,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); let common_hir_owner = fcx_typeck_results.hir_owner; - for (&local_id, fn_sig) in fcx_typeck_results.liberated_fn_sigs().iter() { + for (&local_id, &fn_sig) in fcx_typeck_results.liberated_fn_sigs().iter() { let hir_id = hir::HirId { owner: common_hir_owner, local_id }; let fn_sig = self.resolve(fn_sig, &hir_id); self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig); @@ -584,12 +584,12 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { for (&local_id, ftys) in fcx_typeck_results.fru_field_types().iter() { let hir_id = hir::HirId { owner: common_hir_owner, local_id }; - let ftys = self.resolve(ftys, &hir_id); + let ftys = self.resolve(ftys.clone(), &hir_id); self.typeck_results.fru_field_types_mut().insert(hir_id, ftys); } } - fn resolve(&mut self, x: &T, span: &dyn Locatable) -> T + fn resolve(&mut self, x: T, span: &dyn Locatable) -> T where T: TypeFoldable<'tcx>, { @@ -681,8 +681,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - match self.infcx.fully_resolve(&t) { - Ok(t) => self.infcx.tcx.erase_regions(&t), + match self.infcx.fully_resolve(t) { + Ok(t) => self.infcx.tcx.erase_regions(t), Err(_) => { debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t); self.report_type_error(t); @@ -698,8 +698,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { } fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> { - match self.infcx.fully_resolve(&ct) { - Ok(ct) => self.infcx.tcx.erase_regions(&ct), + match self.infcx.fully_resolve(ct) { + Ok(ct) => self.infcx.tcx.erase_regions(ct), Err(_) => { debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct); self.report_const_error(ct); diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index b431de9036944..566aa94a392e9 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -386,7 +386,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { "{}::{}", // Replace the existing lifetimes with a new named lifetime. self.tcx - .replace_late_bound_regions(&poly_trait_ref, |_| { + .replace_late_bound_regions(poly_trait_ref, |_| { self.tcx.mk_region(ty::ReEarlyBound( ty::EarlyBoundRegion { def_id: item_def_id, @@ -424,7 +424,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { format!( "{}::{}", // Erase named lt, we want `::C`, not `::C`. - self.tcx.anonymize_late_bound_regions(&poly_trait_ref).skip_binder(), + self.tcx.anonymize_late_bound_regions(poly_trait_ref).skip_binder(), item_segment.ident ), Applicability::MaybeIncorrect, diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 61d1efc837b03..c4f4c8bc76b46 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -637,7 +637,7 @@ fn infer_placeholder_type( } // Typeck doesn't expect erased regions to be returned from `type_of`. - tcx.fold_regions(&ty, &mut false, |r, _| match r { + tcx.fold_regions(ty, &mut false, |r, _| match r { ty::ReErased => tcx.lifetimes.re_static, _ => r, }) diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 4cf3efcf5136d..5db9ff9524de0 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -165,7 +165,7 @@ fn get_impl_substs<'tcx>( // Conservatively use an empty `ParamEnv`. let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty()); infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env, RegionckMode::default()); - let impl2_substs = match infcx.fully_resolve(&impl2_substs) { + let impl2_substs = match infcx.fully_resolve(impl2_substs) { Ok(s) => s, Err(_) => { tcx.sess.struct_span_err(span, "could not resolve substs on overridden impl").emit(); diff --git a/compiler/rustc_typeck/src/mem_categorization.rs b/compiler/rustc_typeck/src/mem_categorization.rs index f6ac7aa9155fe..9992094117dfc 100644 --- a/compiler/rustc_typeck/src/mem_categorization.rs +++ b/compiler/rustc_typeck/src/mem_categorization.rs @@ -124,7 +124,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) } - fn resolve_vars_if_possible(&self, value: &T) -> T + fn resolve_vars_if_possible(&self, value: T) -> T where T: TypeFoldable<'tcx>, { @@ -142,7 +142,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { ) -> McResult> { match ty { Some(ty) => { - let ty = self.resolve_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(ty); if ty.references_error() || ty.is_ty_var() { debug!("resolve_type_vars_or_error: error from {:?}", ty); Err(()) @@ -274,7 +274,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { F: FnOnce() -> McResult>, { debug!("cat_expr_adjusted_with({:?}): {:?}", adjustment, expr); - let target = self.resolve_vars_if_possible(&adjustment.target); + let target = self.resolve_vars_if_possible(adjustment.target); match adjustment.kind { adjustment::Adjust::Deref(overloaded) => { // Equivalent to *expr or something similar.