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

Avoid deriving Eq for structs containing floating point type parameters #3255

Merged
merged 4 commits into from
Sep 6, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ jobs:
run: cargo clippy -p test_query_signature
- name: Clippy test_readme
run: cargo clippy -p test_readme
- name: Clippy test_reference_float
run: cargo clippy -p test_reference_float
- name: Clippy test_registry
run: cargo clippy -p test_registry
- name: Clippy test_registry_default
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,18 @@ jobs:
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_float
run: cargo test -p test_reference_float --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_resources
run: cargo test -p test_resources --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_resources
run: cargo test -p test_resources --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_result
run: cargo test -p test_result --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_return_handle
Expand Down
4 changes: 3 additions & 1 deletion crates/libs/bindgen/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ pub fn type_has_float(ty: &Type) -> bool {
match ty {
Type::F32 | Type::F64 => true,
Type::Win32Array(ty, _) => type_has_float(ty),
Type::TypeDef(def, _) => type_def_has_float(*def),
Type::TypeDef(def, generics) => {
type_def_has_float(*def) || generics.iter().any(type_has_float)
}
_ => false,
}
}
Expand Down
23 changes: 23 additions & 0 deletions crates/tests/winrt/reference_float/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "test_reference_float"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doc = false
doctest = false

[build-dependencies.windows-bindgen]
workspace = true

[dependencies.windows-core]
workspace = true

[dependencies.windows]
workspace = true
features = [
"implement",
"Foundation",
]
33 changes: 33 additions & 0 deletions crates/tests/winrt/reference_float/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
fn main() {
let mut command = std::process::Command::new("midlrt.exe");
command.args([
"/winrt",
"/nomidl",
"/h",
"nul",
"/metadata_dir",
"../../../libs/bindgen/default",
"/reference",
"../../../libs/bindgen/default/Windows.winmd",
"/winmd",
"metadata.winmd",
"src/metadata.idl",
]);

if !command.status().unwrap().success() {
panic!("Failed to run midlrt");
}

windows_bindgen::bindgen([
"--in",
"metadata.winmd",
"--out",
"src/bindings.rs",
"--filter",
"test_reference_float",
"--config",
"implement",
"no-bindgen-comment",
])
.unwrap();
}
23 changes: 23 additions & 0 deletions crates/tests/winrt/reference_float/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![allow(
non_snake_case,
non_upper_case_globals,
non_camel_case_types,
dead_code,
clippy::all
)]
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct RefWithFloat {
pub Value: Option<windows::Foundation::IReference<f32>>,
}
impl windows_core::TypeKind for RefWithFloat {
type TypeKind = windows_core::CloneType;
}
impl windows_core::RuntimeType for RefWithFloat {
const SIGNATURE :windows_core::imp::ConstBuffer = windows_core::imp::ConstBuffer::from_slice ( b"struct(test_reference_float.RefWithFloat;pinterface({61c17706-2d65-11e0-9ae8-d48564015472};f4))" ) ;
}
impl Default for RefWithFloat {
fn default() -> Self {
unsafe { core::mem::zeroed() }
}
}
14 changes: 14 additions & 0 deletions crates/tests/winrt/reference_float/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![cfg(test)]

mod bindings;
use bindings::*;
use windows::{core::*, Foundation::*};

#[test]
fn test() -> Result<()> {
let mut container = RefWithFloat::default();
container.Value = Some(PropertyValue::CreateSingle(1.23)?.cast()?);
assert_eq!(container.Value.unwrap().Value()?, 1.23);

Ok(())
}
10 changes: 10 additions & 0 deletions crates/tests/winrt/reference_float/src/metadata.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This tests that windows-bindgen avoids deriving `Eq` for types with floating point fields.
// https://github.com/microsoft/windows-rs/issues/3220

namespace test_reference_float
{
struct RefWithFloat
{
Windows.Foundation.IReference<Single> Value;
};
}