From 2d8c905e159ecc86cb747cbf2c69668b0750ea7b Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 25 Apr 2023 15:36:17 +0000 Subject: [PATCH] Move `TraitRef` constructors to the top In rust `new`-ish functions are usually the first ones in an `impl` block --- compiler/rustc_middle/src/ty/sty.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 8002e0cb95f3..6146476de37f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -844,11 +844,13 @@ impl<'tcx> TraitRef<'tcx> { Self::new(tcx.tcx, trait_def_id, substs) } - pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { - tcx.mk_trait_ref( - self.def_id, - [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)), - ) + pub fn from_method( + tcx: TyCtxt<'tcx>, + trait_id: DefId, + 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()])) } /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` @@ -857,19 +859,17 @@ impl<'tcx> TraitRef<'tcx> { ty::Binder::dummy(tcx.mk_trait_ref(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( + self.def_id, + [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)), + ) + } + #[inline] pub fn self_ty(&self) -> Ty<'tcx> { self.substs.type_at(0) } - - pub fn from_method( - tcx: TyCtxt<'tcx>, - trait_id: DefId, - 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()])) - } } pub type PolyTraitRef<'tcx> = Binder<'tcx, TraitRef<'tcx>>;