Skip to content

Commit c9d4f06

Browse files
nikomatsakistmandry
andcommitted
use ty::TraitRef::identity where possible
Co-authored-by: Tyler Mandry <[email protected]>
1 parent 5c15163 commit c9d4f06

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use hir::def_id::DefId;
2323
use lint;
2424
use traits;
2525
use ty::{self, Ty, TyCtxt, TypeFoldable};
26-
use ty::subst::Substs;
2726
use ty::util::ExplicitSelf;
2827
use std::borrow::Cow;
2928
use syntax::ast;
@@ -173,10 +172,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
173172
trait_def_id: DefId,
174173
supertraits_only: bool) -> bool
175174
{
176-
let trait_ref = ty::Binder::dummy(ty::TraitRef {
177-
def_id: trait_def_id,
178-
substs: Substs::identity_for_item(self, trait_def_id)
179-
});
175+
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(self, trait_def_id));
180176
let predicates = if supertraits_only {
181177
self.super_predicates_of(trait_def_id)
182178
} else {
@@ -391,10 +387,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
391387

392388
// Compute supertraits of current trait lazily.
393389
if supertraits.is_none() {
394-
let trait_ref = ty::Binder::bind(ty::TraitRef {
395-
def_id: trait_def_id,
396-
substs: Substs::identity_for_item(self, trait_def_id)
397-
});
390+
let trait_ref = ty::Binder::bind(
391+
ty::TraitRef::identity(self, trait_def_id),
392+
);
398393
supertraits = Some(traits::supertraits(self, trait_ref).collect());
399394
}
400395

src/librustc/ty/sty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,15 @@ impl<'tcx> TraitRef<'tcx> {
614614
TraitRef { def_id: def_id, substs: substs }
615615
}
616616

617+
/// Returns a TraitRef of the form `P0: Foo<P1..Pn>` where `Pi`
618+
/// are the parameters defined on trait.
619+
pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> {
620+
TraitRef {
621+
def_id,
622+
substs: Substs::identity_for_item(tcx, def_id),
623+
}
624+
}
625+
617626
pub fn self_ty(&self) -> Ty<'tcx> {
618627
self.substs.type_at(0)
619628
}

src/librustc_traits/lowering.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::hir::{self, ImplPolarity};
1515
use rustc::traits::{Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause,
1616
WhereClause, FromEnv, WellFormed};
1717
use rustc::ty::query::Providers;
18-
use rustc::ty::subst::Substs;
1918
use rustc::ty::{self, Slice, TyCtxt};
2019
use rustc_data_structures::fx::FxHashSet;
2120
use std::mem;
@@ -225,10 +224,7 @@ fn program_clauses_for_trait<'a, 'tcx>(
225224

226225
// `Self: Trait<P1..Pn>`
227226
let trait_pred = ty::TraitPredicate {
228-
trait_ref: ty::TraitRef {
229-
def_id,
230-
substs: Substs::identity_for_item(tcx, def_id),
231-
},
227+
trait_ref: ty::TraitRef::identity(tcx, def_id),
232228
};
233229

234230
// `Implemented(Self: Trait<P1..Pn>)`

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
274274
ItemTrait(_, _, ref generics, ..) => {
275275
// Implied `Self: Trait` and supertrait bounds.
276276
if param_id == item_node_id {
277-
result.predicates.push(ty::TraitRef {
278-
def_id: item_def_id,
279-
substs: Substs::identity_for_item(tcx, item_def_id)
280-
}.to_predicate());
277+
result.predicates.push(
278+
ty::TraitRef::identity(tcx, item_def_id).to_predicate()
279+
);
281280
}
282281
generics
283282
}
@@ -1359,10 +1358,7 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13591358
ItemUnion(_, ref generics) => generics,
13601359

13611360
ItemTrait(_, _, ref generics, .., ref items) => {
1362-
is_trait = Some((ty::TraitRef {
1363-
def_id,
1364-
substs: Substs::identity_for_item(tcx, def_id)
1365-
}, items));
1361+
is_trait = Some((ty::TraitRef::identity(tcx, def_id), items));
13661362
generics
13671363
}
13681364
ItemExistential(ref exist_ty) => {

0 commit comments

Comments
 (0)