Skip to content

Commit b3d2baf

Browse files
committed
Give correct suggestions
1 parent e3357d9 commit b3d2baf

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
707707
let mut ranges: Vec<_> =
708708
ranges.into_iter().filter_map(|r| to_inc_range_pair(cx.tcx, &r)).collect();
709709
while let Some((lo2, hi2)) = ranges.pop() {
710-
eprintln!("{:?} {:?}", (lo2, hi2), (lo1, hi1));
710+
// eprintln!("{:?} {:?}", (lo2, hi2), (lo1, hi1));
711711
if lo1 <= lo2 && hi1 >= hi2 {
712712
if _deb { eprintln!("case 1"); }
713713
ctor_was_useful = true;
@@ -793,6 +793,17 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
793793
missing_ctors.extend(cur);
794794
}
795795

796+
// if _ranged {
797+
// missing_ctors = missing_ctors.into_iter().map(|ctor| {
798+
// match ctor {
799+
// ConstantRange(lo, hi, RangeEnd::Included) if lo == hi => {
800+
// ConstantValue(lo)
801+
// }
802+
// _ => ctor,
803+
// }
804+
// }).collect();
805+
// }
806+
796807
// let missing_ctors: Vec<Constructor> = all_ctors.iter().filter(|c| {
797808
// !used_ctors.contains(*c)
798809
// }).cloned().collect();
@@ -916,11 +927,33 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
916927
}).collect()
917928
} else {
918929
if _deb { eprintln!("ABC 5"); }
919-
pats.into_iter().flat_map(|witness| {
920-
missing_ctors.iter().map(move |ctor| {
921-
witness.clone().push_wild_constructor(cx, ctor, pcx.ty)
922-
})
923-
}).collect()
930+
if _ranged {
931+
missing_ctors.into_iter().map(|ctor| {
932+
match ctor {
933+
ConstantRange(lo, hi, _) if lo == hi => {
934+
Witness(vec![Pattern {
935+
ty: pcx.ty,
936+
span: DUMMY_SP,
937+
kind: box PatternKind::Constant { value: lo },
938+
}])
939+
}
940+
ConstantRange(lo, hi, end) => {
941+
Witness(vec![Pattern {
942+
ty: pcx.ty,
943+
span: DUMMY_SP,
944+
kind: box PatternKind::Range { lo, hi, end },
945+
}])
946+
},
947+
_ => bug!("this shouldn't be happening"),
948+
}
949+
}).collect()
950+
} else {
951+
pats.into_iter().flat_map(|witness| {
952+
missing_ctors.iter().map(move |ctor| {
953+
witness.clone().push_wild_constructor(cx, ctor, pcx.ty)
954+
})
955+
}).collect()
956+
}
924957
};
925958
UsefulWithWitness(new_witnesses)
926959
}

0 commit comments

Comments
 (0)