Skip to content

Commit 0ae3da3

Browse files
committed
Remove TraitRef::new
1 parent 6af3638 commit 0ae3da3

File tree

8 files changed

+22
-40
lines changed

8 files changed

+22
-40
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
680680
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
681681

682682
let poly_trait_ref =
683-
ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars);
683+
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
684684

685685
debug!(?poly_trait_ref, ?assoc_bindings);
686686
bounds.trait_bounds.push((poly_trait_ref, span, constness));
@@ -813,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
813813
if let Some(b) = trait_segment.args().bindings.first() {
814814
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
815815
}
816-
ty::TraitRef::new(trait_def_id, substs)
816+
self.tcx().mk_trait_ref(trait_def_id, substs)
817817
}
818818

819819
#[instrument(level = "debug", skip(self, span))]

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,19 +2132,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21322132
_ => {
21332133
// Look for a user-provided impl of a `Fn` trait, and point to it.
21342134
let new_def_id = self.probe(|_| {
2135-
let trait_ref = ty::TraitRef::new(
2135+
let trait_ref = self.tcx.mk_trait_ref(
21362136
call_kind.to_def_id(self.tcx),
2137-
self.tcx.mk_substs(
2138-
[
2139-
ty::GenericArg::from(callee_ty),
2140-
self.next_ty_var(TypeVariableOrigin {
2141-
kind: TypeVariableOriginKind::MiscVariable,
2142-
span: rustc_span::DUMMY_SP,
2143-
})
2144-
.into(),
2145-
]
2146-
.into_iter(),
2147-
),
2137+
[
2138+
callee_ty,
2139+
self.next_ty_var(TypeVariableOrigin {
2140+
kind: TypeVariableOriginKind::MiscVariable,
2141+
span: rustc_span::DUMMY_SP,
2142+
}),
2143+
],
21482144
);
21492145
let obligation = traits::Obligation::new(
21502146
self.tcx,

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
285285
self.var_for_def(span, param)
286286
});
287287

288-
let trait_ref = ty::TraitRef::new(trait_def_id, substs);
288+
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
289289

290290
// Construct an obligation
291291
let poly_trait_ref = ty::Binder::dummy(trait_ref);
@@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
326326
self.var_for_def(span, param)
327327
});
328328

329-
let trait_ref = ty::TraitRef::new(trait_def_id, substs);
329+
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
330330

331331
// Construct an obligation
332332
let poly_trait_ref = ty::Binder::dummy(trait_ref);

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
920920
) {
921921
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
922922
let trait_substs = self.fresh_item_substs(trait_def_id);
923-
let trait_ref = ty::TraitRef::new(trait_def_id, trait_substs);
923+
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
924924

925925
if self.tcx.is_trait_alias(trait_def_id) {
926926
// For trait aliases, assume all supertraits are relevant.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ impl<'tcx> TyCtxt<'tcx> {
28712871
substs.collect::<Vec<_>>(),
28722872
);
28732873
let substs = self.mk_substs(substs);
2874-
ty::TraitRef::new(trait_def_id, substs)
2874+
ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
28752875
}
28762876

28772877
pub fn mk_alias_ty(

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,8 @@ pub trait Printer<'tcx>: Sized {
169169
self.path_append(
170170
|cx: Self| {
171171
if trait_qualify_parent {
172-
let trait_ref = ty::TraitRef::new(
173-
parent_def_id,
174-
cx.tcx().intern_substs(parent_substs),
175-
);
172+
let trait_ref =
173+
cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied());
176174
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
177175
} else {
178176
cx.print_def_path(parent_def_id, parent_substs)

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -818,14 +818,10 @@ pub struct TraitRef<'tcx> {
818818
pub substs: SubstsRef<'tcx>,
819819
/// This field exists to prevent the creation of `TraitRef` without
820820
/// calling [TyCtxt::mk_trait_ref].
821-
_use_mk_trait_ref_instead: (),
821+
pub(super) _use_mk_trait_ref_instead: (),
822822
}
823823

824824
impl<'tcx> TraitRef<'tcx> {
825-
pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> {
826-
TraitRef { def_id, substs, _use_mk_trait_ref_instead: () }
827-
}
828-
829825
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
830826
tcx.mk_trait_ref(
831827
self.def_id,
@@ -836,11 +832,7 @@ impl<'tcx> TraitRef<'tcx> {
836832
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
837833
/// are the parameters defined on trait.
838834
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
839-
ty::Binder::dummy(TraitRef {
840-
def_id,
841-
substs: InternalSubsts::identity_for_item(tcx, def_id),
842-
_use_mk_trait_ref_instead: (),
843-
})
835+
ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
844836
}
845837

846838
#[inline]
@@ -854,11 +846,7 @@ impl<'tcx> TraitRef<'tcx> {
854846
substs: SubstsRef<'tcx>,
855847
) -> ty::TraitRef<'tcx> {
856848
let defs = tcx.generics_of(trait_id);
857-
ty::TraitRef {
858-
def_id: trait_id,
859-
substs: tcx.intern_substs(&substs[..defs.params.len()]),
860-
_use_mk_trait_ref_instead: (),
861-
}
849+
tcx.mk_trait_ref(trait_id, tcx.intern_substs(&substs[..defs.params.len()]))
862850
}
863851
}
864852

src/tools/clippy/clippy_lints/src/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter;
1515
use rustc_middle::traits::Reveal;
1616
use rustc_middle::ty::{
1717
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
18-
TraitRef, Ty, TyCtxt,
18+
Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
2121
use rustc_span::source_map::Span;
@@ -513,9 +513,9 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
513513
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
514514
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
515515
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
516-
trait_ref: TraitRef::new(
516+
trait_ref: tcx.mk_trait_ref(
517517
eq_trait_id,
518-
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
518+
[tcx.mk_param_from_def(param)],
519519
),
520520
constness: BoundConstness::NotConst,
521521
polarity: ImplPolarity::Positive,

0 commit comments

Comments
 (0)