@@ -585,7 +585,9 @@ impl Pat {
585
585
}
586
586
// A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
587
587
// when `P` can be reparsed as a type `T`.
588
- PatKind :: Slice ( pats) if pats. len ( ) == 1 => pats[ 0 ] . to_ty ( ) . map ( TyKind :: Slice ) ?,
588
+ PatKind :: Slice ( pats) if let [ pat] = pats. as_slice ( ) => {
589
+ pat. to_ty ( ) . map ( TyKind :: Slice ) ?
590
+ }
589
591
// A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
590
592
// assuming `T0` to `Tn` are all syntactically valid as types.
591
593
PatKind :: Tuple ( pats) => {
@@ -1187,8 +1189,8 @@ impl Expr {
1187
1189
/// Does not ensure that the path resolves to a const param, the caller should check this.
1188
1190
pub fn is_potential_trivial_const_arg ( & self ) -> bool {
1189
1191
let this = if let ExprKind :: Block ( block, None ) = & self . kind
1190
- && block. stmts . len ( ) == 1
1191
- && let StmtKind :: Expr ( expr) = & block . stmts [ 0 ] . kind
1192
+ && let [ stmt ] = block. stmts . as_slice ( )
1193
+ && let StmtKind :: Expr ( expr) = & stmt . kind
1192
1194
{
1193
1195
expr
1194
1196
} else {
@@ -1248,7 +1250,9 @@ impl Expr {
1248
1250
expr. to_ty ( ) . map ( |ty| TyKind :: Array ( ty, expr_len. clone ( ) ) ) ?
1249
1251
}
1250
1252
1251
- ExprKind :: Array ( exprs) if exprs. len ( ) == 1 => exprs[ 0 ] . to_ty ( ) . map ( TyKind :: Slice ) ?,
1253
+ ExprKind :: Array ( exprs) if let [ expr] = exprs. as_slice ( ) => {
1254
+ expr. to_ty ( ) . map ( TyKind :: Slice ) ?
1255
+ }
1252
1256
1253
1257
ExprKind :: Tup ( exprs) => {
1254
1258
let tys = exprs. iter ( ) . map ( |expr| expr. to_ty ( ) ) . collect :: < Option < ThinVec < _ > > > ( ) ?;
0 commit comments