Skip to content

Commit 1795bf8

Browse files
authored
Rollup merge of #110404 - matthiaskrgr:mapmap, r=Nilstrieb
fix clippy::toplevel_ref_arg and ::manual_map r? ``@Nilstrieb``
2 parents 6e9a52c + 543f8bc commit 1795bf8

File tree

12 files changed

+42
-70
lines changed

12 files changed

+42
-70
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
141141
args: args
142142
.named_args()
143143
.iter()
144-
.filter_map(|a| {
145-
if let Some(ident) = a.kind.ident() {
146-
Some((a, ident))
147-
} else {
148-
None
149-
}
150-
})
144+
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
151145
.map(|(arg, n)| n.span.to(arg.expr.span))
152146
.collect(),
153147
});

compiler/rustc_data_structures/src/sso/map.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,9 @@ impl<K: Eq + Hash, V> SsoHashMap<K, V> {
256256
pub fn remove(&mut self, key: &K) -> Option<V> {
257257
match self {
258258
SsoHashMap::Array(array) => {
259-
if let Some(index) = array.iter().position(|(k, _v)| k == key) {
260-
Some(array.swap_remove(index).1)
261-
} else {
262-
None
263-
}
259+
array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1)
264260
}
261+
265262
SsoHashMap::Map(map) => map.remove(key),
266263
}
267264
}

compiler/rustc_lint/src/unused.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -636,20 +636,14 @@ trait UnusedDelimLint {
636636
return;
637637
}
638638
let spans = match value.kind {
639-
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
640-
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
641-
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
642-
} else {
643-
None
644-
}
645-
}
639+
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => block.stmts[0]
640+
.span
641+
.find_ancestor_inside(value.span)
642+
.map(|span| (value.span.with_hi(span.lo()), value.span.with_lo(span.hi()))),
646643
ast::ExprKind::Paren(ref expr) => {
647-
let expr_span = expr.span.find_ancestor_inside(value.span);
648-
if let Some(expr_span) = expr_span {
649-
Some((value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi())))
650-
} else {
651-
None
652-
}
644+
expr.span.find_ancestor_inside(value.span).map(|expr_span| {
645+
(value.span.with_hi(expr_span.lo()), value.span.with_lo(expr_span.hi()))
646+
})
653647
}
654648
_ => return,
655649
};
@@ -928,11 +922,10 @@ impl UnusedParens {
928922
// Otherwise proceed with linting.
929923
_ => {}
930924
}
931-
let spans = if let Some(inner) = inner.span.find_ancestor_inside(value.span) {
932-
Some((value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())))
933-
} else {
934-
None
935-
};
925+
let spans = inner
926+
.span
927+
.find_ancestor_inside(value.span)
928+
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
936929
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space);
937930
}
938931
}
@@ -1043,11 +1036,11 @@ impl EarlyLintPass for UnusedParens {
10431036
if self.with_self_ty_parens && b.generic_params.len() > 0 => {}
10441037
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
10451038
_ => {
1046-
let spans = if let Some(r) = r.span.find_ancestor_inside(ty.span) {
1047-
Some((ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())))
1048-
} else {
1049-
None
1050-
};
1039+
let spans = r
1040+
.span
1041+
.find_ancestor_inside(ty.span)
1042+
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));
1043+
10511044
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
10521045
}
10531046
}

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
493493
cond: &Operand<'tcx>,
494494
location: Location,
495495
) -> Option<!> {
496-
let ref value = self.eval_operand(&cond, location)?;
496+
let value = &self.eval_operand(&cond, location)?;
497497
trace!("assertion on {:?} should be {:?}", value, expected);
498498

499499
let expected = Scalar::from_bool(expected);

compiler/rustc_parse/src/parser/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ impl<'a> Parser<'a> {
4545
Some(InnerAttrForbiddenReason::AfterOuterDocComment {
4646
prev_doc_comment_span: prev_outer_attr_sp.unwrap(),
4747
})
48-
} else if let Some(prev_outer_attr_sp) = prev_outer_attr_sp {
49-
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp })
5048
} else {
51-
None
49+
prev_outer_attr_sp.map(|prev_outer_attr_sp| {
50+
InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }
51+
})
5252
};
5353
let inner_parse_policy = InnerAttrPolicy::Forbidden(inner_error_reason);
5454
just_parsed_doc_comment = false;

