Skip to content

Commit 085e528

Browse files
committed
Simplify is_sized_marker by using Iterator::eq
1 parent ea57de4 commit 085e528

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

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

0 commit comments

Comments
 (0)