1
Fork 0

Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors

Use more slice patterns inside the compiler

Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'.

r? ghost
This commit is contained in:
Matthias Krüger 2024-08-11 07:51:51 +02:00 committed by GitHub
commit 32e0fe129d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 191 additions and 221 deletions

View file

@ -676,7 +676,7 @@ impl<'a> Parser<'a> {
match &expr.kind {
ExprKind::Path(None, ast::Path { segments, .. })
if segments.len() == 1 =>
if let [segment] = segments.as_slice() =>
{
if self.token == token::Colon
&& self.look_ahead(1, |token| {
@ -693,8 +693,8 @@ impl<'a> Parser<'a> {
let snapshot = self.create_snapshot_for_diagnostic();
let label = Label {
ident: Ident::from_str_and_span(
&format!("'{}", segments[0].ident),
segments[0].ident.span,
&format!("'{}", segment.ident),
segment.ident.span,
),
};
match self.parse_expr_labeled(label, false) {