Skip to content

Commit 2d8c905

Browse files
committed
Move TraitRef constructors to the top
In rust `new`-ish functions are usually the first ones in an `impl` block
1 parent 14f8327 commit 2d8c905

File tree

1 file changed

+14
-14
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+14
-14
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,13 @@ impl<'tcx> TraitRef<'tcx> {
844844
Self::new(tcx.tcx, trait_def_id, substs)
845845
}
846846

847-
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
848-
tcx.mk_trait_ref(
849-
self.def_id,
850-
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
851-
)
847+
pub fn from_method(
848+
tcx: TyCtxt<'tcx>,
849+
trait_id: DefId,
850+
substs: SubstsRef<'tcx>,
851+
) -> ty::TraitRef<'tcx> {
852+
let defs = tcx.generics_of(trait_id);
853+
tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
852854
}
853855

854856
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
@@ -857,19 +859,17 @@ impl<'tcx> TraitRef<'tcx> {
857859
ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
858860
}
859861

862+
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
863+
tcx.mk_trait_ref(
864+
self.def_id,
865+
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
866+
)
867+
}
868+
860869
#[inline]
861870
pub fn self_ty(&self) -> Ty<'tcx> {
862871
self.substs.type_at(0)
863872
}
864-
865-
pub fn from_method(
866-
tcx: TyCtxt<'tcx>,
867-
trait_id: DefId,
868-
substs: SubstsRef<'tcx>,
869-
) -> ty::TraitRef<'tcx> {
870-
let defs = tcx.generics_of(trait_id);
871-
tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
872-
}
873873
}
874874

875875
pub type PolyTraitRef<'tcx> = Binder<'tcx, TraitRef<'tcx>>;

0 commit comments

Comments
 (0)