From dc4869945c42b6df04487955e914319466975ae9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Mar 2013 17:55:16 -0800 Subject: [PATCH] librustc: Remove newtype enums from librustc --- src/librustc/middle/liveness.rs | 4 +- src/librustc/middle/ty.rs | 14 +++--- src/librustc/middle/typeck/infer/coercion.rs | 2 +- src/librustc/middle/typeck/infer/glb.rs | 2 +- src/librustc/middle/typeck/infer/lub.rs | 2 +- .../middle/typeck/infer/region_inference.rs | 49 ++++++++++--------- src/librustc/middle/typeck/infer/sub.rs | 2 +- src/librustc/middle/typeck/rscope.rs | 3 +- 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 1bde1e85843..0c17b371694 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -137,8 +137,8 @@ // if it detects an outstanding loan (that is, the addr is taken). pub type last_use_map = HashMap; -enum Variable = uint; -enum LiveNode = uint; +struct Variable(uint); +struct LiveNode(uint); impl cmp::Eq for Variable { pure fn eq(&self, other: &Variable) -> bool { *(*self) == *(*other) } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 5552364df23..b4ef87491a8 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -582,18 +582,20 @@ pub enum param_bound { } #[deriving_eq] -pub enum TyVid = uint; +pub struct TyVid(uint); #[deriving_eq] -pub enum IntVid = uint; +pub struct IntVid(uint); #[deriving_eq] -pub enum FloatVid = uint; +pub struct FloatVid(uint); #[deriving_eq] #[auto_encode] #[auto_decode] -pub enum RegionVid = uint; +pub struct RegionVid { + id: uint +} #[deriving_eq] pub enum InferTy { @@ -687,11 +689,11 @@ impl ToStr for FloatVid { } impl Vid for RegionVid { - pure fn to_uint(&self) -> uint { **self } + pure fn to_uint(&self) -> uint { self.id } } impl ToStr for RegionVid { - pure fn to_str(&self) -> ~str { fmt!("%?", self) } + pure fn to_str(&self) -> ~str { fmt!("%?", self.id) } } impl ToStr for FnSig { diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index 2390e73f16f..91c987acc6a 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -84,7 +84,7 @@ fn foo(a: A, b: A) { ... } // Note: Coerce is not actually a combiner, in that it does not // conform to the same interface, though it performs a similar // function. -pub enum Coerce = CombineFields; +pub struct Coerce(CombineFields); pub impl Coerce { fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 49e5fe61762..bba35f02b0c 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -29,7 +29,7 @@ use std::list; -pub enum Glb = CombineFields; // "greatest lower bound" (common subtype) +pub struct Glb(CombineFields); // "greatest lower bound" (common subtype) impl Combine for Glb { fn infcx(&self) -> @mut InferCtxt { self.infcx } diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 83cbd4c745c..3a12fb31a1a 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -29,7 +29,7 @@ use syntax::ast::{Onceness, purity}; use syntax::codemap::span; -pub enum Lub = CombineFields; // least-upper-bound: common supertype +pub struct Lub(CombineFields); // least-upper-bound: common supertype pub impl Lub { fn bot_ty(&self, b: ty::t) -> cres { Ok(b) } diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index cceef9fc0c3..33e953b6218 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -700,7 +700,7 @@ fn rollback_to(&mut self, snapshot: uint) { match undo_item { Snapshot => {} AddVar(vid) => { - fail_unless!(self.var_spans.len() == *vid + 1); + fail_unless!(self.var_spans.len() == vid.to_uint() + 1); self.var_spans.pop(); } AddConstraint(ref constraint) => { @@ -720,7 +720,7 @@ fn num_vars(&mut self) -> uint { fn new_region_var(&mut self, span: span) -> RegionVid { let id = self.num_vars(); self.var_spans.push(span); - let vid = RegionVid(id); + let vid = RegionVid { id: id }; if self.in_snapshot() { self.undo_log.push(AddVar(vid)); } @@ -863,15 +863,15 @@ fn glb_regions(&mut self, } fn resolve_var(&mut self, rid: RegionVid) -> ty::Region { - debug!("RegionVarBindings: resolve_var(%?=%u)", rid, *rid); + debug!("RegionVarBindings: resolve_var(%?=%u)", rid, rid.to_uint()); if self.values.is_empty() { self.tcx.sess.span_bug( - self.var_spans[*rid], + self.var_spans[rid.to_uint()], fmt!("Attempt to resolve region variable before values have \ been computed!")); } - let v = self.values.with_ref(|values| values[*rid]); + let v = self.values.with_ref(|values| values[rid.to_uint()]); match v { Value(r) => r, @@ -886,13 +886,13 @@ fn resolve_var(&mut self, rid: RegionVid) -> ty::Region { // should ultimately have some bounds. self.tcx.sess.span_err( - self.var_spans[*rid], - fmt!("Unconstrained region variable #%u", *rid)); + self.var_spans[rid.to_uint()], + fmt!("Unconstrained region variable #%u", rid.to_uint())); // Touch of a hack: to suppress duplicate messages, // replace the NoValue entry with ErrorValue. let mut values = self.values.take(); - values[*rid] = ErrorValue; + values[rid.to_uint()] = ErrorValue; self.values.put_back(values); re_static } @@ -1049,7 +1049,7 @@ fn lub_concrete_regions(&mut self, +a: Region, +b: Region) -> Region { (re_infer(ReVar(v_id)), _) | (_, re_infer(ReVar(v_id))) => { self.tcx.sess.span_bug( - self.var_spans[*v_id], + self.var_spans[v_id.to_uint()], fmt!("lub_concrete_regions invoked with \ non-concrete regions: %?, %?", a, b)); } @@ -1111,7 +1111,7 @@ fn glb_concrete_regions(&mut self, (re_infer(ReVar(v_id)), _) | (_, re_infer(ReVar(v_id))) => { self.tcx.sess.span_bug( - self.var_spans[*v_id], + self.var_spans[v_id.to_uint()], fmt!("glb_concrete_regions invoked with \ non-concrete regions: %?, %?", a, b)); } @@ -1275,8 +1275,8 @@ fn insert_edge(+graph: &mut Graph, edge_idx: uint) { let edge_dir = edge_dir as uint; graph.edges[edge_idx].next_edge[edge_dir] = - graph.nodes[*node_id].head_edge[edge_dir]; - graph.nodes[*node_id].head_edge[edge_dir] = + graph.nodes[node_id.to_uint()].head_edge[edge_dir]; + graph.nodes[node_id.to_uint()].head_edge[edge_dir] = edge_idx; } } @@ -1285,14 +1285,14 @@ fn expansion(&mut self, graph: &mut Graph) { do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| { match edge.constraint { ConstrainRegSubVar(a_region, b_vid) => { - let b_node = &mut nodes[*b_vid]; + let b_node = &mut nodes[b_vid.to_uint()]; self.expand_node(a_region, b_vid, b_node) } ConstrainVarSubVar(a_vid, b_vid) => { - match nodes[*a_vid].value { + match nodes[a_vid.to_uint()].value { NoValue | ErrorValue => false, Value(a_region) => { - let b_node = &mut nodes[*b_vid]; + let b_node = &mut nodes[b_vid.to_uint()]; self.expand_node(a_region, b_vid, b_node) } } @@ -1349,16 +1349,16 @@ fn contraction(&mut self, graph: &mut Graph) { false } ConstrainVarSubVar(a_vid, b_vid) => { - match nodes[*b_vid].value { + match nodes[b_vid.to_uint()].value { NoValue | ErrorValue => false, Value(b_region) => { - let a_node = &mut nodes[*a_vid]; + let a_node = &mut nodes[a_vid.to_uint()]; self.contract_node(a_vid, a_node, b_region) } } } ConstrainVarSubReg(a_vid, b_region) => { - let a_node = &mut nodes[*a_vid]; + let a_node = &mut nodes[a_vid.to_uint()]; self.contract_node(a_vid, a_node, b_region) } } @@ -1474,7 +1474,7 @@ fn extract_values_and_report_conflicts( that is not used is not a problem, so if this rule starts to create problems we'll have to revisit this portion of the code and think hard about it. =) */ - let node_vid = RegionVid(idx); + let node_vid = RegionVid { id: idx }; match node.classification { Expanding => { self.report_error_for_expanding_node( @@ -1525,7 +1525,7 @@ fn report_error_for_expanding_node(&mut self, } self.tcx.sess.span_err( - self.var_spans[*node_idx], + self.var_spans[node_idx.to_uint()], fmt!("cannot infer an appropriate lifetime \ due to conflicting requirements")); @@ -1578,7 +1578,7 @@ fn report_error_for_contracting_node(&mut self, } self.tcx.sess.span_err( - self.var_spans[*node_idx], + self.var_spans[node_idx.to_uint()], fmt!("cannot infer an appropriate lifetime \ due to conflicting requirements")); @@ -1616,7 +1616,7 @@ fn collect_concrete_regions(&mut self, -> ~[SpannedRegion] { let set = HashMap(); let mut stack = ~[orig_node_idx]; - set.insert(*orig_node_idx, ()); + set.insert(orig_node_idx.to_uint(), ()); let mut result = ~[]; while !vec::is_empty(stack) { let node_idx = stack.pop(); @@ -1627,7 +1627,7 @@ fn collect_concrete_regions(&mut self, Incoming => from_vid, Outgoing => to_vid }; - if set.insert(*vid, ()) { + if set.insert(vid.to_uint(), ()) { stack.push(vid); } } @@ -1658,7 +1658,8 @@ fn each_edge(&mut self, node_idx: RegionVid, dir: Direction, op: &fn(edge: &GraphEdge) -> bool) { - let mut edge_idx = graph.nodes[*node_idx].head_edge[dir as uint]; + let mut edge_idx = + graph.nodes[node_idx.to_uint()].head_edge[dir as uint]; while edge_idx != uint::max_value { let edge_ptr = &graph.edges[edge_idx]; if !op(edge_ptr) { diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index f209116696e..b4d8905a936 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -29,7 +29,7 @@ use syntax::codemap::span; -pub enum Sub = CombineFields; // "subtype", "subregion" etc +pub struct Sub(CombineFields); // "subtype", "subregion" etc impl Combine for Sub { fn infcx(&self) -> @mut InferCtxt { self.infcx } diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index f0fc173101f..f74a0960f66 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -74,7 +74,8 @@ fn named_region(&self, span: span, id: ast::ident) } } -pub enum type_rscope = Option; +pub struct type_rscope(Option); + impl type_rscope { priv fn replacement(&self) -> ty::Region { if self.is_some() { -- GitLab