Skip to content

Commit

Permalink
chore: simplify dropping last elem
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Mar 8, 2024
1 parent 568650f commit fc530d9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/diagnostics/stmt_fallthrough.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use redscript::ast::Expr;

use super::{Diagnostic, ExprDiagnosticPass, FunctionMetadata};
Expand All @@ -20,7 +21,7 @@ struct StatementFallthroughVisitor<'a> {
impl StatementFallthroughVisitor<'_> {
fn on_expr(&mut self, expr: &TypedExpr) {
if let Expr::Switch(_, cases, _, _) = expr {
for case in cases.iter().take(cases.len().max(1) - 1) {
for case in cases.iter().dropping_back(1) {
if !matches!(case.body.exprs.last(), None | Some(Expr::Break(_) | Expr::Return(_, _))) {
self.results.push(Diagnostic::StatementFallthrough(case.matcher.span()));
}
Expand Down

0 comments on commit fc530d9

Please sign in to comment.