@@ -53,10 +53,11 @@ bitflags! {
53
53
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
54
54
#[ cfg_attr( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
55
55
pub enum IntegerType {
56
- /// Pointer sized integer type, i.e. isize and usize. The field shows signedness, that
57
- /// is, `Pointer(true)` is isize.
56
+ /// Pointer- sized integer type, i.e. ` isize` and ` usize` . The field shows signedness, e.g.
57
+ /// `Pointer(true)` means ` isize` .
58
58
Pointer ( bool ) ,
59
- /// Fix sized integer type, e.g. i8, u32, i128 The bool field shows signedness, `Fixed(I8, false)` means `u8`
59
+ /// Fixed-sized integer type, e.g. `i8`, `u32`, `i128`. The bool field shows signedness, e.g.
60
+ /// `Fixed(I8, false)` means `u8`.
60
61
Fixed ( Integer , bool ) ,
61
62
}
62
63
@@ -69,7 +70,7 @@ impl IntegerType {
69
70
}
70
71
}
71
72
72
- /// Represents the repr options provided by the user,
73
+ /// Represents the repr options provided by the user.
73
74
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Default ) ]
74
75
#[ cfg_attr( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
75
76
pub struct ReprOptions {
@@ -139,7 +140,7 @@ impl ReprOptions {
139
140
}
140
141
141
142
/// Returns `true` if this type is valid for reordering and `-Z randomize-layout`
142
- /// was enabled for its declaration crate
143
+ /// was enabled for its declaration crate.
143
144
pub fn can_randomize_type_layout ( & self ) -> bool {
144
145
!self . inhibit_struct_field_reordering_opt ( )
145
146
&& self . flags . contains ( ReprFlags :: RANDOMIZE_LAYOUT )
@@ -217,7 +218,8 @@ pub enum TargetDataLayoutErrors<'a> {
217
218
}
218
219
219
220
impl TargetDataLayout {
220
- /// Parse data layout from an [llvm data layout string](https://llvm.org/docs/LangRef.html#data-layout)
221
+ /// Parse data layout from an
222
+ /// [llvm data layout string](https://llvm.org/docs/LangRef.html#data-layout)
221
223
///
222
224
/// This function doesn't fill `c_enum_min_size` and it will always be `I32` since it can not be
223
225
/// determined from llvm string.
@@ -242,10 +244,11 @@ impl TargetDataLayout {
242
244
} ;
243
245
244
246
// Parse a size string.
245
- let size = |s : & ' a str , cause : & ' a str | parse_bits ( s, "size" , cause) . map ( Size :: from_bits) ;
247
+ let parse_size =
248
+ |s : & ' a str , cause : & ' a str | parse_bits ( s, "size" , cause) . map ( Size :: from_bits) ;
246
249
247
250
// Parse an alignment string.
248
- let align = |s : & [ & ' a str ] , cause : & ' a str | {
251
+ let parse_align = |s : & [ & ' a str ] , cause : & ' a str | {
249
252
if s. is_empty ( ) {
250
253
return Err ( TargetDataLayoutErrors :: MissingAlignment { cause } ) ;
251
254
}
@@ -269,22 +272,22 @@ impl TargetDataLayout {
269
272
[ p] if p. starts_with ( 'P' ) => {
270
273
dl. instruction_address_space = parse_address_space ( & p[ 1 ..] , "P" ) ?
271
274
}
272
- [ "a" , ref a @ ..] => dl. aggregate_align = align ( a, "a" ) ?,
273
- [ "f32" , ref a @ ..] => dl. f32_align = align ( a, "f32" ) ?,
274
- [ "f64" , ref a @ ..] => dl. f64_align = align ( a, "f64" ) ?,
275
+ [ "a" , ref a @ ..] => dl. aggregate_align = parse_align ( a, "a" ) ?,
276
+ [ "f32" , ref a @ ..] => dl. f32_align = parse_align ( a, "f32" ) ?,
277
+ [ "f64" , ref a @ ..] => dl. f64_align = parse_align ( a, "f64" ) ?,
275
278
// FIXME(erikdesjardins): we should be parsing nonzero address spaces
276
279
// this will require replacing TargetDataLayout::{pointer_size,pointer_align}
277
280
// with e.g. `fn pointer_size_in(AddressSpace)`
278
281
[ p @ "p" , s, ref a @ ..] | [ p @ "p0" , s, ref a @ ..] => {
279
- dl. pointer_size = size ( s, p) ?;
280
- dl. pointer_align = align ( a, p) ?;
282
+ dl. pointer_size = parse_size ( s, p) ?;
283
+ dl. pointer_align = parse_align ( a, p) ?;
281
284
}
282
285
[ s, ref a @ ..] if s. starts_with ( 'i' ) => {
283
286
let Ok ( bits) = s[ 1 ..] . parse :: < u64 > ( ) else {
284
- size ( & s[ 1 ..] , "i" ) ?; // For the user error.
287
+ parse_size ( & s[ 1 ..] , "i" ) ?; // For the user error.
285
288
continue ;
286
289
} ;
287
- let a = align ( a, s) ?;
290
+ let a = parse_align ( a, s) ?;
288
291
match bits {
289
292
1 => dl. i1_align = a,
290
293
8 => dl. i8_align = a,
@@ -301,8 +304,8 @@ impl TargetDataLayout {
301
304
}
302
305
}
303
306
[ s, ref a @ ..] if s. starts_with ( 'v' ) => {
304
- let v_size = size ( & s[ 1 ..] , "v" ) ?;
305
- let a = align ( a, s) ?;
307
+ let v_size = parse_size ( & s[ 1 ..] , "v" ) ?;
308
+ let a = parse_align ( a, s) ?;
306
309
if let Some ( v) = dl. vector_align . iter_mut ( ) . find ( |v| v. 0 == v_size) {
307
310
v. 1 = a;
308
311
continue ;
@@ -747,7 +750,6 @@ impl Align {
747
750
/// A pair of alignments, ABI-mandated and preferred.
748
751
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
749
752
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
750
-
751
753
pub struct AbiAndPrefAlign {
752
754
pub abi : Align ,
753
755
pub pref : Align ,
@@ -773,7 +775,6 @@ impl AbiAndPrefAlign {
773
775
/// Integers, also used for enum discriminants.
774
776
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
775
777
#[ cfg_attr( feature = "nightly" , derive( Encodable , Decodable , HashStable_Generic ) ) ]
776
-
777
778
pub enum Integer {
778
779
I8 ,
779
780
I16 ,
@@ -937,8 +938,7 @@ impl Primitive {
937
938
}
938
939
939
940
/// Inclusive wrap-around range of valid values, that is, if
940
- /// start > end, it represents `start..=MAX`,
941
- /// followed by `0..=end`.
941
+ /// start > end, it represents `start..=MAX`, followed by `0..=end`.
942
942
///
943
943
/// That is, for an i8 primitive, a range of `254..=2` means following
944
944
/// sequence:
@@ -970,21 +970,21 @@ impl WrappingRange {
970
970
971
971
/// Returns `self` with replaced `start`
972
972
#[ inline( always) ]
973
- pub fn with_start ( mut self , start : u128 ) -> Self {
973
+ fn with_start ( mut self , start : u128 ) -> Self {
974
974
self . start = start;
975
975
self
976
976
}
977
977
978
978
/// Returns `self` with replaced `end`
979
979
#[ inline( always) ]
980
- pub fn with_end ( mut self , end : u128 ) -> Self {
980
+ fn with_end ( mut self , end : u128 ) -> Self {
981
981
self . end = end;
982
982
self
983
983
}
984
984
985
985
/// Returns `true` if `size` completely fills the range.
986
986
#[ inline]
987
- pub fn is_full_for ( & self , size : Size ) -> bool {
987
+ fn is_full_for ( & self , size : Size ) -> bool {
988
988
let max_value = size. unsigned_int_max ( ) ;
989
989
debug_assert ! ( self . start <= max_value && self . end <= max_value) ;
990
990
self . start == ( self . end . wrapping_add ( 1 ) & max_value)
@@ -1066,15 +1066,17 @@ impl Scalar {
1066
1066
}
1067
1067
1068
1068
#[ inline]
1069
- /// Allows the caller to mutate the valid range. This operation will panic if attempted on a union.
1069
+ /// Allows the caller to mutate the valid range. This operation will panic if attempted on a
1070
+ /// union.
1070
1071
pub fn valid_range_mut ( & mut self ) -> & mut WrappingRange {
1071
1072
match self {
1072
1073
Scalar :: Initialized { valid_range, .. } => valid_range,
1073
1074
Scalar :: Union { .. } => panic ! ( "cannot change the valid range of a union" ) ,
1074
1075
}
1075
1076
}
1076
1077
1077
- /// Returns `true` if all possible numbers are valid, i.e `valid_range` covers the whole layout
1078
+ /// Returns `true` if all possible numbers are valid, i.e `valid_range` covers the whole
1079
+ /// layout.
1078
1080
#[ inline]
1079
1081
pub fn is_always_valid < C : HasDataLayout > ( & self , cx : & C ) -> bool {
1080
1082
match * self {
@@ -1252,7 +1254,6 @@ impl AddressSpace {
1252
1254
/// in terms of categories of C types there are ABI rules for.
1253
1255
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
1254
1256
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
1255
-
1256
1257
pub enum Abi {
1257
1258
Uninhabited ,
1258
1259
Scalar ( Scalar ) ,
@@ -1457,17 +1458,19 @@ impl Niche {
1457
1458
return None ;
1458
1459
}
1459
1460
1460
- // Extend the range of valid values being reserved by moving either `v.start` or `v.end` bound.
1461
- // Given an eventual `Option<T>`, we try to maximize the chance for `None` to occupy the niche of zero.
1462
- // This is accomplished by preferring enums with 2 variants(`count==1`) and always taking the shortest path to niche zero.
1463
- // Having `None` in niche zero can enable some special optimizations.
1461
+ // Extend the range of valid values being reserved by moving either `v.start` or `v.end`
1462
+ // bound. Given an eventual `Option<T>`, we try to maximize the chance for `None` to occupy
1463
+ // the niche of zero. This is accomplished by preferring enums with 2 variants(`count==1`)
1464
+ // and always taking the shortest path to niche zero. Having `None` in niche zero can
1465
+ // enable some special optimizations.
1464
1466
//
1465
1467
// Bound selection criteria:
1466
1468
// 1. Select closest to zero given wrapping semantics.
1467
1469
// 2. Avoid moving past zero if possible.
1468
1470
//
1469
- // In practice this means that enums with `count > 1` are unlikely to claim niche zero, since they have to fit perfectly.
1470
- // If niche zero is already reserved, the selection of bounds are of little interest.
1471
+ // In practice this means that enums with `count > 1` are unlikely to claim niche zero,
1472
+ // since they have to fit perfectly. If niche zero is already reserved, the selection of
1473
+ // bounds are of little interest.
1471
1474
let move_start = |v : WrappingRange | {
1472
1475
let start = v. start . wrapping_sub ( count) & max_value;
1473
1476
Some ( ( start, Scalar :: Initialized { value, valid_range : v. with_start ( start) } ) )
0 commit comments