@@ -585,7 +585,9 @@ impl Pat {
585585 }
586586 // A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
587587 // 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+ }
589591 // A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
590592 // assuming `T0` to `Tn` are all syntactically valid as types.
591593 PatKind :: Tuple ( pats) => {
@@ -1187,8 +1189,8 @@ impl Expr {
11871189 /// Does not ensure that the path resolves to a const param, the caller should check this.
11881190 pub fn is_potential_trivial_const_arg ( & self ) -> bool {
11891191 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
11921194 {
11931195 expr
11941196 } else {
@@ -1248,7 +1250,9 @@ impl Expr {
12481250 expr. to_ty ( ) . map ( |ty| TyKind :: Array ( ty, expr_len. clone ( ) ) ) ?
12491251 }
12501252
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+ }
12521256
12531257 ExprKind :: Tup ( exprs) => {
12541258 let tys = exprs. iter ( ) . map ( |expr| expr. to_ty ( ) ) . collect :: < Option < ThinVec < _ > > > ( ) ?;
0 commit comments