Skip to content

Commit 7aaaaa7

Browse files
committed
Reduce repetition around lower_method_sig
1 parent 6162b14 commit 7aaaaa7

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

src/librustc/hir/lowering.rs

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,35 +2635,28 @@ impl<'a> LoweringContext<'a> {
26352635
),
26362636
TraitItemKind::Method(ref sig, None) => {
26372637
let names = self.lower_fn_args_to_names(&sig.decl);
2638-
self.add_in_band_defs(
2638+
let (generics, sig) = self.lower_method_sig(
26392639
&i.generics,
2640+
sig,
26402641
trait_item_def_id,
2641-
AnonymousLifetimeMode::PassThrough,
2642-
|this| {
2643-
hir::TraitItemKind::Method(
2644-
this.lower_method_sig(sig, trait_item_def_id, false),
2645-
hir::TraitMethod::Required(names),
2646-
)
2647-
},
2648-
)
2642+
false,
2643+
);
2644+
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
26492645
}
26502646
TraitItemKind::Method(ref sig, Some(ref body)) => {
26512647
let body_id = self.lower_body(Some(&sig.decl), |this| {
26522648
let body = this.lower_block(body, false);
26532649
this.expr_block(body, ThinVec::new())
26542650
});
26552651

2656-
self.add_in_band_defs(
2652+
let (generics, sig) = self.lower_method_sig(
26572653
&i.generics,
2654+
sig,
26582655
trait_item_def_id,
2659-
AnonymousLifetimeMode::PassThrough,
2660-
|this| {
2661-
hir::TraitItemKind::Method(
2662-
this.lower_method_sig(sig, trait_item_def_id, false),
2663-
hir::TraitMethod::Provided(body_id),
2664-
)
2665-
},
2666-
)
2656+
false,
2657+
);
2658+
2659+
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
26672660
}
26682661
TraitItemKind::Type(ref bounds, ref default) => (
26692662
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
@@ -2734,22 +2727,13 @@ impl<'a> LoweringContext<'a> {
27342727
this.expr_block(body, ThinVec::new())
27352728
});
27362729
let impl_trait_return_allow = !self.is_in_trait_impl;
2737-
2738-
self.add_in_band_defs(
2730+
let (generics, sig) = self.lower_method_sig(
27392731
&i.generics,
2740-
impl_item_def_id,
2741-
AnonymousLifetimeMode::PassThrough,
2742-
|this| {
2743-
hir::ImplItemKind::Method(
2744-
this.lower_method_sig(
27452732
sig,
27462733
impl_item_def_id,
27472734
impl_trait_return_allow,
2748-
),
2749-
body_id,
2750-
)
2751-
},
2752-
)
2735+
);
2736+
(generics, hir::ImplItemKind::Method(sig, body_id))
27532737
}
27542738
ImplItemKind::Type(ref ty) => (
27552739
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
@@ -2923,16 +2907,28 @@ impl<'a> LoweringContext<'a> {
29232907

29242908
fn lower_method_sig(
29252909
&mut self,
2910+
generics: &Generics,
29262911
sig: &MethodSig,
29272912
fn_def_id: DefId,
29282913
impl_trait_return_allow: bool,
2929-
) -> hir::MethodSig {
2930-
hir::MethodSig {
2931-
abi: sig.abi,
2932-
unsafety: self.lower_unsafety(sig.unsafety),
2933-
constness: self.lower_constness(sig.constness),
2934-
decl: self.lower_fn_decl(&sig.decl, Some(fn_def_id), impl_trait_return_allow),
2935-
}
2914+
) -> (hir::Generics, hir::MethodSig) {
2915+
let unsafety = self.lower_unsafety(sig.unsafety);
2916+
let constness = self.lower_constness(sig.constness);
2917+
let (generics, decl) = self.add_in_band_defs(
2918+
generics,
2919+
fn_def_id,
2920+
AnonymousLifetimeMode::PassThrough,
2921+
|this| this.lower_fn_decl(&sig.decl, Some(fn_def_id), impl_trait_return_allow),
2922+
);
2923+
(
2924+
generics,
2925+
hir::MethodSig {
2926+
abi: sig.abi,
2927+
unsafety,
2928+
constness,
2929+
decl,
2930+
},
2931+
)
29362932
}
29372933

29382934
fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {

0 commit comments

Comments
 (0)