@@ -1499,18 +1499,19 @@ fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: L
14991499 check_transparent ( tcx, sp, def) ;
15001500}
15011501
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
15031503fn detect_discriminant_duplicate < ' tcx > (
15041504 tcx : TyCtxt < ' tcx > ,
15051505 mut discrs : Vec < ( VariantIdx , Discr < ' tcx > ) > ,
15061506 vs : & ' tcx [ hir:: Variant < ' tcx > ] ,
15071507 self_span : Span ,
15081508) {
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`
15101511 let report = |dis : Discr < ' tcx > ,
15111512 idx : usize ,
15121513 err : & mut DiagnosticBuilder < ' _ , ErrorGuaranteed > | {
1513- let var = & vs[ idx] ;
1514+ let var = & vs[ idx] ; // HIR for the duplicate discriminant
15141515 let ( span, display_discr) = match var. disr_expr {
15151516 Some ( ref expr) => {
15161517 // In the case the discriminant is both a duplicate and overflowed, let the user know
@@ -1533,8 +1534,8 @@ fn detect_discriminant_duplicate<'tcx>(
15331534 vs[ ..idx] . iter ( ) . rev ( ) . enumerate ( ) . find ( |v| v. 1 . disr_expr . is_some ( ) )
15341535 {
15351536 let ve_ident = var. ident ;
1536- let sp = if n > 1 { "variants" } else { "variant" } ;
15371537 let n = n + 1 ;
1538+ let sp = if n > 1 { "variants" } else { "variant" } ;
15381539
15391540 err. span_label (
15401541 * span,
@@ -1549,7 +1550,7 @@ fn detect_discriminant_duplicate<'tcx>(
15491550 err. span_label ( span, format ! ( "{display_discr} assigned here" ) ) ;
15501551 } ;
15511552
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.
15531554 // When a duplicate is detected, we instatiate an error and point to both
15541555 // initial and duplicate value. The duplicate discriminant is then discarded by swapping
15551556 // it with the last element and decrementing the `vec.len` (which is why we have to evaluate
0 commit comments