Skip to content

use find(x) instead of filter(x).next() #69496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ impl RegionHighlightMode {
pub fn highlighting_region(&mut self, region: ty::Region<'_>, number: usize) {
let num_slots = self.highlight_regions.len();
let first_avail_slot =
self.highlight_regions.iter_mut().filter(|s| s.is_none()).next().unwrap_or_else(|| {
self.highlight_regions.iter_mut().find(|s| s.is_none()).unwrap_or_else(|| {
bug!("can only highlight {} placeholders at a time", num_slots,)
});
*first_avail_slot = Some((*region, number));
3 changes: 1 addition & 2 deletions src/librustc_infer/traits/coherence.rs
Original file line number Diff line number Diff line change
@@ -399,8 +399,7 @@ fn orphan_check_trait_ref<'tcx>(
let local_type = trait_ref
.input_types()
.flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
.filter(|ty| ty_is_non_local_constructor(ty, in_crate).is_none())
.next();
.find(|ty| ty_is_non_local_constructor(ty, in_crate).is_none());

debug!("orphan_check_trait_ref: uncovered ty local_type: `{:?}`", local_type);

2 changes: 1 addition & 1 deletion src/librustc_infer/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -1442,7 +1442,7 @@ pub fn suggest_constraining_type_param(
const MSG_RESTRICT_TYPE: &str = "consider restricting this type parameter with";
const MSG_RESTRICT_TYPE_FURTHER: &str = "consider further restricting this type parameter with";

let param = generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next();
let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);

let param = if let Some(param) = param {
param
7 changes: 2 additions & 5 deletions src/librustc_parse/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
@@ -93,18 +93,15 @@ impl<'a> TokenTreesReader<'a> {
}

if let Some((delim, _)) = self.open_braces.last() {
if let Some((_, open_sp, close_sp)) = self
.matching_delim_spans
.iter()
.filter(|(d, open_sp, close_sp)| {
if let Some((_, open_sp, close_sp)) =
self.matching_delim_spans.iter().find(|(d, open_sp, close_sp)| {
if let Some(close_padding) = sm.span_to_margin(*close_sp) {
if let Some(open_padding) = sm.span_to_margin(*open_sp) {
return delim == d && close_padding != open_padding;
}
}
false
})
.next()
// these are in reverse order as they get inserted on close, but
{
// we want the last open/first close
8 changes: 2 additions & 6 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -225,12 +225,8 @@ impl<'a> Parser<'a> {

// Make sure that the span of the parent node is larger than the span of lhs and rhs,
// including the attributes.
let lhs_span = lhs
.attrs
.iter()
.filter(|a| a.style == AttrStyle::Outer)
.next()
.map_or(lhs_span, |a| a.span);
let lhs_span =
lhs.attrs.iter().find(|a| a.style == AttrStyle::Outer).map_or(lhs_span, |a| a.span);
let span = lhs_span.to(rhs.span);
lhs = match op {
AssocOp::Add
3 changes: 1 addition & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
@@ -565,8 +565,7 @@ impl Attributes {

let inner_docs = attrs
.iter()
.filter(|a| a.doc_str().is_some())
.next()
.find(|a| a.doc_str().is_some())
.map_or(true, |a| a.style == AttrStyle::Inner);

Attributes {