@@ -10,7 +10,7 @@ use rustc_span::{sym, symbol, BytePos, LocalExpnId, Span, Symbol, SyntaxContext}
10
10
use unicode_width:: UnicodeWidthStr ;
11
11
12
12
use crate :: comment:: { filter_normal_code, CharClasses , FullCodeCharKind , LineClasses } ;
13
- use crate :: config:: { Config , Version } ;
13
+ use crate :: config:: { Config , TrailingSemicolon , Version } ;
14
14
use crate :: rewrite:: RewriteContext ;
15
15
use crate :: shape:: { Indent , Shape } ;
16
16
@@ -273,15 +273,18 @@ pub(crate) fn contains_skip(attrs: &[Attribute]) -> bool {
273
273
#[ inline]
274
274
pub ( crate ) fn semicolon_for_expr ( context : & RewriteContext < ' _ > , expr : & ast:: Expr ) -> bool {
275
275
// Never try to insert semicolons on expressions when we're inside
276
- // a macro definition - this can prevent the macro from compiling
276
+ // a macro definition - this can prevent the macro from compiling
277
277
// when used in expression position
278
278
if context. is_macro_def {
279
279
return false ;
280
280
}
281
281
282
282
match expr. kind {
283
283
ast:: ExprKind :: Ret ( ..) | ast:: ExprKind :: Continue ( ..) | ast:: ExprKind :: Break ( ..) => {
284
- context. config . trailing_semicolon ( )
284
+ match context. config . trailing_semicolon ( ) {
285
+ TrailingSemicolon :: Always => true ,
286
+ TrailingSemicolon :: Never | TrailingSemicolon :: Preserve => false ,
287
+ }
285
288
}
286
289
_ => false ,
287
290
}
@@ -301,7 +304,14 @@ pub(crate) fn semicolon_for_stmt(
301
304
ast:: ExprKind :: Break ( ..) | ast:: ExprKind :: Continue ( ..) | ast:: ExprKind :: Ret ( ..) => {
302
305
// The only time we can skip the semi-colon is if the config option is set to false
303
306
// **and** this is the last expr (even though any following exprs are unreachable)
304
- context. config . trailing_semicolon ( ) || !is_last_expr
307
+ if !is_last_expr {
308
+ true
309
+ } else {
310
+ match context. config . trailing_semicolon ( ) {
311
+ TrailingSemicolon :: Always | TrailingSemicolon :: Preserve => true ,
312
+ TrailingSemicolon :: Never => false ,
313
+ }
314
+ }
305
315
}
306
316
_ => true ,
307
317
} ,
0 commit comments