Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
{
let field_place = self.project_field(&place, field_idx)?;
match field.name {
sym::bit_width => self.write_scalar(
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
sym::bits => self.write_scalar(
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
&field_place,
)?,
sym::signed => self.write_scalar(Scalar::from_bool(signed), &field_place)?,
Expand All @@ -270,8 +270,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
{
let field_place = self.project_field(&place, field_idx)?;
match field.name {
sym::bit_width => self.write_scalar(
ScalarInt::try_from_target_usize(bit_width, self.tcx.tcx).unwrap(),
sym::bits => self.write_scalar(
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
&field_place,
)?,
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,12 @@ symbols! {
binaryheap_iter,
bind_by_move_pattern_guards,
bindings_after_at,
bit_width,
bitand,
bitand_assign,
bitor,
bitor_assign,
bitreverse,
bits,
bitxor,
bitxor_assign,
black_box,
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/mem/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct Char {
#[unstable(feature = "type_info", issue = "146922")]
pub struct Int {
/// The bit width of the signed integer type.
pub bit_width: usize,
pub bits: u32,
/// Whether the integer type is signed.
pub signed: bool,
}
Expand All @@ -123,7 +123,7 @@ pub struct Int {
#[unstable(feature = "type_info", issue = "146922")]
pub struct Float {
/// The bit width of the floating-point type.
pub bit_width: usize,
pub bits: u32,
}

/// Compile-time type information about string slice types.
Expand Down
14 changes: 7 additions & 7 deletions library/coretests/tests/mem/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ fn test_tuples() {

match (a.ty.info().kind, b.ty.info().kind) {
(TypeKind::Int(a), TypeKind::Int(b)) => {
assert!(a.bit_width == 8 && a.signed);
assert!(b.bit_width == 8 && !b.signed);
assert!(a.bits == 8 && a.signed);
assert!(b.bits == 8 && !b.signed);
}
_ => unreachable!(),
}
Expand All @@ -70,27 +70,27 @@ fn test_primitives() {

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

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

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

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

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

let Type { kind: Str(_ty), size, .. } = (const { Type::of::<str>() }) else { panic!() };
assert_eq!(size, None);
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/reflection/dump.bit32.run.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 8,
bits: 8,
signed: true,
},
),
Expand All @@ -46,7 +46,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: true,
},
),
Expand All @@ -57,7 +57,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: true,
},
),
Expand All @@ -68,7 +68,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 128,
bits: 128,
signed: true,
},
),
Expand All @@ -79,7 +79,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: true,
},
),
Expand All @@ -90,7 +90,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 8,
bits: 8,
signed: false,
},
),
Expand All @@ -101,7 +101,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: false,
},
),
Expand All @@ -112,7 +112,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: false,
},
),
Expand All @@ -123,7 +123,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 128,
bits: 128,
signed: false,
},
),
Expand All @@ -134,7 +134,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: false,
},
),
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/reflection/dump.bit64.run.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 8,
bits: 8,
signed: true,
},
),
Expand All @@ -46,7 +46,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: true,
},
),
Expand All @@ -57,7 +57,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: true,
},
),
Expand All @@ -68,7 +68,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 128,
bits: 128,
signed: true,
},
),
Expand All @@ -79,7 +79,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: true,
},
),
Expand All @@ -90,7 +90,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 8,
bits: 8,
signed: false,
},
),
Expand All @@ -101,7 +101,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 32,
bits: 32,
signed: false,
},
),
Expand All @@ -112,7 +112,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: false,
},
),
Expand All @@ -123,7 +123,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 128,
bits: 128,
signed: false,
},
),
Expand All @@ -134,7 +134,7 @@ Type {
Type {
kind: Int(
Int {
bit_width: 64,
bits: 64,
signed: false,
},
),
Expand Down
Loading