@@ -141,33 +141,34 @@ impl Rule for NoLabels {
141141 }
142142
143143 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
144- if let AstKind :: LabeledStatement ( labeled_stmt) = node. kind ( )
145- && !self . is_allowed ( & labeled_stmt. body )
146- {
147- let label_span = labeled_stmt. label . span ;
148- ctx. diagnostic ( no_labels_diagnostic ( "Labeled statement is not allowed" , label_span) ) ;
149- }
150-
151- if let AstKind :: BreakStatement ( break_stmt) = node. kind ( ) {
152- let Some ( label) = & break_stmt. label else { return } ;
153-
154- if !self . is_allowed_in_break_or_continue ( label, node. id ( ) , ctx) {
144+ match node. kind ( ) {
145+ AstKind :: LabeledStatement ( labeled_stmt) if !self . is_allowed ( & labeled_stmt. body ) => {
155146 ctx. diagnostic ( no_labels_diagnostic (
156- "Label in break statement is not allowed" ,
157- label. span ,
147+ "Labeled statement is not allowed" ,
148+ labeled_stmt . label . span ,
158149 ) ) ;
159150 }
160- }
161-
162- if let AstKind :: ContinueStatement ( cont_stmt) = node. kind ( ) {
163- let Some ( label) = & cont_stmt. label else { return } ;
164-
165- if !self . is_allowed_in_break_or_continue ( label, node. id ( ) , ctx) {
166- ctx. diagnostic ( no_labels_diagnostic (
167- "Label in continue statement is not allowed" ,
168- label. span ,
169- ) ) ;
151+ AstKind :: BreakStatement ( break_stmt) => {
152+ if let Some ( label) = & break_stmt. label
153+ && !self . is_allowed_in_break_or_continue ( label, node. id ( ) , ctx)
154+ {
155+ ctx. diagnostic ( no_labels_diagnostic (
156+ "Label in break statement is not allowed" ,
157+ label. span ,
158+ ) ) ;
159+ }
160+ }
161+ AstKind :: ContinueStatement ( cont_stmt) => {
162+ if let Some ( label) = & cont_stmt. label
163+ && !self . is_allowed_in_break_or_continue ( label, node. id ( ) , ctx)
164+ {
165+ ctx. diagnostic ( no_labels_diagnostic (
166+ "Label in continue statement is not allowed" ,
167+ label. span ,
168+ ) ) ;
169+ }
170170 }
171+ _ => { }
171172 }
172173 }
173174}
0 commit comments