Skip to content

Commit 13e4c6c

Browse files
authored
Rollup merge of #69547 - matthiaskrgr:more_misc, r=Mark-Simulacrum
remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.
2 parents 61b091b + ff9341a commit 13e4c6c

File tree

5 files changed

+39
-53
lines changed

5 files changed

+39
-53
lines changed

src/librustc_infer/traits/wf.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
232232
// found type `()`
233233
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
234234
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
235-
if let Some(impl_item) = items
236-
.iter()
237-
.filter(|item| item.ident == trait_assoc_item.ident)
238-
.next()
235+
if let Some(impl_item) =
236+
items.iter().find(|item| item.ident == trait_assoc_item.ident)
239237
{
240238
cause.span = impl_item.span;
241239
cause.code = traits::AssocTypeBound(Box::new(AssocTypeBoundData {
@@ -285,13 +283,11 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
285283
{
286284
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
287285
.iter()
288-
.filter(|i| i.def_id == *item_def_id)
289-
.next()
286+
.find(|i| i.def_id == *item_def_id)
290287
.and_then(|trait_assoc_item| {
291288
items
292289
.iter()
293-
.filter(|i| i.ident == trait_assoc_item.ident)
294-
.next()
290+
.find(|i| i.ident == trait_assoc_item.ident)
295291
.map(|impl_item| (impl_item, trait_assoc_item))
296292
})
297293
{

src/librustc_mir/dataflow/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,7 @@ pub trait BottomValue {
689689
/// 3. Override `join` to do the opposite from what it's doing now.
690690
#[inline]
691691
fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
692-
if Self::BOTTOM_VALUE == false {
693-
inout_set.union(in_set)
694-
} else {
695-
inout_set.intersect(in_set)
696-
}
692+
if !Self::BOTTOM_VALUE { inout_set.union(in_set) } else { inout_set.intersect(in_set) }
697693
}
698694
}
699695

src/librustc_parse/parser/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a> Parser<'a> {
8989

9090
fn parse_stmt_item(&mut self, attrs: Vec<Attribute>) -> PResult<'a, Option<ast::Item>> {
9191
let old = mem::replace(&mut self.directory.ownership, DirectoryOwnership::UnownedViaBlock);
92-
let item = self.parse_item_common(attrs.clone(), false, true, |_| true)?;
92+
let item = self.parse_item_common(attrs, false, true, |_| true)?;
9393
self.directory.ownership = old;
9494
Ok(item)
9595
}

src/librustc_resolve/late/diagnostics.rs

+32-38
Original file line numberDiff line numberDiff line change
@@ -968,18 +968,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
968968
for missing in &self.missing_named_lifetime_spots {
969969
match missing {
970970
MissingLifetimeSpot::Generics(generics) => {
971-
let (span, sugg) = if let Some(param) = generics
972-
.params
973-
.iter()
974-
.filter(|p| match p.kind {
971+
let (span, sugg) = if let Some(param) =
972+
generics.params.iter().find(|p| match p.kind {
975973
hir::GenericParamKind::Type {
976974
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
977975
..
978976
} => false,
979977
_ => true,
980-
})
981-
.next()
982-
{
978+
}) {
983979
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
984980
} else {
985981
(generics.span, format!("<{}>", lifetime_ref))
@@ -1053,25 +1049,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10531049
Applicability::MaybeIncorrect,
10541050
);
10551051
};
1056-
let suggest_new =
1057-
|err: &mut DiagnosticBuilder<'_>, sugg: &str| {
1058-
err.span_label(span, "expected named lifetime parameter");
1052+
let suggest_new = |err: &mut DiagnosticBuilder<'_>, sugg: &str| {
1053+
err.span_label(span, "expected named lifetime parameter");
10591054

1060-
for missing in self.missing_named_lifetime_spots.iter().rev() {
1061-
let mut introduce_suggestion = vec![];
1062-
let msg;
1063-
let should_break;
1064-
introduce_suggestion.push(match missing {
1055+
for missing in self.missing_named_lifetime_spots.iter().rev() {
1056+
let mut introduce_suggestion = vec![];
1057+
let msg;
1058+
let should_break;
1059+
introduce_suggestion.push(match missing {
10651060
MissingLifetimeSpot::Generics(generics) => {
10661061
msg = "consider introducing a named lifetime parameter".to_string();
10671062
should_break = true;
1068-
if let Some(param) = generics.params.iter().filter(|p| match p.kind {
1063+
if let Some(param) = generics.params.iter().find(|p| match p.kind {
10691064
hir::GenericParamKind::Type {
10701065
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
10711066
..
10721067
} => false,
10731068
_ => true,
1074-
}).next() {
1069+
}) {
10751070
(param.span.shrink_to_lo(), "'a, ".to_string())
10761071
} else {
10771072
(generics.span, "<'a>".to_string())
@@ -1090,30 +1085,29 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10901085
(*span, span_type.suggestion("'a"))
10911086
}
10921087
});
1093-
for param in params {
1094-
if let Ok(snippet) =
1095-
self.tcx.sess.source_map().span_to_snippet(param.span)
1096-
{
1097-
if snippet.starts_with("&") && !snippet.starts_with("&'") {
1098-
introduce_suggestion
1099-
.push((param.span, format!("&'a {}", &snippet[1..])));
1100-
} else if snippet.starts_with("&'_ ") {
1101-
introduce_suggestion
1102-
.push((param.span, format!("&'a {}", &snippet[4..])));
1103-
}
1088+
for param in params {
1089+
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(param.span)
1090+
{
1091+
if snippet.starts_with("&") && !snippet.starts_with("&'") {
1092+
introduce_suggestion
1093+
.push((param.span, format!("&'a {}", &snippet[1..])));
1094+
} else if snippet.starts_with("&'_ ") {
1095+
introduce_suggestion
1096+
.push((param.span, format!("&'a {}", &snippet[4..])));
11041097
}
11051098
}
1106-
introduce_suggestion.push((span, sugg.to_string()));
1107-
err.multipart_suggestion(
1108-
&msg,
1109-
introduce_suggestion,
1110-
Applicability::MaybeIncorrect,
1111-
);
1112-
if should_break {
1113-
break;
1114-
}
11151099
}
1116-
};
1100+
introduce_suggestion.push((span, sugg.to_string()));
1101+
err.multipart_suggestion(
1102+
&msg,
1103+
introduce_suggestion,
1104+
Applicability::MaybeIncorrect,
1105+
);
1106+
if should_break {
1107+
break;
1108+
}
1109+
}
1110+
};
11171111

11181112
match (
11191113
lifetime_names.len(),

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub fn make_test(
398398
use rustc_span::source_map::FilePathMapping;
399399

400400
let filename = FileName::anon_source_code(s);
401-
let source = crates + &everything_else;
401+
let source = crates + everything_else;
402402

403403
// Any errors in parsing should also appear when the doctest is compiled for real, so just
404404
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.

0 commit comments

Comments
 (0)