@@ -21,27 +21,27 @@ use syntax_pos::symbol::Symbol;
21
21
/// A `LitKind`-like enum to fold constant `Expr`s into.
22
22
#[ derive( Debug , Clone ) ]
23
23
pub enum Constant {
24
- /// a String "abc"
24
+ /// A ` String` (e.g., "abc").
25
25
Str ( String ) ,
26
- /// a Binary String b"abc"
26
+ /// A binary string (e.g., ` b"abc"`).
27
27
Binary ( Lrc < Vec < u8 > > ) ,
28
- /// a single char 'a'
28
+ /// A single ` char` (e.g., ` 'a'`).
29
29
Char ( char ) ,
30
- /// an integer's bit representation
30
+ /// An integer's bit representation.
31
31
Int ( u128 ) ,
32
- /// an f32
32
+ /// An ` f32`.
33
33
F32 ( f32 ) ,
34
- /// an f64
34
+ /// An ` f64`.
35
35
F64 ( f64 ) ,
36
- /// true or false
36
+ /// ` true` or ` false`.
37
37
Bool ( bool ) ,
38
- /// an array of constants
38
+ /// An array of constants.
39
39
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.
41
41
Repeat ( Box < Constant > , u64 ) ,
42
- /// a tuple of constants
42
+ /// A tuple of constants.
43
43
Tuple ( Vec < Constant > ) ,
44
- /// a literal with syntax error
44
+ /// A literal with syntax error.
45
45
Err ( Symbol ) ,
46
46
}
47
47
@@ -53,23 +53,24 @@ impl PartialEq for Constant {
53
53
( & Constant :: Char ( l) , & Constant :: Char ( r) ) => l == r,
54
54
( & Constant :: Int ( l) , & Constant :: Int ( r) ) => l == r,
55
55
( & 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.
59
59
l. to_bits ( ) == r. to_bits ( )
60
60
} ,
61
61
( & 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.
65
65
f64:: from ( l) . to_bits ( ) == f64:: from ( r) . to_bits ( )
66
66
} ,
67
67
( & Constant :: Bool ( l) , & Constant :: Bool ( r) ) => l == r,
68
68
( & Constant :: Vec ( ref l) , & Constant :: Vec ( ref r) ) | ( & Constant :: Tuple ( ref l) , & Constant :: Tuple ( ref r) ) => {
69
69
l == r
70
70
} ,
71
71
( & 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 ,
73
74
}
74
75
}
75
76
}
@@ -142,12 +143,13 @@ impl Constant {
142
143
x => x,
143
144
}
144
145
} ,
145
- _ => None , // TODO: Are there any useful inter-type orderings?
146
+ // TODO: are there any useful inter-type orderings?
147
+ _ => None ,
146
148
}
147
149
}
148
150
}
149
151
150
- /// parse a `LitKind` to a `Constant`
152
+ /// Parses a `LitKind` to a `Constant`.
151
153
pub fn lit_to_constant < ' tcx > ( lit : & LitKind , ty : Ty < ' tcx > ) -> Constant {
152
154
use syntax:: ast:: * ;
153
155
0 commit comments