@@ -190,6 +190,7 @@ macro_rules! push_rules {
190
190
191
191
if let Some ( __JudgmentStruct( $( $input_names) ,* ) ) = Some ( $input_value) {
192
192
$crate:: push_rules!( @match
193
+ $conclusion_name
193
194
inputs( $( $input_names) * )
194
195
patterns( $( $patterns) * , )
195
196
args( @body
@@ -232,43 +233,43 @@ macro_rules! push_rules {
232
233
// Matching phase: peel off the patterns one by one and match them against the values
233
234
// extracted from the input. For anything that is not an identity pattern, invoke `downcast`.
234
235
235
- ( @match inputs( ) patterns( ) args( @body ( $judgment_name: ident; $n: literal; $v: expr; $output: expr) ; $inputs: tt; $( $m: tt) * ) ) => {
236
+ ( @match $conclusion_name : ident inputs( ) patterns( ) args( @body ( $judgment_name: ident; $n: literal; $v: expr; $output: expr) ; $inputs: tt; $( $m: tt) * ) ) => {
236
237
tracing:: trace_span!( "matched rule" , rule = $n, judgment = stringify!( $judgment_name) ) . in_scope( || {
237
238
let mut step_index = 0 ;
238
239
$crate:: push_rules!( @body ( $judgment_name, $n, $v, $output) ; $inputs; step_index; $( $m) * ) ;
239
240
} ) ;
240
241
} ;
241
242
242
- ( @match inputs( ) patterns( , ) args $args: tt) => {
243
- $crate:: push_rules!( @match inputs( ) patterns( ) args $args) ;
243
+ ( @match $conclusion_name : ident inputs( ) patterns( , ) args $args: tt) => {
244
+ $crate:: push_rules!( @match $conclusion_name inputs( ) patterns( ) args $args) ;
244
245
} ;
245
246
246
- ( @match inputs( ) patterns $patterns : tt args $args: tt) => {
247
- compile_error!( "more patterns in rule than arguments on fn" )
247
+ ( @match $conclusion_name : ident inputs( ) patterns ( $pattern0 : tt $ ( $pattern1 : tt ) * ) args $args: tt) => {
248
+ $crate :: respan! ( $pattern0 ( compile_error!( "more patterns in rule than arguments on fn" ) ) )
248
249
} ;
249
250
250
- ( @match inputs $inputs: tt patterns( ) args $args: tt) => {
251
- compile_error!( "fewer patterns in rule than arguments on fn" )
251
+ ( @match $conclusion_name : ident inputs $inputs: tt patterns( ) args $args: tt) => {
252
+ $crate :: respan! ( $conclusion_name ( compile_error!( "fewer patterns in rule than arguments on fn" ) ) )
252
253
} ;
253
254
254
- ( @match inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: ident : $ty0: ty, $( $pats: tt) * ) args $args: tt) => {
255
+ ( @match $conclusion_name : ident inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: ident : $ty0: ty, $( $pats: tt) * ) args $args: tt) => {
255
256
{
256
257
if let Some ( $pat0) = $crate:: Downcast :: downcast:: <$ty0>( $in0) {
257
- $crate:: push_rules!( @match inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
258
+ $crate:: push_rules!( @match $conclusion_name inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
258
259
}
259
260
}
260
261
} ;
261
262
262
- ( @match inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: ident, $( $pats: tt) * ) args $args: tt) => {
263
+ ( @match $conclusion_name : ident inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: ident, $( $pats: tt) * ) args $args: tt) => {
263
264
{
264
265
let $pat0 = Clone :: clone( $in0) ;
265
- $crate:: push_rules!( @match inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
266
+ $crate:: push_rules!( @match $conclusion_name inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
266
267
}
267
268
} ;
268
269
269
- ( @match inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: pat, $( $pats: tt) * ) args $args: tt) => {
270
+ ( @match $conclusion_name : ident inputs( $in0: ident $( $inputs: tt) * ) patterns( $pat0: pat, $( $pats: tt) * ) args $args: tt) => {
270
271
if let Some ( $pat0) = $crate:: Downcast :: downcast( & $in0) {
271
- $crate:: push_rules!( @match inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
272
+ $crate:: push_rules!( @match $conclusion_name inputs( $( $inputs) * ) patterns( $( $pats) * ) args $args) ;
272
273
}
273
274
} ;
274
275
@@ -288,7 +289,7 @@ macro_rules! push_rules {
288
289
$step_index += 1 ;
289
290
$crate:: push_rules!( @body $args; $inputs; $step_index; $( $m) * ) ;
290
291
} else {
291
- $crate:: push_rules!( @record_failure $inputs; $step_index; $crate:: judgment:: RuleFailureCause :: IfFalse {
292
+ $crate:: push_rules!( @record_failure $inputs; $step_index, $c ; $crate:: judgment:: RuleFailureCause :: IfFalse {
292
293
expr: stringify!( $c) . to_string( ) ,
293
294
} ) ;
294
295
}
@@ -306,7 +307,7 @@ macro_rules! push_rules {
306
307
$step_index += 1 ;
307
308
$crate:: push_rules!( @body $args; $inputs; $step_index; $( $m) * ) ;
308
309
} else {
309
- $crate:: push_rules!( @record_failure $inputs; $step_index; $crate:: judgment:: RuleFailureCause :: IfLetDidNotMatch {
310
+ $crate:: push_rules!( @record_failure $inputs; $step_index, $e ; $crate:: judgment:: RuleFailureCause :: IfLetDidNotMatch {
310
311
pattern: stringify!( $p) . to_string( ) ,
311
312
value: format!( "{:?}" , value) ,
312
313
} ) ;
@@ -324,7 +325,7 @@ macro_rules! push_rules {
324
325
}
325
326
}
326
327
Err ( e) => {
327
- $crate:: push_rules!( @record_failure $inputs; $step_index; e) ;
328
+ $crate:: push_rules!( @record_failure $inputs; $step_index, $i ; e) ;
328
329
}
329
330
}
330
331
} ;
@@ -348,23 +349,26 @@ macro_rules! push_rules {
348
349
349
350
//
350
351
351
- ( @record_failure ( $failed_rules: expr, $match_index: expr, $inputs: tt, $rule_name: literal) ; $step_index: ident; $cause: expr) => {
352
+ ( @record_failure ( $failed_rules: expr, $match_index: expr, $inputs: tt, $rule_name: literal) ; $step_index: ident, $step_expr: expr; $cause: expr) => {
353
+ let file = $crate:: respan!( $step_expr ( file!( ) ) ) ;
354
+ let line = $crate:: respan!( $step_expr ( line!( ) ) ) ;
355
+ let column = $crate:: respan!( $step_expr ( column!( ) ) ) ;
352
356
if $step_index >= $match_index {
353
357
tracing:: debug!(
354
358
"rule {rn} failed at step {s} because {cause} ({file}:{line}:{column})" ,
355
359
rn = $rule_name,
356
360
s = $step_index,
357
361
cause = $cause,
358
- file = file! ( ) ,
359
- line = line! ( ) ,
360
- column = column! ( ) ,
362
+ file = file,
363
+ line = line,
364
+ column = column,
361
365
) ;
362
366
$failed_rules. insert(
363
367
$crate:: judgment:: FailedRule {
364
368
rule_name_index: Some ( ( $rule_name. to_string( ) , $step_index) ) ,
365
- file: file! ( ) . to_string( ) ,
366
- line: line! ( ) ,
367
- column: column! ( ) ,
369
+ file: file. to_string( ) ,
370
+ line: line,
371
+ column: column,
368
372
cause: $cause,
369
373
}
370
374
) ;
@@ -374,9 +378,9 @@ macro_rules! push_rules {
374
378
rn = $rule_name,
375
379
s = $step_index,
376
380
cause = $cause,
377
- file = file! ( ) ,
378
- line = line! ( ) ,
379
- column = column! ( ) ,
381
+ file = file,
382
+ line = line,
383
+ column = column,
380
384
) ;
381
385
}
382
386
}
0 commit comments