@@ -1499,18 +1499,19 @@ fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: L
1499
1499
check_transparent ( tcx, sp, def) ;
1500
1500
}
1501
1501
1502
- /// Part of enum check, errors if two or more discriminants are equal
1502
+ /// Part of enum check. Given the discriminants of an enum , errors if two or more discriminants are equal
1503
1503
fn detect_discriminant_duplicate < ' tcx > (
1504
1504
tcx : TyCtxt < ' tcx > ,
1505
1505
mut discrs : Vec < ( VariantIdx , Discr < ' tcx > ) > ,
1506
1506
vs : & ' tcx [ hir:: Variant < ' tcx > ] ,
1507
1507
self_span : Span ,
1508
1508
) {
1509
- // Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate
1509
+ // Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate.
1510
+ // Here `idx` refers to the order of which the discriminant appears, and its index in `vs`
1510
1511
let report = |dis : Discr < ' tcx > ,
1511
1512
idx : usize ,
1512
1513
err : & mut DiagnosticBuilder < ' _ , ErrorGuaranteed > | {
1513
- let var = & vs[ idx] ;
1514
+ let var = & vs[ idx] ; // HIR for the duplicate discriminant
1514
1515
let ( span, display_discr) = match var. disr_expr {
1515
1516
Some ( ref expr) => {
1516
1517
// In the case the discriminant is both a duplicate and overflowed, let the user know
@@ -1533,8 +1534,8 @@ fn detect_discriminant_duplicate<'tcx>(
1533
1534
vs[ ..idx] . iter ( ) . rev ( ) . enumerate ( ) . find ( |v| v. 1 . disr_expr . is_some ( ) )
1534
1535
{
1535
1536
let ve_ident = var. ident ;
1536
- let sp = if n > 1 { "variants" } else { "variant" } ;
1537
1537
let n = n + 1 ;
1538
+ let sp = if n > 1 { "variants" } else { "variant" } ;
1538
1539
1539
1540
err. span_label (
1540
1541
* span,
@@ -1549,7 +1550,7 @@ fn detect_discriminant_duplicate<'tcx>(
1549
1550
err. span_label ( span, format ! ( "{display_discr} assigned here" ) ) ;
1550
1551
} ;
1551
1552
1552
- // Here we are loop through the discriminants, comparing each discriminant to another.
1553
+ // Here we loop through the discriminants, comparing each discriminant to another.
1553
1554
// When a duplicate is detected, we instatiate an error and point to both
1554
1555
// initial and duplicate value. The duplicate discriminant is then discarded by swapping
1555
1556
// it with the last element and decrementing the `vec.len` (which is why we have to evaluate
0 commit comments