Skip to content

Commit a3d8cf7

Browse files
authored
Cleanup wchar_t layout computation to happen later. (#1596)
This is a breaking cheange since WChar is exposed, but should be no behavior change otherwise.
1 parent 9fe3e90 commit a3d8cf7

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/codegen/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3060,8 +3060,9 @@ impl TryToRustTy for Type {
30603060
IntKind::ULong => Ok(raw_type(ctx, "c_ulong")),
30613061
IntKind::LongLong => Ok(raw_type(ctx, "c_longlong")),
30623062
IntKind::ULongLong => Ok(raw_type(ctx, "c_ulonglong")),
3063-
IntKind::WChar { size } => {
3064-
let ty = Layout::known_type_for_size(ctx, size)
3063+
IntKind::WChar => {
3064+
let layout = self.layout(ctx).expect("Couldn't compute wchar_t's layout?");
3065+
let ty = Layout::known_type_for_size(ctx, layout.size)
30653066
.expect("Non-representable wchar_t?");
30663067
let ident = ctx.rust_ident_raw(ty);
30673068
Ok(quote! { #ident })

src/ir/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2011,11 +2011,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
20112011
CXType_UChar => TypeKind::Int(IntKind::UChar),
20122012
CXType_Short => TypeKind::Int(IntKind::Short),
20132013
CXType_UShort => TypeKind::Int(IntKind::UShort),
2014-
CXType_WChar => {
2015-
TypeKind::Int(IntKind::WChar {
2016-
size: ty.fallible_size(self).expect("Couldn't compute size of wchar_t?"),
2017-
})
2018-
},
2014+
CXType_WChar => TypeKind::Int(IntKind::WChar),
20192015
CXType_Char16 => TypeKind::Int(IntKind::U16),
20202016
CXType_Char32 => TypeKind::Int(IntKind::U32),
20212017
CXType_Long => TypeKind::Int(IntKind::Long),

src/ir/int.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ pub enum IntKind {
1313
UChar,
1414

1515
/// An `wchar_t`.
16-
WChar {
17-
/// The size of the wchar_t in bytes, which will be 2 or 4.
18-
size: usize,
19-
},
16+
WChar,
2017

2118
/// A platform-dependent `char` type, with the signedness support.
2219
Char {
@@ -97,7 +94,7 @@ impl IntKind {
9794
// to know whether it is or not right now (unlike char, there's no
9895
// WChar_S / WChar_U).
9996
Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 |
100-
WChar { .. } | U32 | U64 | U128 => false,
97+
WChar | U32 | U64 | U128 => false,
10198

10299
SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
103100
I128 => true,

0 commit comments

Comments
 (0)