Skip to content

Commit 6641233

Browse files
committed
Reduce repetition around lower_method_sig
1 parent 82091d4 commit 6641233

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

src/librustc/hir/lowering.rs

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,35 +2905,30 @@ impl<'a> LoweringContext<'a> {
29052905
),
29062906
TraitItemKind::Method(ref sig, None) => {
29072907
let names = self.lower_fn_args_to_names(&sig.decl);
2908-
self.add_in_band_defs(
2908+
let (generics, sig) = self.lower_method_sig(
29092909
&i.generics,
2910+
sig,
29102911
trait_item_def_id,
2911-
AnonymousLifetimeMode::PassThrough,
2912-
|this| {
2913-
hir::TraitItemKind::Method(
2914-
this.lower_method_sig(sig, trait_item_def_id, false, None),
2915-
hir::TraitMethod::Required(names),
2916-
)
2917-
},
2918-
)
2912+
false,
2913+
None,
2914+
);
2915+
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
29192916
}
29202917
TraitItemKind::Method(ref sig, Some(ref body)) => {
29212918
let body_id = self.lower_body(Some(&sig.decl), |this| {
29222919
let body = this.lower_block(body, false);
29232920
this.expr_block(body, ThinVec::new())
29242921
});
29252922

2926-
self.add_in_band_defs(
2923+
let (generics, sig) = self.lower_method_sig(
29272924
&i.generics,
2925+
sig,
29282926
trait_item_def_id,
2929-
AnonymousLifetimeMode::PassThrough,
2930-
|this| {
2931-
hir::TraitItemKind::Method(
2932-
this.lower_method_sig(sig, trait_item_def_id, false, None),
2933-
hir::TraitMethod::Provided(body_id),
2934-
)
2935-
},
2936-
)
2927+
false,
2928+
None,
2929+
);
2930+
2931+
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
29372932
}
29382933
TraitItemKind::Type(ref bounds, ref default) => (
29392934
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
@@ -3001,23 +2996,14 @@ impl<'a> LoweringContext<'a> {
30012996
ImplItemKind::Method(ref sig, ref body) => {
30022997
let body_id = self.lower_async_body(&sig.decl, sig.header.asyncness, body);
30032998
let impl_trait_return_allow = !self.is_in_trait_impl;
3004-
3005-
self.add_in_band_defs(
2999+
let (generics, sig) = self.lower_method_sig(
30063000
&i.generics,
3001+
sig,
30073002
impl_item_def_id,
3008-
AnonymousLifetimeMode::PassThrough,
3009-
|this| {
3010-
hir::ImplItemKind::Method(
3011-
this.lower_method_sig(
3012-
sig,
3013-
impl_item_def_id,
3014-
impl_trait_return_allow,
3015-
sig.header.asyncness.opt_return_id(),
3016-
),
3017-
body_id,
3018-
)
3019-
},
3020-
)
3003+
impl_trait_return_allow,
3004+
sig.header.asyncness.opt_return_id(),
3005+
);
3006+
(generics, hir::ImplItemKind::Method(sig, body_id))
30213007
}
30223008
ImplItemKind::Type(ref ty) => (
30233009
self.lower_generics(&i.generics, ImplTraitContext::Disallowed),
@@ -3231,15 +3217,20 @@ impl<'a> LoweringContext<'a> {
32313217

32323218
fn lower_method_sig(
32333219
&mut self,
3220+
generics: &Generics,
32343221
sig: &MethodSig,
32353222
fn_def_id: DefId,
32363223
impl_trait_return_allow: bool,
32373224
is_async: Option<NodeId>,
3238-
) -> hir::MethodSig {
3239-
hir::MethodSig {
3240-
header: self.lower_fn_header(sig.header),
3241-
decl: self.lower_fn_decl(&sig.decl, Some(fn_def_id), impl_trait_return_allow, is_async),
3242-
}
3225+
) -> (hir::Generics, hir::MethodSig) {
3226+
let header = self.lower_fn_header(sig.header);
3227+
let (generics, decl) = self.add_in_band_defs(
3228+
generics,
3229+
fn_def_id,
3230+
AnonymousLifetimeMode::PassThrough,
3231+
|cx| cx.lower_fn_decl(&sig.decl, Some(fn_def_id), impl_trait_return_allow, is_async),
3232+
);
3233+
(generics, hir::MethodSig { header, decl })
32433234
}
32443235

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

0 commit comments

Comments
 (0)