Skip to content

Commit cf7fe00

Browse files
committed
Make RegionVid use newtype_index!
Closes #45843
1 parent 7f2c82f commit cf7fe00

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

src/librustc/infer/lexical_region_resolve/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
171171
for (r, vid) in seeds {
172172
// While all things transitively reachable in the graph
173173
// from the variable (`'0` in the example above).
174-
let seed_index = NodeIndex(vid.index as usize);
174+
let seed_index = NodeIndex(vid.index() as usize);
175175
for succ_index in graph.depth_traverse(seed_index, OUTGOING) {
176176
let succ_index = succ_index.0;
177177

@@ -512,16 +512,16 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
512512
match *constraint {
513513
Constraint::VarSubVar(a_id, b_id) => {
514514
graph.add_edge(
515-
NodeIndex(a_id.index as usize),
516-
NodeIndex(b_id.index as usize),
515+
NodeIndex(a_id.index() as usize),
516+
NodeIndex(b_id.index() as usize),
517517
*constraint,
518518
);
519519
}
520520
Constraint::RegSubVar(_, b_id) => {
521-
graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint);
521+
graph.add_edge(dummy_source, NodeIndex(b_id.index() as usize), *constraint);
522522
}
523523
Constraint::VarSubReg(a_id, _) => {
524-
graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint);
524+
graph.add_edge(NodeIndex(a_id.index() as usize), dummy_sink, *constraint);
525525
}
526526
Constraint::RegSubReg(..) => {
527527
// this would be an edge from `dummy_source` to
@@ -630,9 +630,9 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
630630
let node_idx = state.stack.pop().unwrap();
631631

632632
// check whether we've visited this node on some previous walk
633-
if dup_vec[node_idx.index as usize] == u32::MAX {
634-
dup_vec[node_idx.index as usize] = orig_node_idx.index;
635-
} else if dup_vec[node_idx.index as usize] != orig_node_idx.index {
633+
if dup_vec[node_idx.index() as usize] == u32::MAX {
634+
dup_vec[node_idx.index() as usize] = orig_node_idx.index() as u32;
635+
} else if dup_vec[node_idx.index() as usize] != orig_node_idx.index() as u32 {
636636
state.dup_found = true;
637637
}
638638

@@ -659,7 +659,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
659659
) {
660660
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);
661661

662-
let source_node_index = NodeIndex(source_vid.index as usize);
662+
let source_node_index = NodeIndex(source_vid.index() as usize);
663663
for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
664664
match edge.data {
665665
Constraint::VarSubVar(from_vid, to_vid) => {

src/librustc/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use self::CombineMapType::*;
1616
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
1717
use super::unify_key;
1818

19-
use rustc_data_structures::indexed_vec::IndexVec;
19+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2020
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2121
use rustc_data_structures::unify::{self, UnificationTable};
2222
use ty::{self, Ty, TyCtxt};
@@ -363,7 +363,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
363363
}
364364
AddVar(vid) => {
365365
self.var_origins.pop().unwrap();
366-
assert_eq!(self.var_origins.len(), vid.index as usize);
366+
assert_eq!(self.var_origins.len(), vid.index() as usize);
367367
}
368368
AddConstraint(ref constraint) => {
369369
self.data.constraints.remove(constraint);

src/librustc/infer/unify_key.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct RegionVidKey {
3333

3434
impl Combine for RegionVidKey {
3535
fn combine(&self, other: &RegionVidKey) -> RegionVidKey {
36-
let min_vid = if self.min_vid.index < other.min_vid.index {
36+
let min_vid = if self.min_vid.index() < other.min_vid.index() {
3737
self.min_vid
3838
} else {
3939
other.min_vid
@@ -45,8 +45,8 @@ impl Combine for RegionVidKey {
4545

4646
impl UnifyKey for ty::RegionVid {
4747
type Value = RegionVidKey;
48-
fn index(&self) -> u32 { self.index }
49-
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid { index: i } }
48+
fn index(&self) -> u32 { self.0 }
49+
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid(i) }
5050
fn tag(_: Option<ty::RegionVid>) -> &'static str { "RegionVid" }
5151
}
5252

src/librustc/ty/sty.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -894,22 +894,11 @@ pub struct FloatVid {
894894
pub index: u32,
895895
}
896896

897-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Copy)]
898-
pub struct RegionVid {
899-
pub index: u32,
900-
}
901-
902-
// FIXME: We could convert this to use `newtype_index!`
903-
impl Idx for RegionVid {
904-
fn new(value: usize) -> Self {
905-
assert!(value < ::std::u32::MAX as usize);
906-
RegionVid { index: value as u32 }
907-
}
908-
909-
fn index(self) -> usize {
910-
self.index as usize
911-
}
912-
}
897+
newtype_index!(RegionVid
898+
{
899+
pub idx
900+
DEBUG_FORMAT = custom,
901+
});
913902

914903
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
915904
pub struct SkolemizedRegionVid {

src/librustc/util/ppaux.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ define_print! {
726726
}
727727
}
728728
ty::ReVar(region_vid) if cx.identify_regions => {
729-
write!(f, "'{}rv", region_vid.index)
729+
write!(f, "'{}rv", region_vid.index())
730730
}
731731
ty::ReScope(_) |
732732
ty::ReVar(_) |
@@ -850,7 +850,7 @@ impl fmt::Debug for ty::FloatVid {
850850

851851
impl fmt::Debug for ty::RegionVid {
852852
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
853-
write!(f, "'_#{}r", self.index)
853+
write!(f, "'_#{}r", self.index())
854854
}
855855
}
856856

0 commit comments

Comments
 (0)