Use Iterator::eq and (dogfood) eq_by in compiler and library
This commit is contained in:
parent
f957826bff
commit
68a7c25078
17 changed files with 20 additions and 33 deletions
|
|
@ -114,8 +114,7 @@ impl PartialEq<Symbol> for Path {
|
|||
impl PartialEq<&[Symbol]> for Path {
|
||||
#[inline]
|
||||
fn eq(&self, names: &&[Symbol]) -> bool {
|
||||
self.segments.len() == names.len()
|
||||
&& self.segments.iter().zip(names.iter()).all(|(s1, s2)| s1 == s2)
|
||||
self.segments.iter().eq(*names)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#![feature(associated_type_defaults)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(macro_metavar_expr)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![recursion_limit = "256"]
|
||||
|
|
|
|||
|
|
@ -48,9 +48,7 @@ impl TokenTree {
|
|||
match (self, other) {
|
||||
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
|
||||
(TokenTree::Delimited(.., delim, tts), TokenTree::Delimited(.., delim2, tts2)) => {
|
||||
delim == delim2
|
||||
&& tts.len() == tts2.len()
|
||||
&& tts.iter().zip(tts2.iter()).all(|(a, b)| a.eq_unspanned(b))
|
||||
delim == delim2 && tts.iter().eq_by(tts2.iter(), |a, b| a.eq_unspanned(b))
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ impl<'a> PathParser<'a> {
|
|||
}
|
||||
|
||||
pub fn segments_is(&self, segments: &[Symbol]) -> bool {
|
||||
self.len() == segments.len() && self.segments().zip(segments).all(|(a, b)| a.name == *b)
|
||||
self.segments().map(|segment| &segment.name).eq(segments)
|
||||
}
|
||||
|
||||
pub fn word(&self) -> Option<Ident> {
|
||||
|
|
|
|||
|
|
@ -377,8 +377,7 @@ mod llvm_enzyme {
|
|||
(ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => {
|
||||
let a = &a.item.path;
|
||||
let b = &b.item.path;
|
||||
a.segments.len() == b.segments.len()
|
||||
&& a.segments.iter().zip(b.segments.iter()).all(|(a, b)| a.ident == b.ident)
|
||||
a.segments.iter().eq_by(&b.segments, |a, b| a.ident == b.ident)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,21 +356,14 @@ fn contains_maybe_sized_bound(bounds: &[GenericBound]) -> bool {
|
|||
bounds.iter().any(is_maybe_sized_bound)
|
||||
}
|
||||
|
||||
fn path_segment_is_exact_match(path_segments: &[ast::PathSegment], syms: &[Symbol]) -> bool {
|
||||
path_segments.iter().zip(syms).all(|(segment, &symbol)| segment.ident.name == symbol)
|
||||
}
|
||||
|
||||
fn is_sized_marker(path: &ast::Path) -> bool {
|
||||
const CORE_UNSIZE: [Symbol; 3] = [sym::core, sym::marker, sym::Sized];
|
||||
const STD_UNSIZE: [Symbol; 3] = [sym::std, sym::marker, sym::Sized];
|
||||
if path.segments.len() == 4 && path.is_global() {
|
||||
path_segment_is_exact_match(&path.segments[1..], &CORE_UNSIZE)
|
||||
|| path_segment_is_exact_match(&path.segments[1..], &STD_UNSIZE)
|
||||
} else if path.segments.len() == 3 {
|
||||
path_segment_is_exact_match(&path.segments, &CORE_UNSIZE)
|
||||
|| path_segment_is_exact_match(&path.segments, &STD_UNSIZE)
|
||||
let segments = || path.segments.iter().map(|segment| segment.ident.name);
|
||||
if path.is_global() {
|
||||
segments().skip(1).eq(CORE_UNSIZE) || segments().skip(1).eq(STD_UNSIZE)
|
||||
} else {
|
||||
*path == sym::Sized
|
||||
segments().eq(CORE_UNSIZE) || segments().eq(STD_UNSIZE) || *path == sym::Sized
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -768,7 +768,7 @@ fn report_missing_placeholders(
|
|||
|
||||
if !found_foreign && invalid_refs.is_empty() {
|
||||
// Show example if user didn't use any format specifiers
|
||||
let show_example = used.iter().all(|used| !used);
|
||||
let show_example = !used.contains(&true);
|
||||
|
||||
if !show_example {
|
||||
if unused.len() > 1 {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(proc_macro_quote)]
|
||||
#![feature(rustdoc_internals)]
|
||||
|
|
|
|||
|
|
@ -1298,10 +1298,7 @@ impl AttributeExt for Attribute {
|
|||
#[inline]
|
||||
fn path_matches(&self, name: &[Symbol]) -> bool {
|
||||
match &self {
|
||||
Attribute::Unparsed(n) => {
|
||||
n.path.segments.len() == name.len()
|
||||
&& n.path.segments.iter().zip(name).all(|(s, n)| s.name == *n)
|
||||
}
|
||||
Attribute::Unparsed(n) => n.path.segments.iter().map(|ident| &ident.name).eq(name),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2803,9 +2803,7 @@ impl<'a, 'b, 'tcx> ArgMatchingCtxt<'a, 'b, 'tcx> {
|
|||
if let Some((assoc, fn_sig)) = self.similar_assoc(call_name)
|
||||
&& fn_sig.inputs()[1..]
|
||||
.iter()
|
||||
.zip(input_types.iter())
|
||||
.all(|(expected, found)| self.may_coerce(*expected, *found))
|
||||
&& fn_sig.inputs()[1..].len() == input_types.len()
|
||||
.eq_by(input_types, |expected, found| self.may_coerce(*expected, found))
|
||||
{
|
||||
let assoc_name = assoc.name();
|
||||
err.span_suggestion_verbose(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#![feature(box_patterns)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(never_type)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
|
|
|
|||
|
|
@ -1914,9 +1914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
if let Some(ref args) = call_args
|
||||
&& fn_sig.inputs()[1..]
|
||||
.iter()
|
||||
.zip(args.into_iter())
|
||||
.all(|(expected, found)| self.may_coerce(*expected, *found))
|
||||
&& fn_sig.inputs()[1..].len() == args.len()
|
||||
.eq_by(args, |expected, found| self.may_coerce(*expected, *found))
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
item_name.span,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#![feature(default_field_values)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iter_order_by)]
|
||||
#![recursion_limit = "256"]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn sp(a: u32, b: u32) -> Span {
|
|||
}
|
||||
|
||||
fn cmp_token_stream(a: &TokenStream, b: &TokenStream) -> bool {
|
||||
a.len() == b.len() && a.iter().zip(b.iter()).all(|(x, y)| x.eq_unspanned(y))
|
||||
a.iter().eq_by(b.iter(), |x, y| x.eq_unspanned(y))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -2413,7 +2413,7 @@ impl<K, V> Default for BTreeMap<K, V> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<K: PartialEq, V: PartialEq, A: Allocator + Clone> PartialEq for BTreeMap<K, V, A> {
|
||||
fn eq(&self, other: &BTreeMap<K, V, A>) -> bool {
|
||||
self.len() == other.len() && self.iter().zip(other).all(|(a, b)| a == b)
|
||||
self.iter().eq(other)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1685,7 +1685,7 @@ impl Type {
|
|||
match (self_cleared, other_cleared) {
|
||||
// Recursive cases.
|
||||
(Type::Tuple(a), Type::Tuple(b)) => {
|
||||
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_doc_subtype_of(b, cache))
|
||||
a.iter().eq_by(b, |a, b| a.is_doc_subtype_of(b, cache))
|
||||
}
|
||||
(Type::Slice(a), Type::Slice(b)) => a.is_doc_subtype_of(b, cache),
|
||||
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_doc_subtype_of(b, cache),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#![feature(if_let_guard)]
|
||||
#![feature(iter_advance_by)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(test)]
|
||||
#![warn(rustc::internal)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue