@@ -2,7 +2,8 @@ use super::errors::{
2
2
AsyncCoroutinesNotSupported , AsyncNonMoveClosureNotSupported , AwaitOnlyInAsyncFnAndBlocks ,
3
3
BaseExpressionDoubleDot , ClosureCannotBeStatic , CoroutineTooManyParameters ,
4
4
FunctionalRecordUpdateDestructuringAssignment , InclusiveRangeWithNoEnd , MatchArmWithNoBody ,
5
- NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure , UnderscoreExprLhsAssign ,
5
+ NeverPatternWithBody , NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure ,
6
+ UnderscoreExprLhsAssign ,
6
7
} ;
7
8
use super :: ResolverAstLoweringExt ;
8
9
use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
@@ -567,20 +568,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
567
568
let hir_id = self . next_id ( ) ;
568
569
let span = self . lower_span ( arm. span ) ;
569
570
self . lower_attrs ( hir_id, & arm. attrs ) ;
570
- let body = if let Some ( body) = & arm. body {
571
- // FIXME(never_patterns): Disallow never pattern with a body or guard
571
+ let is_never_pattern = pat. is_never_pattern ( ) ;
572
+ let body = if let Some ( body) = & arm. body
573
+ && !is_never_pattern
574
+ {
572
575
self . lower_expr ( body)
573
576
} else {
574
- if !pat. is_never_pattern ( ) {
575
- self . tcx
576
- . sess
577
- . emit_err ( MatchArmWithNoBody { span, suggestion : span. shrink_to_hi ( ) } ) ;
577
+ // Either `body.is_none()` or `is_never_pattern` here.
578
+ if !is_never_pattern {
579
+ let suggestion = span. shrink_to_hi ( ) ;
580
+ self . tcx . sess . emit_err ( MatchArmWithNoBody { span, suggestion } ) ;
581
+ } else if let Some ( body) = & arm. body {
582
+ self . tcx . sess . emit_err ( NeverPatternWithBody { span : body. span } ) ;
583
+ guard = None ;
578
584
} else if let Some ( g) = & arm. guard {
579
585
self . tcx . sess . emit_err ( NeverPatternWithGuard { span : g. span } ) ;
580
586
guard = None ;
581
587
}
582
588
583
- // An arm without a body, meant for never patterns.
584
589
// We add a fake `loop {}` arm body so that it typecks to `!`.
585
590
// FIXME(never_patterns): Desugar into a call to `unreachable_unchecked`.
586
591
let block = self . arena . alloc ( hir:: Block {
0 commit comments