Skip to content

Commit a561c6a

Browse files
committed
Don't use ok_or_else, cleanups
1 parent 79c34a1 commit a561c6a

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

compiler/rustc_ast_lowering/src/delegation/attributes.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
6565
) -> Vec<hir::Attribute> {
6666
ADDITIONS
6767
.iter()
68-
.filter_map(|addition_info| {
69-
if existing.is_some_and(|attrs| attrs.iter().any(|a| (addition_info.equals)(a))) {
70-
return None;
71-
}
72-
73-
match addition_info.kind {
74-
AdditionKind::Default { factory } => Some(factory(span)),
75-
AdditionKind::Inherit { factory, .. } =>
76-
{
77-
#[allow(deprecated)]
78-
self.tcx
79-
.get_all_attrs(sig_id)
80-
.iter()
81-
.find_map(|a| (addition_info.equals)(a).then(|| factory(span, a)))
82-
}
83-
}
68+
.filter_map(|addition| {
69+
existing
70+
.is_none_or(|attrs| !attrs.iter().any(|a| (addition.equals)(a)))
71+
.then(|| match addition.kind {
72+
AdditionKind::Default { factory } => Some(factory(span)),
73+
AdditionKind::Inherit { factory, .. } =>
74+
{
75+
#[allow(deprecated)]
76+
self.tcx
77+
.get_all_attrs(sig_id)
78+
.iter()
79+
.find_map(|a| (addition.equals)(a).then(|| factory(span, a)))
80+
}
81+
})
82+
.flatten()
8483
})
8584
.collect::<Vec<_>>()
8685
}

compiler/rustc_ast_lowering/src/delegation/resolution.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ impl<'tcx, T: LoweringContextForResolution<'tcx>> DelegationResolverForLowering<
214214

215215
// If there are definitions inside and we can't delete target expression, then report an error.
216216
// FIXME(fn_delegation): support deletion of target expression with defs inside.
217-
(should_generate_block || !contains_defs).ok_or_else(|| {
218-
tcx.dcx().emit_err(DelegationAttemptedBlockWithDefsDeletion { span: block.span })
219-
})
217+
if should_generate_block || !contains_defs {
218+
Ok(())
219+
} else {
220+
Err(tcx.dcx().emit_err(DelegationAttemptedBlockWithDefsDeletion { span: block.span }))
221+
}
220222
}
221223

222224
fn should_generate_block(

0 commit comments

Comments
 (0)