compiler/rustc_resolve/src/diagnostics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1869,15 +1869,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18691869
Some(LexicalScopeBinding::Item(name_binding)) => Some(name_binding.span),
18701870
_ => None,
18711871
};
1872-
let suggestion = if let Some(span) = match_span {
1873-
Some((
1872+
let suggestion = match_span.map(|span| {
1873+
(
18741874
vec![(span, String::from(""))],
18751875
format!("`{}` is defined here, but is not a type", ident),
18761876
Applicability::MaybeIncorrect,
1877-
))
1878-
} else {
1879-
None
1880-
};
1877+
)
1878+
});
18811879

18821880
(format!("use of undeclared type `{}`", ident), suggestion)
18831881
} else {

compiler/rustc_span/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,11 @@ impl SourceFile {
16631663

16641664
if let Some(ref src) = self.src {
16651665
Some(Cow::from(get_until_newline(src, begin)))
1666-
} else if let Some(src) = self.external_src.borrow().get_source() {
1667-
Some(Cow::Owned(String::from(get_until_newline(src, begin))))
16681666
} else {
1669-
None
1667+
self.external_src
1668+
.borrow()
1669+
.get_source()
1670+
.map(|src| Cow::Owned(String::from(get_until_newline(src, begin))))
16701671
}
16711672
}
16721673

compiler/rustc_span/src/source_map.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,8 @@ impl SourceMap {
906906

907907
let snippet = if let Some(ref src) = local_begin.sf.src {
908908
Some(&src[start_index..])
909-
} else if let Some(src) = src.get_source() {
910-
Some(&src[start_index..])
911909
} else {
912-
None
910+
src.get_source().map(|src| &src[start_index..])
913911
};
914912

915913
match snippet {

compiler/rustc_trait_selection/src/traits/util.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,11 @@ pub fn get_vtable_index_of_object_method<'tcx, N>(
243243
) -> Option<usize> {
244244
// Count number of methods preceding the one we are selecting and
245245
// add them to the total offset.
246-
if let Some(index) = tcx
247-
.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
246+
tcx.own_existential_vtable_entries(object.upcast_trait_ref.def_id())
248247
.iter()
249248
.copied()
250249
.position(|def_id| def_id == method_def_id)
251-
{
252-
Some(object.vtable_base + index)
253-
} else {
254-
None
255-
}
250+
.map(|index| object.vtable_base + index)
256251
}
257252

258253
pub fn closure_trait_ref_and_return_type<'tcx>(

compiler/rustc_ty_utils/src/instance.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,12 @@ fn resolve_associated_item<'tcx>(
234234
_ => None,
235235
},
236236
traits::ImplSource::Object(ref data) => {
237-
if let Some(index) = traits::get_vtable_index_of_object_method(tcx, data, trait_item_id)
238-
{
239-
Some(Instance {
237+
traits::get_vtable_index_of_object_method(tcx, data, trait_item_id).map(|index| {
238+
Instance {
240239
def: ty::InstanceDef::Virtual(trait_item_id, index),
241240
substs: rcvr_substs,
242-
})
243-
} else {
244-
None
245-
}
241+
}
242+
})
246243
}
247244
traits::ImplSource::Builtin(..) => {
248245
let lang_items = tcx.lang_items();

compiler/rustc_ty_utils/src/structural_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
1313
/// Note that this does *not* recursively check if the substructure of `adt_ty`
1414
/// implements the traits.
1515
fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool {
16-
let ref infcx = tcx.infer_ctxt().build();
16+
let infcx = &tcx.infer_ctxt().build();
1717
let cause = ObligationCause::dummy();
1818

1919
let ocx = ObligationCtxt::new(infcx);

src/librustdoc/formats/cache.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,13 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
300300
ParentStackItem::Impl { for_, .. } => for_.def_id(&self.cache),
301301
ParentStackItem::Type(item_id) => item_id.as_def_id(),
302302
};
303-
let path = match did.and_then(|did| self.cache.paths.get(&did)) {
303+
let path = did
304+
.and_then(|did| self.cache.paths.get(&did))
304305
// The current stack not necessarily has correlation
305306
// for where the type was defined. On the other
306307
// hand, `paths` always has the right
307308
// information if present.
308-
Some((fqp, _)) => Some(&fqp[..fqp.len() - 1]),
309-
None => None,
310-
};
309+
.map(|(fqp, _)| &fqp[..fqp.len() - 1]);
311310
((did, path), true)
312311
}
313312
}

0 commit comments

Comments
 (0)