diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-04-25 15:36:17 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-04-25 15:36:17 +0000 |
| commit | 2d8c905e159ecc86cb747cbf2c69668b0750ea7b (patch) | |
| tree | 0a041715cac43799773d58413d952c9fcde6728a | |
| parent | 14f832733d89a968b347ced1a82f84abfeda13b0 (diff) | |
| download | rust-2d8c905e159ecc86cb747cbf2c69668b0750ea7b.tar.gz rust-2d8c905e159ecc86cb747cbf2c69668b0750ea7b.zip | |
Move `TraitRef` constructors to the top
In rust `new`-ish functions are usually the first ones in an `impl` block
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 8002e0cb95f..6146476de37 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<P1..Pn>` 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>>; |
