@@ -21,27 +21,27 @@ use syntax_pos::symbol::Symbol;
2121/// A `LitKind`-like enum to fold constant `Expr`s into.
2222#[ derive( Debug , Clone ) ]
2323pub enum Constant {
24- /// a String "abc"
24+ /// A ` String` (e.g., "abc").
2525 Str ( String ) ,
26- /// a Binary String b"abc"
26+ /// A binary string (e.g., ` b"abc"`).
2727 Binary ( Lrc < Vec < u8 > > ) ,
28- /// a single char 'a'
28+ /// A single ` char` (e.g., ` 'a'`).
2929 Char ( char ) ,
30- /// an integer's bit representation
30+ /// An integer's bit representation.
3131 Int ( u128 ) ,
32- /// an f32
32+ /// An ` f32`.
3333 F32 ( f32 ) ,
34- /// an f64
34+ /// An ` f64`.
3535 F64 ( f64 ) ,
36- /// true or false
36+ /// ` true` or ` false`.
3737 Bool ( bool ) ,
38- /// an array of constants
38+ /// An array of constants.
3939 Vec ( Vec < Constant > ) ,
40- /// also an array, but with only one constant, repeated N times
40+ /// Also an array, but with only one constant, repeated N times.
4141 Repeat ( Box < Constant > , u64 ) ,
42- /// a tuple of constants
42+ /// A tuple of constants.
4343 Tuple ( Vec < Constant > ) ,
44- /// a literal with syntax error
44+ /// A literal with syntax error.
4545 Err ( Symbol ) ,
4646}
4747
@@ -53,23 +53,24 @@ impl PartialEq for Constant {
5353 ( & Constant :: Char ( l) , & Constant :: Char ( r) ) => l == r,
5454 ( & Constant :: Int ( l) , & Constant :: Int ( r) ) => l == r,
5555 ( & Constant :: F64 ( l) , & Constant :: F64 ( r) ) => {
56- // we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
57- // `Fw32 == Fw64` so don’t compare them
58- // to_bits is required to catch non-matching 0.0, -0.0, and NaNs
56+ // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
57+ // `Fw32 == Fw64`, so don’t compare them.
58+ // ` to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
5959 l. to_bits ( ) == r. to_bits ( )
6060 } ,
6161 ( & Constant :: F32 ( l) , & Constant :: F32 ( r) ) => {
62- // we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
63- // `Fw32 == Fw64` so don’t compare them
64- // to_bits is required to catch non-matching 0.0, -0.0, and NaNs
62+ // We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
63+ // `Fw32 == Fw64`, so don’t compare them.
64+ // ` to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
6565 f64:: from ( l) . to_bits ( ) == f64:: from ( r) . to_bits ( )
6666 } ,
6767 ( & Constant :: Bool ( l) , & Constant :: Bool ( r) ) => l == r,
6868 ( & Constant :: Vec ( ref l) , & Constant :: Vec ( ref r) ) | ( & Constant :: Tuple ( ref l) , & Constant :: Tuple ( ref r) ) => {
6969 l == r
7070 } ,
7171 ( & Constant :: Repeat ( ref lv, ref ls) , & Constant :: Repeat ( ref rv, ref rs) ) => ls == rs && lv == rv,
72- _ => false , // TODO: Are there inter-type equalities?
72+ // TODO: are there inter-type equalities?
73+ _ => false ,
7374 }
7475 }
7576}
@@ -142,12 +143,13 @@ impl Constant {
142143 x => x,
143144 }
144145 } ,
145- _ => None , // TODO: Are there any useful inter-type orderings?
146+ // TODO: are there any useful inter-type orderings?
147+ _ => None ,
146148 }
147149 }
148150}
149151
150- /// parse a `LitKind` to a `Constant`
152+ /// Parses a `LitKind` to a `Constant`.
151153pub fn lit_to_constant < ' tcx > ( lit : & LitKind , ty : Ty < ' tcx > ) -> Constant {
152154 use syntax:: ast:: * ;
153155
0 commit comments