@@ -2,7 +2,8 @@ use super::errors::{
22 AsyncCoroutinesNotSupported , AsyncNonMoveClosureNotSupported , AwaitOnlyInAsyncFnAndBlocks ,
33 BaseExpressionDoubleDot , ClosureCannotBeStatic , CoroutineTooManyParameters ,
44 FunctionalRecordUpdateDestructuringAssignment , InclusiveRangeWithNoEnd , MatchArmWithNoBody ,
5- NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure , UnderscoreExprLhsAssign ,
5+ NeverPatternWithBody , NeverPatternWithGuard , NotSupportedForLifetimeBinderAsyncClosure ,
6+ UnderscoreExprLhsAssign ,
67} ;
78use super :: ResolverAstLoweringExt ;
89use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
@@ -567,20 +568,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
567568 let hir_id = self . next_id ( ) ;
568569 let span = self . lower_span ( arm. span ) ;
569570 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+ {
572575 self . lower_expr ( body)
573576 } 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 ;
578584 } else if let Some ( g) = & arm. guard {
579585 self . tcx . sess . emit_err ( NeverPatternWithGuard { span : g. span } ) ;
580586 guard = None ;
581587 }
582588
583- // An arm without a body, meant for never patterns.
584589 // We add a fake `loop {}` arm body so that it typecks to `!`.
585590 // FIXME(never_patterns): Desugar into a call to `unreachable_unchecked`.
586591 let block = self . arena . alloc ( hir:: Block {
0 commit comments