Skip to content

Commit bd0bc17

Browse files
committed
librustc: Remove newtype enums from librustc
1 parent 3d76a23 commit bd0bc17

File tree

8 files changed

+41
-37
lines changed

8 files changed

+41
-37
lines changed

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ use syntax::{visit, ast_util};
137137
// if it detects an outstanding loan (that is, the addr is taken).
138138
pub type last_use_map = HashMap<node_id, @mut ~[node_id]>;
139139

140-
enum Variable = uint;
141-
enum LiveNode = uint;
140+
struct Variable(uint);
141+
struct LiveNode(uint);
142142

143143
impl cmp::Eq for Variable {
144144
pure fn eq(&self, other: &Variable) -> bool { *(*self) == *(*other) }

src/librustc/middle/ty.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,18 +582,20 @@ pub enum param_bound {
582582
}
583583

584584
#[deriving_eq]
585-
pub enum TyVid = uint;
585+
pub struct TyVid(uint);
586586

587587
#[deriving_eq]
588-
pub enum IntVid = uint;
588+
pub struct IntVid(uint);
589589

590590
#[deriving_eq]
591-
pub enum FloatVid = uint;
591+
pub struct FloatVid(uint);
592592

593593
#[deriving_eq]
594594
#[auto_encode]
595595
#[auto_decode]
596-
pub enum RegionVid = uint;
596+
pub struct RegionVid {
597+
id: uint
598+
}
597599

598600
#[deriving_eq]
599601
pub enum InferTy {
@@ -687,11 +689,11 @@ impl ToStr for FloatVid {
687689
}
688690

689691
impl Vid for RegionVid {
690-
pure fn to_uint(&self) -> uint { **self }
692+
pure fn to_uint(&self) -> uint { self.id }
691693
}
692694

693695
impl ToStr for RegionVid {
694-
pure fn to_str(&self) -> ~str { fmt!("%?", self) }
696+
pure fn to_str(&self) -> ~str { fmt!("%?", self.id) }
695697
}
696698

697699
impl ToStr for FnSig {

src/librustc/middle/typeck/infer/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use syntax::ast;
8484
// Note: Coerce is not actually a combiner, in that it does not
8585
// conform to the same interface, though it performs a similar
8686
// function.
87-
pub enum Coerce = CombineFields;
87+
pub struct Coerce(CombineFields);
8888

8989
pub impl Coerce {
9090
fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {

src/librustc/middle/typeck/infer/glb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use util::ppaux::mt_to_str;
2929

3030
use std::list;
3131

32-
pub enum Glb = CombineFields; // "greatest lower bound" (common subtype)
32+
pub struct Glb(CombineFields); // "greatest lower bound" (common subtype)
3333

3434
impl Combine for Glb {
3535
fn infcx(&self) -> @mut InferCtxt { self.infcx }

src/librustc/middle/typeck/infer/lub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use syntax::ast::{pure_fn, ret_style, return_val, unsafe_fn};
2929
use syntax::ast::{Onceness, purity};
3030
use syntax::codemap::span;
3131

32-
pub enum Lub = CombineFields; // least-upper-bound: common supertype
32+
pub struct Lub(CombineFields); // least-upper-bound: common supertype
3333

3434
pub impl Lub {
3535
fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }

src/librustc/middle/typeck/infer/region_inference.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub impl RegionVarBindings {
700700
match undo_item {
701701
Snapshot => {}
702702
AddVar(vid) => {
703-
fail_unless!(self.var_spans.len() == *vid + 1);
703+
fail_unless!(self.var_spans.len() == vid.to_uint() + 1);
704704
self.var_spans.pop();
705705
}
706706
AddConstraint(ref constraint) => {
@@ -720,7 +720,7 @@ pub impl RegionVarBindings {
720720
fn new_region_var(&mut self, span: span) -> RegionVid {
721721
let id = self.num_vars();
722722
self.var_spans.push(span);
723-
let vid = RegionVid(id);
723+
let vid = RegionVid { id: id };
724724
if self.in_snapshot() {
725725
self.undo_log.push(AddVar(vid));
726726
}
@@ -863,15 +863,15 @@ pub impl RegionVarBindings {
863863
}
864864

865865
fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
866-
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, *rid);
866+
debug!("RegionVarBindings: resolve_var(%?=%u)", rid, rid.to_uint());
867867
if self.values.is_empty() {
868868
self.tcx.sess.span_bug(
869-
self.var_spans[*rid],
869+
self.var_spans[rid.to_uint()],
870870
fmt!("Attempt to resolve region variable before values have \
871871
been computed!"));
872872
}
873873

874-
let v = self.values.with_ref(|values| values[*rid]);
874+
let v = self.values.with_ref(|values| values[rid.to_uint()]);
875875
match v {
876876
Value(r) => r,
877877

@@ -886,13 +886,13 @@ pub impl RegionVarBindings {
886886
// should ultimately have some bounds.
887887

888888
self.tcx.sess.span_err(
889-
self.var_spans[*rid],
890-
fmt!("Unconstrained region variable #%u", *rid));
889+
self.var_spans[rid.to_uint()],
890+
fmt!("Unconstrained region variable #%u", rid.to_uint()));
891891

892892
// Touch of a hack: to suppress duplicate messages,
893893
// replace the NoValue entry with ErrorValue.
894894
let mut values = self.values.take();
895-
values[*rid] = ErrorValue;
895+
values[rid.to_uint()] = ErrorValue;
896896
self.values.put_back(values);
897897
re_static
898898
}
@@ -1049,7 +1049,7 @@ priv impl RegionVarBindings {
10491049

10501050
(re_infer(ReVar(v_id)), _) | (_, re_infer(ReVar(v_id))) => {
10511051
self.tcx.sess.span_bug(
1052-
self.var_spans[*v_id],
1052+
self.var_spans[v_id.to_uint()],
10531053
fmt!("lub_concrete_regions invoked with \
10541054
non-concrete regions: %?, %?", a, b));
10551055
}
@@ -1111,7 +1111,7 @@ priv impl RegionVarBindings {
11111111
(re_infer(ReVar(v_id)), _) |
11121112
(_, re_infer(ReVar(v_id))) => {
11131113
self.tcx.sess.span_bug(
1114-
self.var_spans[*v_id],
1114+
self.var_spans[v_id.to_uint()],
11151115
fmt!("glb_concrete_regions invoked with \
11161116
non-concrete regions: %?, %?", a, b));
11171117
}
@@ -1275,8 +1275,8 @@ pub impl RegionVarBindings {
12751275
edge_idx: uint) {
12761276
let edge_dir = edge_dir as uint;
12771277
graph.edges[edge_idx].next_edge[edge_dir] =
1278-
graph.nodes[*node_id].head_edge[edge_dir];
1279-
graph.nodes[*node_id].head_edge[edge_dir] =
1278+
graph.nodes[node_id.to_uint()].head_edge[edge_dir];
1279+
graph.nodes[node_id.to_uint()].head_edge[edge_dir] =
12801280
edge_idx;
12811281
}
12821282
}
@@ -1285,14 +1285,14 @@ pub impl RegionVarBindings {
12851285
do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| {
12861286
match edge.constraint {
12871287
ConstrainRegSubVar(a_region, b_vid) => {
1288-
let b_node = &mut nodes[*b_vid];
1288+
let b_node = &mut nodes[b_vid.to_uint()];
12891289
self.expand_node(a_region, b_vid, b_node)
12901290
}
12911291
ConstrainVarSubVar(a_vid, b_vid) => {
1292-
match nodes[*a_vid].value {
1292+
match nodes[a_vid.to_uint()].value {
12931293
NoValue | ErrorValue => false,
12941294
Value(a_region) => {
1295-
let b_node = &mut nodes[*b_vid];
1295+
let b_node = &mut nodes[b_vid.to_uint()];
12961296
self.expand_node(a_region, b_vid, b_node)
12971297
}
12981298
}
@@ -1349,16 +1349,16 @@ pub impl RegionVarBindings {
13491349
false
13501350
}
13511351
ConstrainVarSubVar(a_vid, b_vid) => {
1352-
match nodes[*b_vid].value {
1352+
match nodes[b_vid.to_uint()].value {
13531353
NoValue | ErrorValue => false,
13541354
Value(b_region) => {
1355-
let a_node = &mut nodes[*a_vid];
1355+
let a_node = &mut nodes[a_vid.to_uint()];
13561356
self.contract_node(a_vid, a_node, b_region)
13571357
}
13581358
}
13591359
}
13601360
ConstrainVarSubReg(a_vid, b_region) => {
1361-
let a_node = &mut nodes[*a_vid];
1361+
let a_node = &mut nodes[a_vid.to_uint()];
13621362
self.contract_node(a_vid, a_node, b_region)
13631363
}
13641364
}
@@ -1474,7 +1474,7 @@ pub impl RegionVarBindings {
14741474
that is not used is not a problem, so if this rule
14751475
starts to create problems we'll have to revisit
14761476
this portion of the code and think hard about it. =) */
1477-
let node_vid = RegionVid(idx);
1477+
let node_vid = RegionVid { id: idx };
14781478
match node.classification {
14791479
Expanding => {
14801480
self.report_error_for_expanding_node(
@@ -1525,7 +1525,7 @@ pub impl RegionVarBindings {
15251525
}
15261526

15271527
self.tcx.sess.span_err(
1528-
self.var_spans[*node_idx],
1528+
self.var_spans[node_idx.to_uint()],
15291529
fmt!("cannot infer an appropriate lifetime \
15301530
due to conflicting requirements"));
15311531

@@ -1578,7 +1578,7 @@ pub impl RegionVarBindings {
15781578
}
15791579

15801580
self.tcx.sess.span_err(
1581-
self.var_spans[*node_idx],
1581+
self.var_spans[node_idx.to_uint()],
15821582
fmt!("cannot infer an appropriate lifetime \
15831583
due to conflicting requirements"));
15841584

@@ -1616,7 +1616,7 @@ pub impl RegionVarBindings {
16161616
-> ~[SpannedRegion] {
16171617
let set = HashMap();
16181618
let mut stack = ~[orig_node_idx];
1619-
set.insert(*orig_node_idx, ());
1619+
set.insert(orig_node_idx.to_uint(), ());
16201620
let mut result = ~[];
16211621
while !vec::is_empty(stack) {
16221622
let node_idx = stack.pop();
@@ -1627,7 +1627,7 @@ pub impl RegionVarBindings {
16271627
Incoming => from_vid,
16281628
Outgoing => to_vid
16291629
};
1630-
if set.insert(*vid, ()) {
1630+
if set.insert(vid.to_uint(), ()) {
16311631
stack.push(vid);
16321632
}
16331633
}
@@ -1658,7 +1658,8 @@ pub impl RegionVarBindings {
16581658
node_idx: RegionVid,
16591659
dir: Direction,
16601660
op: &fn(edge: &GraphEdge) -> bool) {
1661-
let mut edge_idx = graph.nodes[*node_idx].head_edge[dir as uint];
1661+
let mut edge_idx =
1662+
graph.nodes[node_idx.to_uint()].head_edge[dir as uint];
16621663
while edge_idx != uint::max_value {
16631664
let edge_ptr = &graph.edges[edge_idx];
16641665
if !op(edge_ptr) {

src/librustc/middle/typeck/infer/sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use syntax::ast::{Onceness, m_const, purity, ret_style};
2929
use syntax::codemap::span;
3030

3131

32-
pub enum Sub = CombineFields; // "subtype", "subregion" etc
32+
pub struct Sub(CombineFields); // "subtype", "subregion" etc
3333

3434
impl Combine for Sub {
3535
fn infcx(&self) -> @mut InferCtxt { self.infcx }

src/librustc/middle/typeck/rscope.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ impl region_scope for MethodRscope {
7474
}
7575
}
7676

77-
pub enum type_rscope = Option<ty::region_variance>;
77+
pub struct type_rscope(Option<ty::region_variance>);
78+
7879
impl type_rscope {
7980
priv fn replacement(&self) -> ty::Region {
8081
if self.is_some() {

0 commit comments

Comments
 (0)