Skip to content

Commit 68a7c25

Browse files
committed
Use Iterator::eq and (dogfood) eq_by in compiler and library
1 parent f957826 commit 68a7c25

File tree

17 files changed

+20
-33
lines changed

17 files changed

+20
-33
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ impl PartialEq<Symbol> for Path {
114114
impl PartialEq<&[Symbol]> for Path {
115115
#[inline]
116116
fn eq(&self, names: &&[Symbol]) -> bool {
117-
self.segments.len() == names.len()
118-
&& self.segments.iter().zip(names.iter()).all(|(s1, s2)| s1 == s2)
117+
self.segments.iter().eq(*names)
119118
}
120119
}
121120

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(associated_type_defaults)]
1616
#![feature(box_patterns)]
1717
#![feature(if_let_guard)]
18+
#![feature(iter_order_by)]
1819
#![feature(macro_metavar_expr)]
1920
#![feature(rustdoc_internals)]
2021
#![recursion_limit = "256"]

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl TokenTree {
4848
match (self, other) {
4949
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
5050
(TokenTree::Delimited(.., delim, tts), TokenTree::Delimited(.., delim2, tts2)) => {
51-
delim == delim2
52-
&& tts.len() == tts2.len()
53-
&& tts.iter().zip(tts2.iter()).all(|(a, b)| a.eq_unspanned(b))
51+
delim == delim2 && tts.iter().eq_by(tts2.iter(), |a, b| a.eq_unspanned(b))
5452
}
5553
_ => false,
5654
}

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a> PathParser<'a> {
4949
}
5050

5151
pub fn segments_is(&self, segments: &[Symbol]) -> bool {
52-
self.len() == segments.len() && self.segments().zip(segments).all(|(a, b)| a.name == *b)
52+
self.segments().map(|segment| &segment.name).eq(segments)
5353
}
5454

5555
pub fn word(&self) -> Option<Ident> {

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ mod llvm_enzyme {
377377
(ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => {
378378
let a = &a.item.path;
379379
let b = &b.item.path;
380-
a.segments.len() == b.segments.len()
381-
&& a.segments.iter().zip(b.segments.iter()).all(|(a, b)| a.ident == b.ident)
380+
a.segments.iter().eq_by(&b.segments, |a, b| a.ident == b.ident)
382381
}
383382
_ => false,
384383
}

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,14 @@ fn contains_maybe_sized_bound(bounds: &[GenericBound]) -> bool {
356356
bounds.iter().any(is_maybe_sized_bound)
357357
}
358358

359-
fn path_segment_is_exact_match(path_segments: &[ast::PathSegment], syms: &[Symbol]) -> bool {
360-
path_segments.iter().zip(syms).all(|(segment, &symbol)| segment.ident.name == symbol)
361-
}
362-
363359
fn is_sized_marker(path: &ast::Path) -> bool {
364360
const CORE_UNSIZE: [Symbol; 3] = [sym::core, sym::marker, sym::Sized];
365361
const STD_UNSIZE: [Symbol; 3] = [sym::std, sym::marker, sym::Sized];
366-
if path.segments.len() == 4 && path.is_global() {
367-
path_segment_is_exact_match(&path.segments[1..], &CORE_UNSIZE)
368-
|| path_segment_is_exact_match(&path.segments[1..], &STD_UNSIZE)
369-
} else if path.segments.len() == 3 {
370-
path_segment_is_exact_match(&path.segments, &CORE_UNSIZE)
371-
|| path_segment_is_exact_match(&path.segments, &STD_UNSIZE)
362+
let segments = || path.segments.iter().map(|segment| segment.ident.name);
363+
if path.is_global() {
364+
segments().skip(1).eq(CORE_UNSIZE) || segments().skip(1).eq(STD_UNSIZE)
372365
} else {
373-
*path == sym::Sized
366+
segments().eq(CORE_UNSIZE) || segments().eq(STD_UNSIZE) || *path == sym::Sized
374367
}
375368
}
376369

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fn report_missing_placeholders(
768768

769769
if !found_foreign && invalid_refs.is_empty() {
770770
// Show example if user didn't use any format specifiers
771-
let show_example = used.iter().all(|used| !used);
771+
let show_example = !used.contains(&true);
772772

773773
if !show_example {
774774
if unused.len() > 1 {

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(box_patterns)]
1212
#![feature(decl_macro)]
1313
#![feature(if_let_guard)]
14+
#![feature(iter_order_by)]
1415
#![feature(proc_macro_internals)]
1516
#![feature(proc_macro_quote)]
1617
#![feature(rustdoc_internals)]

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,7 @@ impl AttributeExt for Attribute {
12981298
#[inline]
12991299
fn path_matches(&self, name: &[Symbol]) -> bool {
13001300
match &self {
1301-
Attribute::Unparsed(n) => {
1302-
n.path.segments.len() == name.len()
1303-
&& n.path.segments.iter().zip(name).all(|(s, n)| s.name == *n)
1304-
}
1301+
Attribute::Unparsed(n) => n.path.segments.iter().map(|ident| &ident.name).eq(name),
13051302
_ => false,
13061303
}
13071304
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,9 +2803,7 @@ impl<'a, 'b, 'tcx> ArgMatchingCtxt<'a, 'b, 'tcx> {
28032803
if let Some((assoc, fn_sig)) = self.similar_assoc(call_name)
28042804
&& fn_sig.inputs()[1..]
28052805
.iter()
2806-
.zip(input_types.iter())
2807-
.all(|(expected, found)| self.may_coerce(*expected, *found))
2808-
&& fn_sig.inputs()[1..].len() == input_types.len()
2806+
.eq_by(input_types, |expected, found| self.may_coerce(*expected, found))
28092807
{
28102808
let assoc_name = assoc.name();
28112809
err.span_suggestion_verbose(

0 commit comments

Comments
 (0)