Skip to content

Commit 84f3992

Browse files
Add u32 conversion methods for fact indexes
1 parent 103b908 commit 84f3992

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/facts.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ macro_rules! index_type {
2020
}
2121
}
2222

23+
impl From<u32> for $t {
24+
fn from(index: u32) -> $t {
25+
$t { index }
26+
}
27+
}
28+
2329
impl Into<usize> for $t {
2430
fn into(self) -> usize {
2531
self.index as usize
2632
}
2733
}
2834

35+
impl Into<u32> for $t {
36+
fn into(self) -> u32 {
37+
self.index
38+
}
39+
}
40+
2941
impl polonius_engine::Atom for $t {
3042
fn index(self) -> usize {
3143
self.into()

src/test.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn test_facts(all_facts: &AllFacts, algorithms: &[Algorithm]) {
4949
for (naive_point, naive_origins) in &naive.subset_errors {
5050
// Potential location-insensitive errors don't have a meaningful location, and use 0
5151
// as a default when debugging.
52-
match insensitive.subset_errors.get(&0.into()) {
52+
match insensitive.subset_errors.get(&0u32.into()) {
5353
Some(insensitive_origins) => {
5454
for &(origin1, origin2) in naive_origins {
5555
if !insensitive_origins.contains(&(origin1, origin2)) {
@@ -152,8 +152,8 @@ fn test_insensitive_errors() -> Result<(), Box<dyn Error>> {
152152
let insensitive = Output::compute(&all_facts, Algorithm::LocationInsensitive, false);
153153

154154
let mut expected = FxHashMap::default();
155-
expected.insert(Point::from(24), vec![Loan::from(1)]);
156-
expected.insert(Point::from(50), vec![Loan::from(2)]);
155+
expected.insert(Point::from(24u32), vec![Loan::from(1u32)]);
156+
expected.insert(Point::from(50u32), vec![Loan::from(2u32)]);
157157

158158
assert_equal(&insensitive.errors, &expected);
159159
Ok(())
@@ -441,7 +441,7 @@ fn var_live_in_successor_propagates_to_predecessor() {
441441
assert_eq!(variables.len(), 1);
442442
}
443443

444-
assert!(!liveness.get(&0.into()).unwrap().is_empty());
444+
assert!(!liveness.get(&0u32.into()).unwrap().is_empty());
445445
}
446446

447447
#[test]
@@ -475,7 +475,7 @@ fn var_live_in_successor_killed_by_reassignment() {
475475
let liveness = result.var_live_on_entry;
476476
println!("CFG: {:#?}", facts.cfg_edge);
477477

478-
let first_defined: Point = 3.into(); // Mid(B1[0])
478+
let first_defined: Point = 3u32.into(); // Mid(B1[0])
479479

480480
for (&point, variables) in liveness.iter() {
481481
println!(
@@ -486,10 +486,10 @@ fn var_live_in_successor_killed_by_reassignment() {
486486
);
487487
}
488488

489-
let live_at_start = liveness.get(&0.into());
489+
let live_at_start = liveness.get(&0u32.into());
490490

491491
assert_eq!(
492-
liveness.get(&0.into()),
492+
liveness.get(&0u32.into()),
493493
None,
494494
"{:?} were live at start!",
495495
live_at_start.and_then(|var| Some(tables.variables.untern_vec(var))),
@@ -535,7 +535,7 @@ fn var_drop_used_simple() {
535535
println!("result: {:#?}", result);
536536
let liveness = result.var_drop_live_on_entry;
537537
println!("CFG: {:#?}", facts.cfg_edge);
538-
let first_defined: Point = 3.into(); // Mid(B1[0])
538+
let first_defined: Point = 3u32.into(); // Mid(B1[0])
539539

540540
for (&point, variables) in liveness.iter() {
541541
println!(
@@ -546,10 +546,10 @@ fn var_drop_used_simple() {
546546
);
547547
}
548548

549-
let live_at_start = liveness.get(&0.into());
549+
let live_at_start = liveness.get(&0u32.into());
550550

551551
assert_eq!(
552-
liveness.get(&0.into()),
552+
liveness.get(&0u32.into()),
553553
None,
554554
"{:?} were live at start!",
555555
live_at_start.and_then(|var| Some(tables.variables.untern_vec(var))),
@@ -752,10 +752,10 @@ fn errors_in_subset_relations_dataset() {
752752

753753
let expected_subset_error = {
754754
// in this dataset, `'a` is interned as `'1`
755-
let origin_a = Origin::from(1);
755+
let origin_a = Origin::from(1u32);
756756

757757
// `'b` is interned as `'2`
758-
let origin_b = Origin::from(2);
758+
let origin_b = Origin::from(2u32);
759759

760760
// and `'b` should flow into `'a`
761761
(origin_b, origin_a)

0 commit comments

Comments
 (0)