Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make applicable fields const #1470

Merged
merged 3 commits into from Jan 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -74,6 +74,7 @@ jobs:
cargo test --target ${{ matrix.target }} -p test_arch &&
cargo test --target ${{ matrix.target }} -p test_arch_feature &&
cargo test --target ${{ matrix.target }} -p test_bstr &&
cargo test --target ${{ matrix.target }} -p test_const_fields &&
cargo test --target ${{ matrix.target }} -p test_core &&
cargo test --target ${{ matrix.target }} -p test_debug &&
cargo test --target ${{ matrix.target }} -p test_deprecated &&
Expand Down Expand Up @@ -171,6 +172,7 @@ jobs:
cargo clippy -p test_arch &&
cargo clippy -p test_arch_feature &&
cargo clippy -p test_bstr &&
cargo clippy -p test_const_fields &&
cargo clippy -p test_core &&
cargo clippy -p test_debug &&
cargo clippy -p test_deprecated &&
Expand Down
5 changes: 4 additions & 1 deletion crates/libs/bindgen/src/structs.rs
Expand Up @@ -49,7 +49,10 @@ fn gen_struct_with_name(def: &TypeDef, struct_name: &str, cfg: &Cfg, gen: &Gen)

let fields = def.fields().map(|f| {
let name = gen_ident(f.name());
let sig = gen_sig(&f.signature(Some(def)), gen);
let mut sig = f.signature(Some(def));
sig.is_const = sig.is_const || f.is_const();
let sig = gen_sig(&sig, gen);

if f.is_literal() {
quote! {}
} else if !gen.sys && is_union && !f.is_blittable(Some(def)) {
Expand Down
8 changes: 8 additions & 0 deletions crates/libs/metadata/src/tables/field.rs
Expand Up @@ -40,6 +40,14 @@ impl Field {
pub fn is_blittable(&self, enclosing: Option<&TypeDef>) -> bool {
self.signature(enclosing).is_blittable()
}

pub fn is_const(&self) -> bool {
self.has_attribute("ConstAttribute")
}

fn has_attribute(&self, name: &str) -> bool {
self.attributes().any(|attribute| attribute.name() == name)
}
}

#[cfg(test)]
Expand Down
1,086 changes: 543 additions & 543 deletions crates/libs/sys/src/Windows/Win32/AI/MachineLearning/DirectML/mod.rs

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions crates/libs/sys/src/Windows/Win32/AI/MachineLearning/WinML/mod.rs
Expand Up @@ -59,10 +59,10 @@ impl ::core::clone::Clone for MLOperatorAttributeNameValue {
#[doc = "*Required features: 'Win32_AI_MachineLearning_WinML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
pub union MLOperatorAttributeNameValue_0 {
pub reserved: *mut ::core::ffi::c_void,
pub ints: *mut i64,
pub strings: *mut *mut i8,
pub floats: *mut f32,
pub reserved: *const ::core::ffi::c_void,
pub ints: *const i64,
pub strings: *const *const i8,
pub floats: *const f32,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for MLOperatorAttributeNameValue_0 {}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl ::core::clone::Clone for MLOperatorEdgeType {
#[cfg(feature = "Win32_Foundation")]
pub struct MLOperatorEdgeTypeConstraint {
pub typeLabel: super::super::super::Foundation::PSTR,
pub allowedTypes: *mut MLOperatorEdgeDescription,
pub allowedTypes: *const MLOperatorEdgeDescription,
pub allowedTypeCount: u32,
}
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -165,9 +165,9 @@ pub struct MLOperatorKernelDescription {
pub name: super::super::super::Foundation::PSTR,
pub minimumOperatorSetVersion: i32,
pub executionType: MLOperatorExecutionType,
pub typeConstraints: *mut MLOperatorEdgeTypeConstraint,
pub typeConstraints: *const MLOperatorEdgeTypeConstraint,
pub typeConstraintCount: u32,
pub defaultAttributes: *mut MLOperatorAttributeNameValue,
pub defaultAttributes: *const MLOperatorAttributeNameValue,
pub defaultAttributeCount: u32,
pub options: MLOperatorKernelOptions,
pub executionOptions: u32,
Expand Down Expand Up @@ -213,15 +213,15 @@ impl ::core::clone::Clone for MLOperatorParameterOptions {
pub struct MLOperatorSchemaDescription {
pub name: super::super::super::Foundation::PSTR,
pub operatorSetVersionAtLastChange: i32,
pub inputs: *mut MLOperatorSchemaEdgeDescription,
pub inputs: *const MLOperatorSchemaEdgeDescription,
pub inputCount: u32,
pub outputs: *mut MLOperatorSchemaEdgeDescription,
pub outputs: *const MLOperatorSchemaEdgeDescription,
pub outputCount: u32,
pub typeConstraints: *mut MLOperatorEdgeTypeConstraint,
pub typeConstraints: *const MLOperatorEdgeTypeConstraint,
pub typeConstraintCount: u32,
pub attributes: *mut MLOperatorAttribute,
pub attributes: *const MLOperatorAttribute,
pub attributeCount: u32,
pub defaultAttributes: *mut MLOperatorAttributeNameValue,
pub defaultAttributes: *const MLOperatorAttributeNameValue,
pub defaultAttributeCount: u32,
}
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -252,7 +252,7 @@ impl ::core::clone::Clone for MLOperatorSchemaEdgeDescription {
#[doc = "*Required features: 'Win32_AI_MachineLearning_WinML', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
pub union MLOperatorSchemaEdgeDescription_0 {
pub reserved: *mut ::core::ffi::c_void,
pub reserved: *const ::core::ffi::c_void,
pub typeLabel: super::super::super::Foundation::PSTR,
pub edgeDescription: MLOperatorEdgeDescription,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/sys/src/Windows/Win32/Devices/AllJoyn/mod.rs
Expand Up @@ -2403,7 +2403,7 @@ impl ::core::clone::Clone for alljoyn_busobject_callbacks {
#[doc = "*Required features: 'Win32_Devices_AllJoyn', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
pub struct alljoyn_busobject_methodentry {
pub member: *mut alljoyn_interfacedescription_member,
pub member: *const alljoyn_interfacedescription_member,
pub method_handler: alljoyn_messagereceiver_methodhandler_ptr,
}
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -2475,7 +2475,7 @@ pub struct alljoyn_interfacedescription_member {
pub signature: super::super::Foundation::PSTR,
pub returnSignature: super::super::Foundation::PSTR,
pub argNames: super::super::Foundation::PSTR,
pub internal_member: *mut ::core::ffi::c_void,
pub internal_member: *const ::core::ffi::c_void,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for alljoyn_interfacedescription_member {}
Expand All @@ -2492,7 +2492,7 @@ pub struct alljoyn_interfacedescription_property {
pub name: super::super::Foundation::PSTR,
pub signature: super::super::Foundation::PSTR,
pub access: u8,
pub internal_property: *mut ::core::ffi::c_void,
pub internal_property: *const ::core::ffi::c_void,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for alljoyn_interfacedescription_property {}
Expand Down
Expand Up @@ -151,7 +151,7 @@ pub struct DEV_OBJECT {
pub ObjectType: DEV_OBJECT_TYPE,
pub pszObjectId: super::super::Foundation::PWSTR,
pub cPropertyCount: u32,
pub pProperties: *mut super::Properties::DEVPROPERTY,
pub pProperties: *const super::Properties::DEVPROPERTY,
}
#[cfg(all(feature = "Win32_Devices_Properties", feature = "Win32_Foundation"))]
impl ::core::marker::Copy for DEV_OBJECT {}
Expand Down
Expand Up @@ -89,11 +89,11 @@ pub struct SW_DEVICE_CREATE_INFO {
pub pszInstanceId: super::super::super::Foundation::PWSTR,
pub pszzHardwareIds: super::super::super::Foundation::PWSTR,
pub pszzCompatibleIds: super::super::super::Foundation::PWSTR,
pub pContainerId: *mut ::windows_sys::core::GUID,
pub pContainerId: *const ::windows_sys::core::GUID,
pub CapabilityFlags: u32,
pub pszDeviceDescription: super::super::super::Foundation::PWSTR,
pub pszDeviceLocation: super::super::super::Foundation::PWSTR,
pub pSecurityDescriptor: *mut super::super::super::Security::SECURITY_DESCRIPTOR,
pub pSecurityDescriptor: *const super::super::super::Security::SECURITY_DESCRIPTOR,
}
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_Security"))]
impl ::core::marker::Copy for SW_DEVICE_CREATE_INFO {}
Expand Down
Expand Up @@ -4136,7 +4136,7 @@ impl ::core::clone::Clone for DIOBJECTCALIBRATION {
#[repr(C)]
#[doc = "*Required features: 'Win32_Devices_HumanInterfaceDevice'*"]
pub struct DIOBJECTDATAFORMAT {
pub pguid: *mut ::windows_sys::core::GUID,
pub pguid: *const ::windows_sys::core::GUID,
pub dwOfs: u32,
pub dwType: u32,
pub dwFlags: u32,
Expand Down
Expand Up @@ -556,7 +556,7 @@ impl ::core::clone::Clone for WSDXML_TEXT {
#[cfg(feature = "Win32_Foundation")]
pub struct WSDXML_TYPE {
pub Uri: super::super::Foundation::PWSTR,
pub Table: *mut u8,
pub Table: *const u8,
}
#[cfg(feature = "Win32_Foundation")]
impl ::core::marker::Copy for WSDXML_TYPE {}
Expand Down
32 changes: 16 additions & 16 deletions crates/libs/sys/src/Windows/Win32/Globalization/mod.rs
Expand Up @@ -5893,7 +5893,7 @@ pub const UCPTRIE_SMALL_MAX: i32 = 4095i32;
#[repr(C)]
#[doc = "*Required features: 'Win32_Globalization'*"]
pub struct UCPTrie {
pub index: *mut u16,
pub index: *const u16,
pub data: UCPTrieData,
pub indexLength: i32,
pub dataLength: i32,
Expand All @@ -5916,10 +5916,10 @@ impl ::core::clone::Clone for UCPTrie {
#[repr(C)]
#[doc = "*Required features: 'Win32_Globalization'*"]
pub union UCPTrieData {
pub ptr0: *mut ::core::ffi::c_void,
pub ptr16: *mut u16,
pub ptr32: *mut u32,
pub ptr8: *mut u8,
pub ptr0: *const ::core::ffi::c_void,
pub ptr16: *const u16,
pub ptr32: *const u32,
pub ptr8: *const u8,
}
impl ::core::marker::Copy for UCPTrieData {}
impl ::core::clone::Clone for UCPTrieData {
Expand Down Expand Up @@ -6230,7 +6230,7 @@ pub type UCharEnumTypeRange = ::core::option::Option<unsafe extern "system" fn(c
#[repr(C)]
#[doc = "*Required features: 'Win32_Globalization'*"]
pub struct UCharIterator {
pub context: *mut ::core::ffi::c_void,
pub context: *const ::core::ffi::c_void,
pub length: i32,
pub start: i32,
pub index: i32,
Expand Down Expand Up @@ -6423,8 +6423,8 @@ pub struct UConverterFromUnicodeArgs {
pub size: u16,
pub flush: i8,
pub converter: *mut UConverter,
pub source: *mut u16,
pub sourceLimit: *mut u16,
pub source: *const u16,
pub sourceLimit: *const u16,
pub target: super::Foundation::PSTR,
pub targetLimit: super::Foundation::PSTR,
pub offsets: *mut i32,
Expand Down Expand Up @@ -6458,7 +6458,7 @@ pub struct UConverterToUnicodeArgs {
pub source: super::Foundation::PSTR,
pub sourceLimit: super::Foundation::PSTR,
pub target: *mut u16,
pub targetLimit: *mut u16,
pub targetLimit: *const u16,
pub offsets: *mut i32,
}
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -9392,7 +9392,7 @@ pub const UBRK_SENTENCE_SEP_LIMIT: USentenceBreakTag = 200i32;
#[repr(C)]
#[doc = "*Required features: 'Win32_Globalization'*"]
pub struct USerializedSet {
pub array: *mut u16,
pub array: *const u16,
pub bmpLength: i32,
pub length: i32,
pub staticArray: [u16; 8],
Expand Down Expand Up @@ -9542,13 +9542,13 @@ pub struct UText {
pub chunkNativeStart: i64,
pub chunkOffset: i32,
pub chunkLength: i32,
pub chunkContents: *mut u16,
pub pFuncs: *mut UTextFuncs,
pub chunkContents: *const u16,
pub pFuncs: *const UTextFuncs,
pub pExtra: *mut ::core::ffi::c_void,
pub context: *mut ::core::ffi::c_void,
pub p: *mut ::core::ffi::c_void,
pub q: *mut ::core::ffi::c_void,
pub r: *mut ::core::ffi::c_void,
pub context: *const ::core::ffi::c_void,
pub p: *const ::core::ffi::c_void,
pub q: *const ::core::ffi::c_void,
pub r: *const ::core::ffi::c_void,
pub privP: *mut ::core::ffi::c_void,
pub a: i64,
pub b: i32,
Expand Down
10 changes: 5 additions & 5 deletions crates/libs/sys/src/Windows/Win32/Graphics/Direct2D/mod.rs
Expand Up @@ -747,9 +747,9 @@ pub const D2D1_CROSSFADE_PROP_FORCE_DWORD: D2D1_CROSSFADE_PROP = 4294967295u32;
#[doc = "*Required features: 'Win32_Graphics_Direct2D', 'Win32_Foundation', 'Win32_Graphics_Dxgi_Common'*"]
#[cfg(all(feature = "Win32_Foundation", feature = "Win32_Graphics_Dxgi_Common"))]
pub struct D2D1_CUSTOM_VERTEX_BUFFER_PROPERTIES {
pub shaderBufferWithInputSignature: *mut u8,
pub shaderBufferWithInputSignature: *const u8,
pub shaderBufferSize: u32,
pub inputElements: *mut D2D1_INPUT_ELEMENT_DESC,
pub inputElements: *const D2D1_INPUT_ELEMENT_DESC,
pub elementCount: u32,
pub stride: u32,
}
Expand Down Expand Up @@ -2109,12 +2109,12 @@ pub const D2D1_RENDER_TARGET_USAGE_FORCE_DWORD: D2D1_RENDER_TARGET_USAGE = 42949
#[repr(C)]
#[doc = "*Required features: 'Win32_Graphics_Direct2D'*"]
pub struct D2D1_RESOURCE_TEXTURE_PROPERTIES {
pub extents: *mut u32,
pub extents: *const u32,
pub dimensions: u32,
pub bufferPrecision: D2D1_BUFFER_PRECISION,
pub channelDepth: D2D1_CHANNEL_DEPTH,
pub filter: D2D1_FILTER,
pub extendModes: *mut D2D1_EXTEND_MODE,
pub extendModes: *const D2D1_EXTEND_MODE,
}
impl ::core::marker::Copy for D2D1_RESOURCE_TEXTURE_PROPERTIES {}
impl ::core::clone::Clone for D2D1_RESOURCE_TEXTURE_PROPERTIES {
Expand Down Expand Up @@ -2793,7 +2793,7 @@ pub const D2D1_UNIT_MODE_FORCE_DWORD: D2D1_UNIT_MODE = 4294967295u32;
pub struct D2D1_VERTEX_BUFFER_PROPERTIES {
pub inputCount: u32,
pub usage: D2D1_VERTEX_USAGE,
pub data: *mut u8,
pub data: *const u8,
pub byteWidth: u32,
}
impl ::core::marker::Copy for D2D1_VERTEX_BUFFER_PROPERTIES {}
Expand Down
Expand Up @@ -72,7 +72,7 @@ impl ::core::clone::Clone for DxcArgPair {
#[repr(C)]
#[doc = "*Required features: 'Win32_Graphics_Direct3D_Dxc'*"]
pub struct DxcBuffer {
pub Ptr: *mut ::core::ffi::c_void,
pub Ptr: *const ::core::ffi::c_void,
pub Size: usize,
pub Encoding: u32,
}
Expand Down
Expand Up @@ -205,7 +205,7 @@ pub const D3D_GET_INST_OFFSETS_INCLUDE_NON_EXECUTABLE: u32 = 1u32;
#[repr(C)]
#[doc = "*Required features: 'Win32_Graphics_Direct3D_Fxc'*"]
pub struct D3D_SHADER_DATA {
pub pBytecode: *mut ::core::ffi::c_void,
pub pBytecode: *const ::core::ffi::c_void,
pub BytecodeLength: usize,
}
impl ::core::marker::Copy for D3D_SHADER_DATA {}
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/sys/src/Windows/Win32/Graphics/Direct3D10/mod.rs
Expand Up @@ -801,9 +801,9 @@ impl ::core::clone::Clone for D3D10_EFFECT_DESC {
#[doc = "*Required features: 'Win32_Graphics_Direct3D10', 'Win32_Foundation'*"]
#[cfg(feature = "Win32_Foundation")]
pub struct D3D10_EFFECT_SHADER_DESC {
pub pInputSignature: *mut u8,
pub pInputSignature: *const u8,
pub IsInline: super::super::Foundation::BOOL,
pub pBytecode: *mut u8,
pub pBytecode: *const u8,
pub BytecodeLength: u32,
pub SODecl: super::super::Foundation::PSTR,
pub NumInputSignatureEntries: u32,
Expand Down Expand Up @@ -1188,7 +1188,7 @@ pub struct D3D10_MESSAGE {
pub Category: D3D10_MESSAGE_CATEGORY,
pub Severity: D3D10_MESSAGE_SEVERITY,
pub ID: D3D10_MESSAGE_ID,
pub pDescription: *mut u8,
pub pDescription: *const u8,
pub DescriptionByteLength: usize,
}
impl ::core::marker::Copy for D3D10_MESSAGE {}
Expand Down Expand Up @@ -3272,7 +3272,7 @@ pub const D3D10_SUBPIXEL_FRACTIONAL_BIT_COUNT: u32 = 8u32;
#[repr(C)]
#[doc = "*Required features: 'Win32_Graphics_Direct3D10'*"]
pub struct D3D10_SUBRESOURCE_DATA {
pub pSysMem: *mut ::core::ffi::c_void,
pub pSysMem: *const ::core::ffi::c_void,
pub SysMemPitch: u32,
pub SysMemSlicePitch: u32,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/sys/src/Windows/Win32/Graphics/Direct3D11/mod.rs
Expand Up @@ -2594,7 +2594,7 @@ pub struct D3D11_MESSAGE {
pub Category: D3D11_MESSAGE_CATEGORY,
pub Severity: D3D11_MESSAGE_SEVERITY,
pub ID: D3D11_MESSAGE_ID,
pub pDescription: *mut u8,
pub pDescription: *const u8,
pub DescriptionByteLength: usize,
}
impl ::core::marker::Copy for D3D11_MESSAGE {}
Expand Down Expand Up @@ -6406,7 +6406,7 @@ pub const D3D11_SUBPIXEL_FRACTIONAL_BIT_COUNT: u32 = 8u32;
#[repr(C)]
#[doc = "*Required features: 'Win32_Graphics_Direct3D11'*"]
pub struct D3D11_SUBRESOURCE_DATA {
pub pSysMem: *mut ::core::ffi::c_void,
pub pSysMem: *const ::core::ffi::c_void,
pub SysMemPitch: u32,
pub SysMemSlicePitch: u32,
}
Expand Down