]> git.lizzy.rs Git - rust.git/commitdiff
Remove TraitRef::new
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 13 Dec 2022 11:25:31 +0000 (11:25 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 14 Dec 2022 15:36:39 +0000 (15:36 +0000)
compiler/rustc_hir_analysis/src/astconv/mod.rs
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
compiler/rustc_hir_typeck/src/method/mod.rs
compiler/rustc_hir_typeck/src/method/probe.rs
compiler/rustc_middle/src/ty/context.rs
compiler/rustc_middle/src/ty/print/mod.rs
compiler/rustc_middle/src/ty/sty.rs
src/tools/clippy/clippy_lints/src/derive.rs

index babf2ef1af418f9cb22f4870d276e8985974948d..71f26eb60c9628e880f5f5b71ca4274e4fed5598 100644 (file)
@@ -680,7 +680,7 @@ fn instantiate_poly_trait_ref_inner(
         let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
 
         let poly_trait_ref =
-            ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars);
+            ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
 
         debug!(?poly_trait_ref, ?assoc_bindings);
         bounds.trait_bounds.push((poly_trait_ref, span, constness));
@@ -813,7 +813,7 @@ fn ast_path_to_mono_trait_ref(
         if let Some(b) = trait_segment.args().bindings.first() {
             Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
         }
-        ty::TraitRef::new(trait_def_id, substs)
+        self.tcx().mk_trait_ref(trait_def_id, substs)
     }
 
     #[instrument(level = "debug", skip(self, span))]
index 6f0e8eb9039a56e24f302f17ddc3e3edab2366f5..8e520e563ff630ecdeb62b0e4a1b046feb7dbe14 100644 (file)
@@ -2132,19 +2132,15 @@ fn label_fn_like(
                 _ => {
                     // Look for a user-provided impl of a `Fn` trait, and point to it.
                     let new_def_id = self.probe(|_| {
-                        let trait_ref = ty::TraitRef::new(
+                        let trait_ref = self.tcx.mk_trait_ref(
                             call_kind.to_def_id(self.tcx),
-                            self.tcx.mk_substs(
-                                [
-                                    ty::GenericArg::from(callee_ty),
-                                    self.next_ty_var(TypeVariableOrigin {
-                                        kind: TypeVariableOriginKind::MiscVariable,
-                                        span: rustc_span::DUMMY_SP,
-                                    })
-                                    .into(),
-                                ]
-                                .into_iter(),
-                            ),
+                            [
+                                callee_ty,
+                                self.next_ty_var(TypeVariableOrigin {
+                                    kind: TypeVariableOriginKind::MiscVariable,
+                                    span: rustc_span::DUMMY_SP,
+                                }),
+                            ],
                         );
                         let obligation = traits::Obligation::new(
                             self.tcx,
index a7eae392de1dd1fccefb6d46a0b3ecd1c27795ec..3f3af53d199b12918512a1597a9f7b1eb34532a5 100644 (file)
@@ -285,7 +285,7 @@ pub(super) fn obligation_for_method(
             self.var_for_def(span, param)
         });
 
-        let trait_ref = ty::TraitRef::new(trait_def_id, substs);
+        let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
 
         // Construct an obligation
         let poly_trait_ref = ty::Binder::dummy(trait_ref);
@@ -326,7 +326,7 @@ pub(super) fn obligation_for_op_method(
             self.var_for_def(span, param)
         });
 
-        let trait_ref = ty::TraitRef::new(trait_def_id, substs);
+        let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
 
         // Construct an obligation
         let poly_trait_ref = ty::Binder::dummy(trait_ref);
index 070359e71becc13381d15e12fb510b336a58c28e..b9e7830bf079214af2a29491fff1ab458fbee011 100644 (file)
@@ -920,7 +920,7 @@ fn assemble_extension_candidates_for_trait(
     ) {
         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 = ty::TraitRef::new(trait_def_id, trait_substs);
+        let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
 
         if self.tcx.is_trait_alias(trait_def_id) {
             // For trait aliases, assume all supertraits are relevant.
index c220814d4fdf60c404212658b423401f67612333..ae913c6a3674549f8969b41fd73744b9594f42f5 100644 (file)
@@ -2871,7 +2871,7 @@ pub fn mk_trait_ref(
             substs.collect::<Vec<_>>(),
         );
         let substs = self.mk_substs(substs);
-        ty::TraitRef::new(trait_def_id, substs)
+        ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
     }
 
     pub fn mk_alias_ty(
index 3fad349bff8124a2f474dd73bcf105729175e9ce..29bad33e4bc0f36aa5ef8f955e1ec30da54ef19a 100644 (file)
@@ -169,10 +169,8 @@ fn default_print_def_path(
                 self.path_append(
                     |cx: Self| {
                         if trait_qualify_parent {
-                            let trait_ref = ty::TraitRef::new(
-                                parent_def_id,
-                                cx.tcx().intern_substs(parent_substs),
-                            );
+                            let trait_ref =
+                                cx.tcx().mk_trait_ref(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)
index 28f04c83a9b5edbf715a5b03744938f44d295460..e073637402fceeb0006cf4a1ab5c362d7b29d38c 100644 (file)
@@ -818,14 +818,10 @@ pub struct TraitRef<'tcx> {
     pub substs: SubstsRef<'tcx>,
     /// This field exists to prevent the creation of `TraitRef` without
     /// calling [TyCtxt::mk_trait_ref].
-    _use_mk_trait_ref_instead: (),
+    pub(super) _use_mk_trait_ref_instead: (),
 }
 
 impl<'tcx> TraitRef<'tcx> {
-    pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> {
-        TraitRef { def_id, substs, _use_mk_trait_ref_instead: () }
-    }
-
     pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
         tcx.mk_trait_ref(
             self.def_id,
@@ -836,11 +832,7 @@ pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
     /// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
     /// are the parameters defined on trait.
     pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
-        ty::Binder::dummy(TraitRef {
-            def_id,
-            substs: InternalSubsts::identity_for_item(tcx, def_id),
-            _use_mk_trait_ref_instead: (),
-        })
+        ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
     }
 
     #[inline]
@@ -854,11 +846,7 @@ pub fn from_method(
         substs: SubstsRef<'tcx>,
     ) -> ty::TraitRef<'tcx> {
         let defs = tcx.generics_of(trait_id);
-        ty::TraitRef {
-            def_id: trait_id,
-            substs: tcx.intern_substs(&substs[..defs.params.len()]),
-            _use_mk_trait_ref_instead: (),
-        }
+        tcx.mk_trait_ref(trait_id, tcx.intern_substs(&substs[..defs.params.len()]))
     }
 }
 
index 9e596ca8157eb93b58fc827d6c4d3eda261a116c..3f0b165f2b604a006e253bf4972c458611599212 100644 (file)
@@ -15,7 +15,7 @@
 use rustc_middle::traits::Reveal;
 use rustc_middle::ty::{
     self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
-    TraitRef, Ty, TyCtxt,
+    Ty, TyCtxt,
 };
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::source_map::Span;
@@ -513,9 +513,9 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
         tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
             params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
                 tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
-                    trait_ref: TraitRef::new(
+                    trait_ref: tcx.mk_trait_ref(
                         eq_trait_id,
-                        tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
+                        [tcx.mk_param_from_def(param)],
                     ),
                     constness: BoundConstness::NotConst,
                     polarity: ImplPolarity::Positive,