@@ -17,6 +17,7 @@ use tracing::{debug, instrument};
17
17
use crate :: builder:: expr:: category:: { Category , RvalueFunc } ;
18
18
use crate :: builder:: matches:: { DeclareLetBindings , HasMatchGuard } ;
19
19
use crate :: builder:: { BlockAnd , BlockAndExtension , BlockFrame , Builder , NeedsTemporary } ;
20
+ use crate :: errors:: LoopMatchArmWithGuard ;
20
21
21
22
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
22
23
/// Compile `expr`, storing the result into `destination`, which
@@ -268,15 +269,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
268
269
unpack ! ( body_block = this. as_place_builder( body_block, state) ) ;
269
270
let scrutinee_span = this. thir . exprs [ state] . span ;
270
271
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
+ }
280
284
281
285
let built_tree = this. lower_match_tree (
282
286
body_block,
0 commit comments