@@ -17,6 +17,7 @@ use tracing::{debug, instrument};
1717use crate :: builder:: expr:: category:: { Category , RvalueFunc } ;
1818use crate :: builder:: matches:: { DeclareLetBindings , HasMatchGuard } ;
1919use crate :: builder:: { BlockAnd , BlockAndExtension , BlockFrame , Builder , NeedsTemporary } ;
20+ use crate :: errors:: LoopMatchArmWithGuard ;
2021
2122impl < ' a , ' tcx > Builder < ' a , ' tcx > {
2223 /// Compile `expr`, storing the result into `destination`, which
@@ -268,15 +269,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
268269 unpack ! ( body_block = this. as_place_builder( body_block, state) ) ;
269270 let scrutinee_span = this. thir . exprs [ state] . span ;
270271 let match_start_span = scrutinee_span; // span.shrink_to_lo().to(scrutinee_span); FIXME
271- let patterns = arms
272- . iter ( )
273- . map ( |& arm_id| {
274- // FIXME nice error for guards (which are not allowed)
275- let arm = & this. thir [ arm_id] ;
276- assert ! ( arm. guard. is_none( ) ) ;
277- ( & * arm. pattern , HasMatchGuard :: No )
278- } )
279- . collect ( ) ;
272+
273+ let mut patterns = Vec :: with_capacity ( arms. len ( ) ) ;
274+ for & arm_id in arms. iter ( ) {
275+ let arm = & this. thir [ arm_id] ;
276+
277+ if let Some ( guard) = arm. guard {
278+ let span = this. thir . exprs [ guard] . span ;
279+ this. tcx . dcx ( ) . emit_fatal ( LoopMatchArmWithGuard { span } )
280+ }
281+
282+ patterns. push ( ( & * arm. pattern , HasMatchGuard :: No ) ) ;
283+ }
280284
281285 let built_tree = this. lower_match_tree (
282286 body_block,
0 commit comments