Skip to content

Commit 9440b67

Browse files
authored
Unrolled build for rust-lang#136097
Rollup merge of rust-lang#136097 - yotamofek:check-len-and-index, r=petrochenkov rustc_ast: replace some len-checks + indexing with slice patterns etc.
2 parents 633a3fe + 6144468 commit 9440b67

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct Path {
100100
impl PartialEq<Symbol> for Path {
101101
#[inline]
102102
fn eq(&self, symbol: &Symbol) -> bool {
103-
self.segments.len() == 1 && { self.segments[0].ident.name == *symbol }
103+
matches!(&self.segments[..], [segment] if segment.ident.name == *symbol)
104104
}
105105
}
106106

@@ -121,13 +121,13 @@ impl Path {
121121
}
122122

123123
pub fn is_global(&self) -> bool {
124-
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
124+
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
125125
}
126126

127127
/// If this path is a single identifier with no arguments, does not ensure
128128
/// that the path resolves to a const param, the caller should check this.
129129
pub fn is_potential_trivial_const_arg(&self) -> bool {
130-
self.segments.len() == 1 && self.segments[0].args.is_none()
130+
matches!(self.segments[..], [PathSegment { args: None, .. }])
131131
}
132132
}
133133

compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl AttrItem {
302302
impl MetaItem {
303303
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
304304
pub fn ident(&self) -> Option<Ident> {
305-
if self.path.segments.len() == 1 { Some(self.path.segments[0].ident) } else { None }
305+
if let [PathSegment { ident, .. }] = self.path.segments[..] { Some(ident) } else { None }
306306
}
307307

308308
pub fn name_or_empty(&self) -> Symbol {

compiler/rustc_ast/src/mut_visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,10 @@ pub fn walk_flat_map_stmt<T: MutVisitor>(
18131813
.into_iter()
18141814
.map(|kind| Stmt { id, kind, span })
18151815
.collect();
1816-
match stmts.len() {
1817-
0 => {}
1818-
1 => vis.visit_span(&mut stmts[0].span),
1819-
2.. => panic!(
1816+
match &mut stmts[..] {
1817+
[] => {}
1818+
[stmt] => vis.visit_span(&mut stmt.span),
1819+
_ => panic!(
18201820
"cloning statement `NodeId`s is prohibited by default, \
18211821
the visitor should implement custom statement visiting"
18221822
),

compiler/rustc_ast/src/util/comments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
3939
let mut i = 0;
4040
let mut j = lines.len();
4141
// first line of all-stars should be omitted
42-
if !lines.is_empty() && lines[0].chars().all(|c| c == '*') {
42+
if lines.first().is_some_and(|line| line.chars().all(|c| c == '*')) {
4343
i += 1;
4444
}
4545

@@ -97,7 +97,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
9797
return None;
9898
}
9999
}
100-
if lines.is_empty() { None } else { Some(lines[0][..i].into()) }
100+
Some(lines.first()?[..i].to_string())
101101
}
102102

103103
let data_s = data.as_str();

0 commit comments

Comments
 (0)