Skip to content

Commit 10f826f

Browse files
committed
fix some manual_map
1 parent e59643e commit 10f826f

File tree

7 files changed

+19
-31
lines changed

7 files changed

+19
-31
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
959959
None
960960
}
961961
}
962-
hir::ExprKind::MethodCall(_, _, args, span) => {
963-
if let Some(def_id) = typeck_results.type_dependent_def_id(*hir_id) {
964-
Some((def_id, *span, *args))
965-
} else {
966-
None
967-
}
968-
}
962+
hir::ExprKind::MethodCall(_, _, args, span) => typeck_results
963+
.type_dependent_def_id(*hir_id)
964+
.map(|def_id| (def_id, *span, *args)),
969965
_ => None,
970966
}
971967
};

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
529529
&& binding_id != self.binding_id
530530
{
531531
if self.check_and_add_sugg_binding(LetStmt {
532-
ty_hir_id_opt: if let Some(ty) = ty { Some(ty.hir_id) } else { None },
532+
ty_hir_id_opt: ty.map(|ty| ty.hir_id),
533533
binding_id,
534534
span: pat.span,
535535
init_hir_id: init.hir_id,

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,12 @@ pub(super) fn unexpected_cfg_value(
234234

235235
let suggestion = if let Some((value, value_span)) = value {
236236
// Suggest the most probable if we found one
237-
if let Some(best_match) = find_best_match_for_name(&possibilities, value, None) {
238-
Some(lints::unexpected_cfg_value::ChangeValueSuggestion::SimilarName {
237+
find_best_match_for_name(&possibilities, value, None).map(|best_match| {
238+
lints::unexpected_cfg_value::ChangeValueSuggestion::SimilarName {
239239
span: value_span,
240240
best_match,
241-
})
242-
} else {
243-
None
244-
}
241+
}
242+
})
245243
} else if let &[first_possibility] = &possibilities[..] {
246244
Some(lints::unexpected_cfg_value::ChangeValueSuggestion::SpecifyValue {
247245
span: name_span.shrink_to_hi(),

compiler/rustc_middle/src/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1482,10 +1482,10 @@ impl SourceScope {
14821482
let scope_data = &source_scopes[self];
14831483
if let Some((inlined_instance, _)) = scope_data.inlined {
14841484
Some(inlined_instance)
1485-
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
1486-
Some(source_scopes[inlined_scope].inlined.unwrap().0)
14871485
} else {
1488-
None
1486+
scope_data
1487+
.inlined_parent_scope
1488+
.map(|inlined_scope| source_scopes[inlined_scope].inlined.unwrap().0)
14891489
}
14901490
}
14911491
}

compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,8 @@ impl<'tcx> InhabitedPredicate<'tcx> {
190190
(Self::And(&[a, b]), c) | (c, Self::And(&[a, b])) => {
191191
if let Some(ac) = a.reduce_and(tcx, c) {
192192
Some(ac.and(tcx, b))
193-
} else if let Some(bc) = b.reduce_and(tcx, c) {
194-
Some(Self::And(tcx.arena.alloc([a, bc])))
195193
} else {
196-
None
194+
b.reduce_and(tcx, c).map(|bc| Self::And(tcx.arena.alloc([a, bc])))
197195
}
198196
}
199197
_ => None,
@@ -216,10 +214,8 @@ impl<'tcx> InhabitedPredicate<'tcx> {
216214
(Self::Or(&[a, b]), c) | (c, Self::Or(&[a, b])) => {
217215
if let Some(ac) = a.reduce_or(tcx, c) {
218216
Some(ac.or(tcx, b))
219-
} else if let Some(bc) = b.reduce_or(tcx, c) {
220-
Some(Self::Or(tcx.arena.alloc([a, bc])))
221217
} else {
222-
None
218+
b.reduce_or(tcx, c).map(|bc| Self::Or(tcx.arena.alloc([a, bc])))
223219
}
224220
}
225221
_ => None,

compiler/rustc_parse/src/parser/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,12 @@ fn find_similar_kw(lookup: Ident, candidates: &[Symbol]) -> Option<MisspelledKw>
224224
let lowercase_sym = Symbol::intern(&lowercase);
225225
if candidates.contains(&lowercase_sym) {
226226
Some(MisspelledKw { similar_kw: lowercase, span: lookup.span, is_incorrect_case: true })
227-
} else if let Some(similar_sym) = find_best_match_for_name(candidates, lookup.name, None) {
228-
Some(MisspelledKw {
227+
} else {
228+
find_best_match_for_name(candidates, lookup.name, None).map(|similar_sym| MisspelledKw {
229229
similar_kw: similar_sym.to_string(),
230230
span: lookup.span,
231231
is_incorrect_case: false,
232232
})
233-
} else {
234-
None
235233
}
236234
}
237235

compiler/rustc_ty_utils/src/abi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,11 @@ fn adjust_for_rust_scalar<'tcx>(
394394
if let Some(pointee) = layout.pointee_info_at(&cx, offset) {
395395
let kind = if let Some(kind) = pointee.safe {
396396
Some(kind)
397-
} else if let Some(pointee) = drop_target_pointee {
398-
// The argument to `drop_in_place` is semantically equivalent to a mutable reference.
399-
Some(PointerKind::MutableRef { unpin: pointee.is_unpin(tcx, cx.param_env()) })
400397
} else {
401-
None
398+
// The argument to `drop_in_place` is semantically equivalent to a mutable reference.
399+
drop_target_pointee.map(|pointee| PointerKind::MutableRef {
400+
unpin: pointee.is_unpin(tcx, cx.param_env()),
401+
})
402402
};
403403
if let Some(kind) = kind {
404404
attrs.pointee_align = Some(pointee.align);

0 commit comments

Comments
 (0)