diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 18e815e9b7c0..379d3cdc94e4 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -229,8 +229,8 @@ pub mod types { */ #[repr(u8)] pub enum c_void { - priv variant1, - priv variant2 + __variant1, + __variant2, } pub enum FILE {} pub enum fpos_t {} diff --git a/src/librand/distributions/gamma.rs b/src/librand/distributions/gamma.rs index 6ec8411495a5..dd249a1fbcac 100644 --- a/src/librand/distributions/gamma.rs +++ b/src/librand/distributions/gamma.rs @@ -45,10 +45,14 @@ use super::{IndependentSample, Sample, Exp}; /// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3 /// (September 2000), /// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414) -pub enum Gamma { - priv Large(GammaLargeShape), - priv One(Exp), - priv Small(GammaSmallShape) +pub struct Gamma { + repr: GammaRepr, +} + +enum GammaRepr { + Large(GammaLargeShape), + One(Exp), + Small(GammaSmallShape) } // These two helpers could be made public, but saving the @@ -90,11 +94,12 @@ impl Gamma { assert!(shape > 0.0, "Gamma::new called with shape <= 0"); assert!(scale > 0.0, "Gamma::new called with scale <= 0"); - match shape { + let repr = match shape { 1.0 => One(Exp::new(1.0 / scale)), 0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)), _ => Large(GammaLargeShape::new_raw(shape, scale)) - } + }; + Gamma { repr: repr } } } @@ -131,7 +136,7 @@ impl Sample for GammaLargeShape { impl IndependentSample for Gamma { fn ind_sample(&self, rng: &mut R) -> f64 { - match *self { + match self.repr { Small(ref g) => g.ind_sample(rng), One(ref g) => g.ind_sample(rng), Large(ref g) => g.ind_sample(rng), @@ -183,24 +188,29 @@ impl IndependentSample for GammaLargeShape { /// let v = chi.ind_sample(&mut rand::task_rng()); /// println!("{} is from a χ²(11) distribution", v) /// ``` -pub enum ChiSquared { +pub struct ChiSquared { + repr: ChiSquaredRepr, +} + +enum ChiSquaredRepr { // k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1, // e.g. when alpha = 1/2 as it would be for this case, so special- // casing and using the definition of N(0,1)^2 is faster. - priv DoFExactlyOne, - priv DoFAnythingElse(Gamma) + DoFExactlyOne, + DoFAnythingElse(Gamma), } impl ChiSquared { /// Create a new chi-squared distribution with degrees-of-freedom /// `k`. Fails if `k < 0`. pub fn new(k: f64) -> ChiSquared { - if k == 1.0 { + let repr = if k == 1.0 { DoFExactlyOne } else { assert!(k > 0.0, "ChiSquared::new called with `k` < 0"); DoFAnythingElse(Gamma::new(0.5 * k, 2.0)) - } + }; + ChiSquared { repr: repr } } } impl Sample for ChiSquared { @@ -208,7 +218,7 @@ impl Sample for ChiSquared { } impl IndependentSample for ChiSquared { fn ind_sample(&self, rng: &mut R) -> f64 { - match *self { + match self.repr { DoFExactlyOne => { // k == 1 => N(0,1)^2 let StandardNormal(norm) = rng.gen::(); diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ae58e153258e..0514642c5839 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -206,15 +206,19 @@ impl CrateDebugContext { } } -pub enum FunctionDebugContext { - priv FunctionDebugContext(~FunctionDebugContextData), - priv DebugInfoDisabled, - priv FunctionWithoutDebugInfo, +pub struct FunctionDebugContext { + repr: FunctionDebugContextRepr, +} + +enum FunctionDebugContextRepr { + FunctionDebugContext(~FunctionDebugContextData), + DebugInfoDisabled, + FunctionWithoutDebugInfo, } impl FunctionDebugContext { fn get_ref<'a>(&'a self, cx: &CrateContext, span: Span) -> &'a FunctionDebugContextData { - match *self { + match self.repr { FunctionDebugContext(~ref data) => data, DebugInfoDisabled => { cx.sess().span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); @@ -544,7 +548,7 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) { pub fn set_source_location(fcx: &FunctionContext, node_id: ast::NodeId, span: Span) { - match fcx.debug_context { + match fcx.debug_context.repr { DebugInfoDisabled => return, FunctionWithoutDebugInfo => { set_debug_location(fcx.ccx, UnknownLocation); @@ -585,7 +589,7 @@ pub fn clear_source_location(fcx: &FunctionContext) { /// and must therefore be called before the first real statement/expression of the function is /// translated. pub fn start_emitting_source_locations(fcx: &FunctionContext) { - match fcx.debug_context { + match fcx.debug_context.repr { FunctionDebugContext(~ref data) => { data.source_locations_enabled.set(true) }, @@ -603,7 +607,7 @@ pub fn create_function_debug_context(cx: &CrateContext, param_substs: Option<@param_substs>, llfn: ValueRef) -> FunctionDebugContext { if cx.sess().opts.debuginfo == NoDebugInfo { - return DebugInfoDisabled; + return FunctionDebugContext { repr: DebugInfoDisabled }; } // Clear the debug location so we don't assign them in the function prelude. Do this here @@ -611,7 +615,7 @@ pub fn create_function_debug_context(cx: &CrateContext, set_debug_location(cx, UnknownLocation); if fn_ast_id == -1 { - return FunctionWithoutDebugInfo; + return FunctionDebugContext { repr: FunctionWithoutDebugInfo }; } let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: OwnedSlice::empty() }; @@ -678,7 +682,7 @@ pub fn create_function_debug_context(cx: &CrateContext, ast_map::NodeForeignItem(..) | ast_map::NodeVariant(..) | ast_map::NodeStructCtor(..) => { - return FunctionWithoutDebugInfo; + return FunctionDebugContext { repr: FunctionWithoutDebugInfo }; } _ => cx.sess().bug(format!("create_function_debug_context: \ unexpected sort of node: {:?}", fnitem)) @@ -686,7 +690,7 @@ pub fn create_function_debug_context(cx: &CrateContext, // This can be the case for functions inlined from another crate if span == codemap::DUMMY_SP { - return FunctionWithoutDebugInfo; + return FunctionDebugContext { repr: FunctionWithoutDebugInfo }; } let loc = span_start(cx, span); @@ -761,7 +765,7 @@ pub fn create_function_debug_context(cx: &CrateContext, fn_metadata, &mut *fn_debug_context.scope_map.borrow_mut()); - return FunctionDebugContext(fn_debug_context); + return FunctionDebugContext { repr: FunctionDebugContext(fn_debug_context) }; fn get_function_signature(cx: &CrateContext, fn_ast_id: ast::NodeId, @@ -2335,7 +2339,7 @@ fn DIB(cx: &CrateContext) -> DIBuilderRef { } fn fn_should_be_ignored(fcx: &FunctionContext) -> bool { - match fcx.debug_context { + match fcx.debug_context.repr { FunctionDebugContext(_) => false, _ => true } diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 1dcebd7a0161..792673e32981 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -12,15 +12,19 @@ use std::mem; use std::vec; /// A vector type optimized for cases where the size is almost always 0 or 1 -pub enum SmallVector { - priv Zero, - priv One(T), - priv Many(Vec ), +pub struct SmallVector { + repr: SmallVectorRepr, +} + +enum SmallVectorRepr { + Zero, + One(T), + Many(Vec ), } impl Container for SmallVector { fn len(&self) -> uint { - match *self { + match self.repr { Zero => 0, One(..) => 1, Many(ref vals) => vals.len() @@ -30,7 +34,7 @@ impl Container for SmallVector { impl FromIterator for SmallVector { fn from_iter>(iter: I) -> SmallVector { - let mut v = Zero; + let mut v = SmallVector::zero(); v.extend(iter); v } @@ -46,24 +50,24 @@ impl Extendable for SmallVector { impl SmallVector { pub fn zero() -> SmallVector { - Zero + SmallVector { repr: Zero } } pub fn one(v: T) -> SmallVector { - One(v) + SmallVector { repr: One(v) } } - pub fn many(vs: Vec ) -> SmallVector { - Many(vs) + pub fn many(vs: Vec) -> SmallVector { + SmallVector { repr: Many(vs) } } pub fn push(&mut self, v: T) { - match *self { - Zero => *self = One(v), + match self.repr { + Zero => self.repr = One(v), One(..) => { - let one = mem::replace(self, Zero); + let one = mem::replace(&mut self.repr, Zero); match one { - One(v1) => mem::replace(self, Many(vec!(v1, v))), + One(v1) => mem::replace(&mut self.repr, Many(vec!(v1, v))), _ => unreachable!() }; } @@ -78,7 +82,7 @@ impl SmallVector { } pub fn get<'a>(&'a self, idx: uint) -> &'a T { - match *self { + match self.repr { One(ref v) if idx == 0 => v, Many(ref vs) => vs.get(idx), _ => fail!("out of bounds access") @@ -86,7 +90,7 @@ impl SmallVector { } pub fn expect_one(self, err: &'static str) -> T { - match self { + match self.repr { One(v) => v, Many(v) => { if v.len() == 1 { @@ -100,27 +104,32 @@ impl SmallVector { } pub fn move_iter(self) -> MoveItems { - match self { + let repr = match self.repr { Zero => ZeroIterator, One(v) => OneIterator(v), Many(vs) => ManyIterator(vs.move_iter()) - } + }; + MoveItems { repr: repr } } } -pub enum MoveItems { - priv ZeroIterator, - priv OneIterator(T), - priv ManyIterator(vec::MoveItems), +pub struct MoveItems { + repr: MoveItemsRepr, +} + +enum MoveItemsRepr { + ZeroIterator, + OneIterator(T), + ManyIterator(vec::MoveItems), } impl Iterator for MoveItems { fn next(&mut self) -> Option { - match *self { + match self.repr { ZeroIterator => None, OneIterator(..) => { let mut replacement = ZeroIterator; - mem::swap(self, &mut replacement); + mem::swap(&mut self.repr, &mut replacement); match replacement { OneIterator(v) => Some(v), _ => unreachable!() @@ -131,7 +140,7 @@ impl Iterator for MoveItems { } fn size_hint(&self) -> (uint, Option) { - match *self { + match self.repr { ZeroIterator => (0, Some(0)), OneIterator(..) => (1, Some(1)), ManyIterator(ref inner) => inner.size_hint()