Skip to content
/ rust Public
forked from rust-lang/rust

Commit 80db715

Browse files
authored
Rollup merge of rust-lang#151235 - type-info-rename-bits, r=oli-obk
Change field `bit_width: usize` to `bits: u32` in type info Follow-up rust-lang#151123 (comment). Quotes: @Skgland: > > I'm not sure whether we should use `usize` or `u64` here to represent the bit width. > > My expectation would be `u32` matching the associated `{u,i}N::BITS`[^1][^2][^3] constant that already exists on the integer types. > > [^1]: https://doc.rust-lang.org/std/primitive.i8.html#associatedconstant.BITS > [^2]: https://doc.rust-lang.org/std/primitive.i128.html#associatedconstant.BITS > [^3]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.BITS @SpriteOvO: > I found some [previous discussions](rust-lang#76492 (comment)) regarding the type of `::BITS` constant. And during the stabilization of `::BITS`, the choice of `u32` affected some ecosystem crates (rust-lang#81654), but soon after, these crates all accepted the `u32` type. > > So I think it makes sense to keep the type consistent with `::BITS` here. Then I'd also like to change the name from `bit_width` to `bits`, also for consistency. r? @oli-obk
2 parents 9ba278e + 27b0279 commit 80db715

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

compiler/rustc_const_eval/src/const_eval/type_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
257257
{
258258
let field_place = self.project_field(&place, field_idx)?;
259259
match field.name {
260-
sym::bit_width => self.write_scalar(
261-
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
260+
sym::bits => self.write_scalar(
261+
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
262262
&field_place,
263263
)?,
264264
sym::signed => self.write_scalar(Scalar::from_bool(signed), &field_place)?,
@@ -278,8 +278,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
278278
{
279279
let field_place = self.project_field(&place, field_idx)?;
280280
match field.name {
281-
sym::bit_width => self.write_scalar(
282-
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
281+
sym::bits => self.write_scalar(
282+
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
283283
&field_place,
284284
)?,
285285
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@ symbols! {
590590
binaryheap_iter,
591591
bind_by_move_pattern_guards,
592592
bindings_after_at,
593-
bit_width,
594593
bitand,
595594
bitand_assign,
596595
bitor,
597596
bitor_assign,
598597
bitreverse,
598+
bits,
599599
bitxor,
600600
bitxor_assign,
601601
black_box,

library/core/src/mem/type_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub struct Char {
114114
#[unstable(feature = "type_info", issue = "146922")]
115115
pub struct Int {
116116
/// The bit width of the signed integer type.
117-
pub bit_width: usize,
117+
pub bits: u32,
118118
/// Whether the integer type is signed.
119119
pub signed: bool,
120120
}
@@ -125,7 +125,7 @@ pub struct Int {
125125
#[unstable(feature = "type_info", issue = "146922")]
126126
pub struct Float {
127127
/// The bit width of the floating-point type.
128-
pub bit_width: usize,
128+
pub bits: u32,
129129
}
130130

131131
/// Compile-time type information about string slice types.

library/coretests/tests/mem/type_info.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ fn test_tuples() {
4747

4848
match (a.ty.info().kind, b.ty.info().kind) {
4949
(TypeKind::Int(a), TypeKind::Int(b)) => {
50-
assert!(a.bit_width == 8 && a.signed);
51-
assert!(b.bit_width == 8 && !b.signed);
50+
assert!(a.bits == 8 && a.signed);
51+
assert!(b.bits == 8 && !b.signed);
5252
}
5353
_ => unreachable!(),
5454
}
@@ -70,27 +70,27 @@ fn test_primitives() {
7070

7171
let Type { kind: Int(ty), size, .. } = (const { Type::of::<i32>() }) else { panic!() };
7272
assert_eq!(size, Some(4));
73-
assert_eq!(ty.bit_width, 32);
73+
assert_eq!(ty.bits, 32);
7474
assert!(ty.signed);
7575

7676
let Type { kind: Int(ty), size, .. } = (const { Type::of::<isize>() }) else { panic!() };
7777
assert_eq!(size, Some(size_of::<isize>()));
78-
assert_eq!(ty.bit_width, size_of::<isize>() * 8);
78+
assert_eq!(ty.bits as usize, size_of::<isize>() * 8);
7979
assert!(ty.signed);
8080

8181
let Type { kind: Int(ty), size, .. } = (const { Type::of::<u32>() }) else { panic!() };
8282
assert_eq!(size, Some(4));
83-
assert_eq!(ty.bit_width, 32);
83+
assert_eq!(ty.bits, 32);
8484
assert!(!ty.signed);
8585

8686
let Type { kind: Int(ty), size, .. } = (const { Type::of::<usize>() }) else { panic!() };
8787
assert_eq!(size, Some(size_of::<usize>()));
88-
assert_eq!(ty.bit_width, size_of::<usize>() * 8);
88+
assert_eq!(ty.bits as usize, size_of::<usize>() * 8);
8989
assert!(!ty.signed);
9090

9191
let Type { kind: Float(ty), size, .. } = (const { Type::of::<f32>() }) else { panic!() };
9292
assert_eq!(size, Some(4));
93-
assert_eq!(ty.bit_width, 32);
93+
assert_eq!(ty.bits, 32);
9494

9595
let Type { kind: Str(_ty), size, .. } = (const { Type::of::<str>() }) else { panic!() };
9696
assert_eq!(size, None);

tests/ui/reflection/dump.bit32.run.stdout

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Type {
3535
Type {
3636
kind: Int(
3737
Int {
38-
bit_width: 8,
38+
bits: 8,
3939
signed: true,
4040
},
4141
),
@@ -46,7 +46,7 @@ Type {
4646
Type {
4747
kind: Int(
4848
Int {
49-
bit_width: 32,
49+
bits: 32,
5050
signed: true,
5151
},
5252
),
@@ -57,7 +57,7 @@ Type {
5757
Type {
5858
kind: Int(
5959
Int {
60-
bit_width: 64,
60+
bits: 64,
6161
signed: true,
6262
},
6363
),
@@ -68,7 +68,7 @@ Type {
6868
Type {
6969
kind: Int(
7070
Int {
71-
bit_width: 128,
71+
bits: 128,
7272
signed: true,
7373
},
7474
),
@@ -79,7 +79,7 @@ Type {
7979
Type {
8080
kind: Int(
8181
Int {
82-
bit_width: 32,
82+
bits: 32,
8383
signed: true,
8484
},
8585
),
@@ -90,7 +90,7 @@ Type {
9090
Type {
9191
kind: Int(
9292
Int {
93-
bit_width: 8,
93+
bits: 8,
9494
signed: false,
9595
},
9696
),
@@ -101,7 +101,7 @@ Type {
101101
Type {
102102
kind: Int(
103103
Int {
104-
bit_width: 32,
104+
bits: 32,
105105
signed: false,
106106
},
107107
),
@@ -112,7 +112,7 @@ Type {
112112
Type {
113113
kind: Int(
114114
Int {
115-
bit_width: 64,
115+
bits: 64,
116116
signed: false,
117117
},
118118
),
@@ -123,7 +123,7 @@ Type {
123123
Type {
124124
kind: Int(
125125
Int {
126-
bit_width: 128,
126+
bits: 128,
127127
signed: false,
128128
},
129129
),
@@ -134,7 +134,7 @@ Type {
134134
Type {
135135
kind: Int(
136136
Int {
137-
bit_width: 32,
137+
bits: 32,
138138
signed: false,
139139
},
140140
),

tests/ui/reflection/dump.bit64.run.stdout

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Type {
3535
Type {
3636
kind: Int(
3737
Int {
38-
bit_width: 8,
38+
bits: 8,
3939
signed: true,
4040
},
4141
),
@@ -46,7 +46,7 @@ Type {
4646
Type {
4747
kind: Int(
4848
Int {
49-
bit_width: 32,
49+
bits: 32,
5050
signed: true,
5151
},
5252
),
@@ -57,7 +57,7 @@ Type {
5757
Type {
5858
kind: Int(
5959
Int {
60-
bit_width: 64,
60+
bits: 64,
6161
signed: true,
6262
},
6363
),
@@ -68,7 +68,7 @@ Type {
6868
Type {
6969
kind: Int(
7070
Int {
71-
bit_width: 128,
71+
bits: 128,
7272
signed: true,
7373
},
7474
),
@@ -79,7 +79,7 @@ Type {
7979
Type {
8080
kind: Int(
8181
Int {
82-
bit_width: 64,
82+
bits: 64,
8383
signed: true,
8484
},
8585
),
@@ -90,7 +90,7 @@ Type {
9090
Type {
9191
kind: Int(
9292
Int {
93-
bit_width: 8,
93+
bits: 8,
9494
signed: false,
9595
},
9696
),
@@ -101,7 +101,7 @@ Type {
101101
Type {
102102
kind: Int(
103103
Int {
104-
bit_width: 32,
104+
bits: 32,
105105
signed: false,
106106
},
107107
),
@@ -112,7 +112,7 @@ Type {
112112
Type {
113113
kind: Int(
114114
Int {
115-
bit_width: 64,
115+
bits: 64,
116116
signed: false,
117117
},
118118
),
@@ -123,7 +123,7 @@ Type {
123123
Type {
124124
kind: Int(
125125
Int {
126-
bit_width: 128,
126+
bits: 128,
127127
signed: false,
128128
},
129129
),
@@ -134,7 +134,7 @@ Type {
134134
Type {
135135
kind: Int(
136136
Int {
137-
bit_width: 64,
137+
bits: 64,
138138
signed: false,
139139
},
140140
),

0 commit comments

Comments
 (0)