diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 4243ec214b0..0b40dbfc740 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1111,7 +1111,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }); } if let Some(clone_trait) = tcx.lang_items().clone_trait() - && let trait_ref = tcx.mk_trait_ref(clone_trait, [ty]) + && let trait_ref = ty::TraitRef::new(tcx, clone_trait, [ty]) && let o = Obligation::new( tcx, ObligationCause::dummy(), diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d5e50a61b03..2e0bf592cd3 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -538,7 +538,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { let tcx = self.tcx(); - let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, [place_ty.ty]); + let trait_ref = + ty::TraitRef::from_lang_item(tcx.at(self.last_span), LangItem::Copy, [place_ty.ty]); // To have a `Copy` operand, the type `T` of the // value must be `Copy`. Note that we prove that `T: Copy`, @@ -1237,8 +1238,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_rvalue(body, rv, location); if !self.unsized_feature_enabled() { - let trait_ref = - tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, [place_ty]); + let trait_ref = ty::TraitRef::from_lang_item( + tcx.at(self.last_span), + LangItem::Sized, + [place_ty], + ); self.prove_trait_ref( trait_ref, location.to_locations(), @@ -1810,7 +1814,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. let ty = place.ty(body, tcx).ty; - let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, [ty]); + let trait_ref = + ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Copy, [ty]); self.prove_trait_ref( trait_ref, @@ -1823,7 +1828,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } &Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => { - let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [ty]); + let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [ty]); self.prove_trait_ref( trait_ref, @@ -1835,7 +1840,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Rvalue::ShallowInitBox(operand, ty) => { self.check_operand(operand, location); - let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [*ty]); + let trait_ref = ty::TraitRef::from_lang_item(tcx.at(span), LangItem::Sized, [*ty]); self.prove_trait_ref( trait_ref, @@ -1932,9 +1937,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { CastKind::Pointer(PointerCast::Unsize) => { let &ty = ty; - let trait_ref = tcx - .at(span) - .mk_trait_ref(LangItem::CoerceUnsized, [op.ty(body, tcx), ty]); + let trait_ref = ty::TraitRef::from_lang_item( + tcx.at(span), + LangItem::CoerceUnsized, + [op.ty(body, tcx), ty], + ); self.prove_trait_ref( trait_ref, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index bf688f2b34e..7b65c828c33 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -157,8 +157,12 @@ impl Qualif for NeedsNonConstDrop { cx.tcx, ObligationCause::dummy_with_span(cx.body.span), cx.param_env, - ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty])) - .with_constness(ty::BoundConstness::ConstIfConst), + ty::Binder::dummy(ty::TraitRef::from_lang_item( + cx.tcx.at(cx.body.span), + LangItem::Destruct, + [ty], + )) + .with_constness(ty::BoundConstness::ConstIfConst), ); let infcx = cx.tcx.infer_ctxt().build(); diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 992316edb63..606d3bee0fc 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -689,7 +689,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let assoc_bindings = self.create_assoc_bindings_for_generic_args(args); let poly_trait_ref = - ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars); + ty::Binder::bind_with_vars(ty::TraitRef::new(tcx, trait_def_id, substs), bound_vars); debug!(?poly_trait_ref, ?assoc_bindings); bounds.push_trait_bound(tcx, poly_trait_ref, span, constness); @@ -822,7 +822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(b) = trait_segment.args().bindings.first() { prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span))); } - self.tcx().mk_trait_ref(trait_def_id, substs) + ty::TraitRef::new(self.tcx(), trait_def_id, substs) } #[instrument(level = "debug", skip(self, span))] diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index ba2d4319af6..1cf93c86f4f 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { let tcx = self.infcx.tcx; // - let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]); + let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]); let cause = traits::ObligationCause::misc(self.span, self.body_id); diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index 284b099e7bc..a751639b56f 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -57,7 +57,7 @@ impl<'tcx> Bounds<'tcx> { pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) { let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span)); - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [ty])); + let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, sized_def_id, [ty])); // Preferable to put this obligation first, since we report better errors for sized ambiguity. self.predicates.insert(0, (trait_ref.without_const().to_predicate(tcx), span)); } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index ad2624a5d2d..cef44c54def 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -538,7 +538,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { tcx, assoc_item, assoc_item, - tcx.mk_trait_ref(id.owner_id.to_def_id(), trait_substs), + ty::TraitRef::new(tcx, id.owner_id.to_def_id(), trait_substs), ); } _ => {} diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b2ebbf993a1..12f46bbb32b 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1784,7 +1784,7 @@ fn receiver_is_implemented<'tcx>( receiver_ty: Ty<'tcx>, ) -> bool { let tcx = wfcx.tcx(); - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty])); + let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, receiver_trait_def_id, [receiver_ty])); let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref); diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 611ce13b739..78c9bc1b2b5 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -340,7 +340,8 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef tcx, cause.clone(), param_env, - ty::Binder::dummy(tcx.mk_trait_ref( + ty::Binder::dummy(ty::TraitRef::new( + tcx, dispatch_from_dyn_trait, [field.ty(tcx, substs_a), field.ty(tcx, substs_b)], )), @@ -579,8 +580,12 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe // Register an obligation for `A: Trait`. let ocx = ObligationCtxt::new(&infcx); let cause = traits::ObligationCause::misc(span, impl_did); - let obligation = - Obligation::new(tcx, cause, param_env, tcx.mk_trait_ref(trait_def_id, [source, target])); + let obligation = Obligation::new( + tcx, + cause, + param_env, + ty::TraitRef::new(tcx, trait_def_id, [source, target]), + ); ocx.register_obligation(obligation); let errors = ocx.select_all_or_error(); if !errors.is_empty() { diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 507c24d540c..af1d61cd0ac 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -601,7 +601,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.tcx, cause, self.fcx.param_env, - self.tcx.mk_trait_ref(coerce_unsized_did, [coerce_source, coerce_target]) + ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]) )]; let mut has_unsized_tuple_coercion = false; @@ -764,9 +764,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.tcx, self.cause.clone(), self.param_env, - ty::Binder::dummy( - self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]), - ), + ty::Binder::dummy(ty::TraitRef::from_lang_item( + self.tcx.at(self.cause.span), + hir::LangItem::PointerLike, + [a], + )), )); Ok(InferOk { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 56c94505727..70ce45e21ea 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -481,7 +481,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of // that struct type. let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_or_alias_def_id) { - self.tcx.mk_trait_ref( + ty::TraitRef::new( + self.tcx, obligation.impl_or_alias_def_id, ty::InternalSubsts::identity_for_item(self.tcx, obligation.impl_or_alias_def_id), ) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 955463c1434..9948416f01b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1911,7 +1911,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { // Look for a user-provided impl of a `Fn` trait, and point to it. let new_def_id = self.probe(|_| { - let trait_ref = self.tcx.mk_trait_ref( + let trait_ref = ty::TraitRef::new(self.tcx, call_kind.to_def_id(self.tcx), [ callee_ty, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index eef2b5009c8..cb528519a71 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx, self.misc(expr.span), self.param_env, - ty::Binder::dummy(self.tcx.mk_trait_ref( + ty::Binder::dummy(ty::TraitRef::new(self.tcx, into_def_id, [expr_ty, expected_ty] )), @@ -1438,7 +1438,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..))) // Check that we're in fact trying to clone into the expected type && self.can_coerce(*pointee_ty, expected_ty) - && let trait_ref = ty::Binder::dummy(self.tcx.mk_trait_ref(clone_trait_did, [expected_ty])) + && let trait_ref = ty::Binder::dummy(ty::TraitRef::new(self.tcx, clone_trait_did, [expected_ty])) // And the expected type doesn't implement `Clone` && !self.predicate_must_hold_considering_regions(&traits::Obligation::new( self.tcx, diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index fab9a8a5f4f..5963a1632c5 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -316,7 +316,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.var_for_def(cause.span, param) }); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs); + let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, substs); // Construct an obligation let poly_trait_ref = ty::Binder::dummy(trait_ref); diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 4fd778910ba..bb982851a7b 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -954,7 +954,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { ) { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id); let trait_substs = self.fresh_item_substs(trait_def_id); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs); + let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, trait_substs); if self.tcx.is_trait_alias(trait_def_id) { // For trait aliases, recursively assume all explicitly named traits are relevant diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index db1f10f645f..fb16c32c0cb 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -72,7 +72,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.autoderef(span, ty).any(|(ty, _)| { info!("check deref {:?} impl FnOnce", ty); self.probe(|_| { - let trait_ref = tcx.mk_trait_ref( + let trait_ref = ty::TraitRef::new( + tcx, fn_once, [ ty, 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 c1ea0a0d95e..c9c1f0aeaac 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 @@ -261,11 +261,16 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { (false, None, None, Some(span), String::new()) }; - let expected_trait_ref = self - .cx - .resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, expected_substs)); - let actual_trait_ref = - self.cx.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, actual_substs)); + let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new( + self.cx.tcx, + trait_def_id, + expected_substs, + )); + let actual_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef::new( + self.cx.tcx, + trait_def_id, + 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/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index b8940e2f045..11f43469400 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -18,7 +18,7 @@ pub trait TraitEngine<'tcx>: 'tcx { def_id: DefId, cause: ObligationCause<'tcx>, ) { - let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]); + let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]); self.register_predicate_obligation( infcx, Obligation { diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 5ce32c7aaaa..64e7480e626 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -169,8 +169,11 @@ pub trait Printer<'tcx>: Sized { self.path_append( |cx: Self| { if trait_qualify_parent { - let trait_ref = - cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied()); + let trait_ref = ty::TraitRef::new( + cx.tcx(), + parent_def_id, + parent_substs.iter().copied(), + ); cx.path_qualified(trait_ref.self_ty(), Some(trait_ref)) } else { cx.print_def_path(parent_def_id, parent_substs) diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c6d10f4741a..7f28ed6c263 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -315,7 +315,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> { Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relate_substs(relation, a.substs, b.substs)?; - Ok(relation.tcx().mk_trait_ref(a.def_id, substs)) + Ok(ty::TraitRef::new(relation.tcx(), a.def_id, substs)) } } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 6146476de37..8e17c143068 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -728,13 +728,13 @@ impl<'tcx> PolyExistentialPredicate<'tcx> { ExistentialPredicate::AutoTrait(did) => { let generics = tcx.generics_of(did); let trait_ref = if generics.params.len() == 1 { - tcx.mk_trait_ref(did, [self_ty]) + ty::TraitRef::new(tcx, did, [self_ty]) } else { // If this is an ill-formed auto trait, then synthesize // new error substs for the missing generics. let err_substs = ty::InternalSubsts::extend_with_error(tcx, did, &[self_ty.into()]); - tcx.mk_trait_ref(did, err_substs) + ty::TraitRef::new(tcx, did, err_substs) }; self.rebind(trait_ref).without_const().to_predicate(tcx) } @@ -850,17 +850,22 @@ impl<'tcx> TraitRef<'tcx> { substs: SubstsRef<'tcx>, ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); - tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()])) + ty::TraitRef::new(tcx, trait_id, tcx.mk_substs(&substs[..defs.params.len()])) } /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` /// are the parameters defined on trait. pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> { - ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id))) + ty::Binder::dummy(ty::TraitRef::new( + tcx, + def_id, + InternalSubsts::identity_for_item(tcx, def_id), + )) } pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { - tcx.mk_trait_ref( + ty::TraitRef::new( + tcx, self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)), ) @@ -926,7 +931,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); - tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter())) + ty::TraitRef::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter())) } } @@ -1245,7 +1250,7 @@ impl<'tcx> AliasTy<'tcx> { let trait_def_id = self.trait_def_id(tcx); let trait_generics = tcx.generics_of(trait_def_id); ( - tcx.mk_trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)), + ty::TraitRef::new(tcx, trait_def_id, self.substs.truncate_to(tcx, trait_generics)), &self.substs[trait_generics.count()..], ) } @@ -1259,7 +1264,7 @@ impl<'tcx> AliasTy<'tcx> { /// as well. pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { let def_id = self.trait_def_id(tcx); - tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) + ty::TraitRef::new(tcx, def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) } pub fn self_ty(self) -> Ty<'tcx> { diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 6a7a9a92279..c73f8284ca5 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -191,7 +191,7 @@ impl<'tcx> ConstToPat<'tcx> { self.tcx(), ObligationCause::dummy(), self.param_env, - self.tcx().mk_trait_ref(partial_eq_trait_id, [ty, ty]), + ty::TraitRef::new(self.tcx(), partial_eq_trait_id, [ty, ty]), ); // FIXME: should this call a `predicate_must_hold` variant instead? diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index aea9f719027..c71ee8e74d1 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -30,8 +30,11 @@ fn custom_coerce_unsize_info<'tcx>( source_ty: Ty<'tcx>, target_ty: Ty<'tcx>, ) -> CustomCoerceUnsized { - let trait_ref = - ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, [source_ty, target_ty])); + let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item( + tcx, + LangItem::CoerceUnsized, + [source_ty, target_ty], + )); match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) { Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 9567329192d..505ac3d285d 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -127,18 +127,19 @@ where fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow { let tcx = self.def_id_visitor.tcx(); - let (trait_ref, assoc_substs) = - if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder { - projection.trait_ref_and_own_substs(tcx) - } else { - // HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys - let def_id = tcx.impl_trait_in_trait_parent_fn(projection.def_id); - let trait_generics = tcx.generics_of(def_id); - ( - tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)), - &projection.substs[trait_generics.count()..], - ) - }; + let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id) + != DefKind::ImplTraitPlaceholder + { + projection.trait_ref_and_own_substs(tcx) + } else { + // HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys + let def_id = tcx.impl_trait_in_trait_parent_fn(projection.def_id); + let trait_generics = tcx.generics_of(def_id); + ( + ty::TraitRef::new(tcx, def_id, projection.substs.truncate_to(tcx, trait_generics)), + &projection.substs[trait_generics.count()..], + ) + }; self.visit_trait(trait_ref)?; if self.def_id_visitor.shallow() { ControlFlow::Continue(()) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 911cc0b88c4..1d1a169aa9e 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -66,7 +66,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { params: impl IntoIterator>>, param_env: ty::ParamEnv<'tcx>, ) -> traits::EvaluationResult { - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, params); + let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, params); let obligation = traits::Obligation { cause: traits::ObligationCause::dummy(), diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index f0840e0443c..a5dc17f9f85 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -274,8 +274,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { .evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS); } }; - let output_is_sized_pred = tupled_inputs_and_output - .map_bound(|(_, output)| tcx.at(DUMMY_SP).mk_trait_ref(LangItem::Sized, [output])); + let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| { + ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output]) + }); let pred = tupled_inputs_and_output .map_bound(|(inputs, output)| ty::ProjectionPredicate { @@ -333,7 +334,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => { // FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints. - let sized_predicate = ty::Binder::dummy(tcx.at(DUMMY_SP).mk_trait_ref( + let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item( + tcx.at(DUMMY_SP), LangItem::Sized, [ty::GenericArg::from(goal.predicate.self_ty())], )); diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index 8e7097ce4a7..533e7b40917 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -242,12 +242,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { .evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS); } }; - let output_is_sized_pred = tupled_inputs_and_output - .map_bound(|(_, output)| tcx.at(DUMMY_SP).mk_trait_ref(LangItem::Sized, [output])); + let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| { + ty::TraitRef::from_lang_item(tcx.at(DUMMY_SP), LangItem::Sized, [output]) + }); let pred = tupled_inputs_and_output .map_bound(|(inputs, _)| { - tcx.mk_trait_ref(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]) + ty::TraitRef::new(tcx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]) }) .to_predicate(tcx); // A built-in `Fn` impl only holds if the output is sized. @@ -312,9 +313,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { Self::consider_implied_clause( ecx, goal, - ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [self_ty, generator.resume_ty()]), - ) + ty::Binder::dummy(ty::TraitRef::new( + tcx, + goal.predicate.def_id(), + [self_ty, generator.resume_ty()], + )) .to_predicate(tcx), // Technically, we need to check that the generator types are Sized, // but that's already proven by the generator being WF. @@ -360,9 +363,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { data.iter().map(|pred| goal.with(tcx, pred.with_self_ty(tcx, a_ty))), ); // The type must be Sized to be unsized. - ecx.add_goal( - goal.with(tcx, ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [a_ty]))), - ); + ecx.add_goal(goal.with( + tcx, + ty::Binder::dummy(ty::TraitRef::new(tcx, sized_def_id, [a_ty])), + )); // The type must outlive the lifetime of the `dyn` we're unsizing into. ecx.add_goal( goal.with(tcx, ty::Binder::dummy(ty::OutlivesPredicate(a_ty, region))), @@ -411,9 +415,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ecx.eq(goal.param_env, unsized_a_ty, b_ty)?; ecx.add_goal(goal.with( tcx, - ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [a_tail_ty, b_tail_ty]), - ), + ty::Binder::dummy(ty::TraitRef::new( + tcx, + goal.predicate.def_id(), + [a_tail_ty, b_tail_ty], + )), )); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } @@ -432,9 +438,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // Similar to ADTs, require that the rest of the fields are equal. ecx.add_goal(goal.with( tcx, - ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [*a_last_ty, *b_last_ty]), - ), + ty::Binder::dummy(ty::TraitRef::new( + tcx, + goal.predicate.def_id(), + [*a_last_ty, *b_last_ty], + )), )); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index e82672e8368..6b080a132f3 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -86,7 +86,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { ) -> AutoTraitResult { let tcx = self.tcx; - let trait_ref = tcx.mk_trait_ref(trait_did, [ty]); + let trait_ref = ty::TraitRef::new(tcx, trait_did, [ty]); let infcx = tcx.infer_ctxt().build(); let mut selcx = SelectionContext::new(&infcx); @@ -263,7 +263,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { let mut already_visited = FxHashSet::default(); let mut predicates = VecDeque::new(); predicates.push_back(ty::Binder::dummy(ty::TraitPredicate { - trait_ref: infcx.tcx.mk_trait_ref(trait_did, [ty]), + trait_ref: ty::TraitRef::new(infcx.tcx, trait_did, [ty]), constness: ty::BoundConstness::NotConst, // Auto traits are positive diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 2beebe94b6d..000427bbe83 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -97,7 +97,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { def_id: DefId, ) { let tcx = self.infcx.tcx; - let trait_ref = tcx.mk_trait_ref(def_id, [ty]); + let trait_ref = ty::TraitRef::new(tcx, def_id, [ty]); self.register_obligation(Obligation { cause, recursion_depth: 0, 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 ce187fbdf84..11395f0bc8b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -358,7 +358,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { span: DUMMY_SP, kind: TypeVariableOriginKind::MiscVariable, }); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, [ty.skip_binder(), var]); + let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, [ty.skip_binder(), var]); let obligation = Obligation::new( self.tcx, ObligationCause::dummy(), 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 c969e5d4975..c814aadfddc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3485,7 +3485,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { _ => None, }; let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate { - trait_ref: self.tcx.mk_trait_ref( + trait_ref: ty::TraitRef::new(self.tcx, trait_pred.def_id(), [field_ty].into_iter().chain(trait_substs), ), diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 4c9df5d9d0a..edea13854ff 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -127,7 +127,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>( ty: Ty<'tcx>, def_id: DefId, ) -> bool { - let trait_ref = ty::Binder::dummy(infcx.tcx.mk_trait_ref(def_id, [ty])); + let trait_ref = ty::Binder::dummy(ty::TraitRef::new(infcx.tcx, def_id, [ty])); pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const()) } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b8ad1925e4e..c31593b7b85 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -769,9 +769,11 @@ fn receiver_is_dispatchable<'tcx>( let param_env = tcx.param_env(method.def_id); // Self: Unsize - let unsize_predicate = ty::Binder::dummy( - tcx.mk_trait_ref(unsize_did, [tcx.types.self_param, unsized_self_ty]), - ) + let unsize_predicate = ty::Binder::dummy(ty::TraitRef::new( + tcx, + unsize_did, + [tcx.types.self_param, unsized_self_ty], + )) .without_const() .to_predicate(tcx); @@ -782,7 +784,7 @@ fn receiver_is_dispatchable<'tcx>( if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) } }); - ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx) + ty::Binder::dummy(ty::TraitRef::new(tcx, trait_def_id, substs)).to_predicate(tcx) }; let caller_bounds = @@ -797,9 +799,11 @@ fn receiver_is_dispatchable<'tcx>( // Receiver: DispatchFromDyn U]> let obligation = { - let predicate = ty::Binder::dummy( - tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]), - ); + let predicate = ty::Binder::dummy(ty::TraitRef::new( + tcx, + dispatch_from_dyn_did, + [receiver_ty, unsized_receiver_ty], + )); Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate) }; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index ea45412e47f..61922ec9ad7 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1319,7 +1319,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>( let trait_substs = obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id)); // FIXME(named-returns): Binders - let trait_predicate = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, trait_substs)); + let trait_predicate = ty::Binder::dummy(ty::TraitRef::new(tcx, trait_def_id, trait_substs)); let _ = selcx.infcx.commit_if_ok(|_| { match selcx.select(&obligation.with(tcx, trait_predicate)) { @@ -1683,7 +1683,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( &obligation.with( selcx.tcx(), ty::Binder::dummy( - selcx.tcx().at(obligation.cause.span()).mk_trait_ref(LangItem::Sized, [self_ty]), + ty::TraitRef::from_lang_item(selcx.tcx().at(obligation.cause.span()), LangItem::Sized, [self_ty]), ) .without_const(), ), @@ -1948,9 +1948,11 @@ fn confirm_builtin_candidate<'cx, 'tcx>( ) }); if check_is_sized { - let sized_predicate = ty::Binder::dummy( - tcx.at(obligation.cause.span()).mk_trait_ref(LangItem::Sized, [self_ty]), - ) + let sized_predicate = ty::Binder::dummy(ty::TraitRef::from_lang_item( + tcx.at(obligation.cause.span()), + LangItem::Sized, + [self_ty], + )) .without_const(); obligations.push(obligation.with(tcx, sized_predicate)); } 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 1db9b8ce92e..e2e767fc23e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -454,7 +454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation.param_env, self.tcx().mk_predicate(obligation.predicate.map_bound(|mut pred| { pred.trait_ref = - self.tcx().mk_trait_ref(fn_ptr_trait, [pred.trait_ref.self_ty()]); + ty::TraitRef::new(self.tcx(), fn_ptr_trait, [pred.trait_ref.self_ty()]); ty::PredicateKind::Clause(ty::Clause::Trait(pred)) })), ); @@ -629,7 +629,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // - let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]); + let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]); let obligation = traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref)); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 3bba11262f5..94197a1609e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -646,8 +646,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { output_ty, &mut nested, ); - let tr = - ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty])); + let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item( + self.tcx().at(cause.span), + LangItem::Sized, + [output_ty], + )); nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr)); Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested }) @@ -1050,8 +1053,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); // We can only make objects from sized types. - let tr = - ty::Binder::dummy(tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [source])); + let tr = ty::Binder::dummy(ty::TraitRef::from_lang_item( + tcx.at(cause.span), + LangItem::Sized, + [source], + )); nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx))); // If the type is `Foo + 'a`, ensure that the type @@ -1121,7 +1127,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Construct the nested `TailField: Unsize>` predicate. let tail_unsize_obligation = obligation.with( tcx, - tcx.mk_trait_ref(obligation.predicate.def_id(), [source_tail, target_tail]), + ty::TraitRef::new( + tcx, + obligation.predicate.def_id(), + [source_tail, target_tail], + ), ); nested.push(tail_unsize_obligation); } @@ -1146,8 +1156,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested.extend(obligations); // Add a nested `T: Unsize` predicate. - let last_unsize_obligation = obligation - .with(tcx, tcx.mk_trait_ref(obligation.predicate.def_id(), [a_last, b_last])); + let last_unsize_obligation = obligation.with( + tcx, + ty::TraitRef::new(tcx, obligation.predicate.def_id(), [a_last, b_last]), + ); nested.push(last_unsize_obligation); } @@ -1271,10 +1283,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { cause.clone(), obligation.recursion_depth + 1, self_ty.rebind(ty::TraitPredicate { - trait_ref: self - .tcx() - .at(cause.span) - .mk_trait_ref(LangItem::Destruct, [nested_ty]), + trait_ref: ty::TraitRef::from_lang_item( + self.tcx().at(cause.span), + LangItem::Destruct, + [nested_ty], + ), constness: ty::BoundConstness::ConstIfConst, polarity: ty::ImplPolarity::Positive, }), @@ -1295,10 +1308,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // or it's an ADT (and we need to check for a custom impl during selection) _ => { let predicate = self_ty.rebind(ty::TraitPredicate { - trait_ref: self - .tcx() - .at(cause.span) - .mk_trait_ref(LangItem::Destruct, [nested_ty]), + trait_ref: ty::TraitRef::from_lang_item( + self.tcx().at(cause.span), + LangItem::Destruct, + [nested_ty], + ), constness: ty::BoundConstness::ConstIfConst, polarity: ty::ImplPolarity::Positive, }); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 081e4d7cfa4..47e169b4082 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2412,7 +2412,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { self.tcx(), cause.clone(), param_env, - self.tcx().mk_trait_ref(trait_def_id, [normalized_ty]), + ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]), ); obligations.push(obligation); obligations diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 7792ceabe7e..7b7e297c64b 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -262,7 +262,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>( TupleArgumentsFlag::No => sig.skip_binder().inputs()[0], TupleArgumentsFlag::Yes => tcx.mk_tup(sig.skip_binder().inputs()), }; - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]); + let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, arguments_tuple]); sig.map_bound(|sig| (trait_ref, sig.output())) } @@ -273,7 +273,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>( sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> { assert!(!self_ty.has_escaping_bound_vars()); - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]); + let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]); sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty)) } @@ -284,7 +284,7 @@ pub fn future_trait_ref_and_outputs<'tcx>( sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> { assert!(!self_ty.has_escaping_bound_vars()); - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty]); + let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty]); sig.map_bound(|sig| (trait_ref, sig.return_ty)) } diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index a4e9928f8b2..35d4d8f3164 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -359,7 +359,7 @@ pub(crate) fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>( // this has been typecked-before, so diagnostics is not really needed. let unsize_trait_did = tcx.require_lang_item(LangItem::Unsize, None); - let trait_ref = tcx.mk_trait_ref(unsize_trait_did, [source, target]); + let trait_ref = ty::TraitRef::new(tcx, unsize_trait_did, [source, target]); match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) { Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 40e19abc0d0..9e659362ff2 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -448,7 +448,8 @@ impl<'tcx> WfPredicates<'tcx> { fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) { if !subty.has_escaping_bound_vars() { let cause = self.cause(cause); - let trait_ref = self.tcx.at(cause.span).mk_trait_ref(LangItem::Sized, [subty]); + let trait_ref = + ty::TraitRef::from_lang_item(self.tcx.at(cause.span), LangItem::Sized, [subty]); self.out.push(traits::Obligation::with_depth( self.tcx, cause, diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index cb06c7acff0..6d6eb40f252 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -62,7 +62,7 @@ fn sized_constraint_for_ty<'tcx>( // it on the impl. let Some(sized_trait) = tcx.lang_items().sized_trait() else { return vec![ty] }; - let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(sized_trait, [ty])) + let sized_predicate = ty::Binder::dummy(ty::TraitRef::new(tcx, sized_trait, [ty])) .without_const() .to_predicate(tcx); let predicates = tcx.predicates_of(adtdef.did()).predicates;