Skip to content

Commit

Permalink
Address Rust nightly compiler warnings (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Sep 23, 2024
1 parent 26635b2 commit bca9a76
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
2 changes: 2 additions & 0 deletions crates/libs/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#![doc(html_no_source)]
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)]
#![cfg_attr(not(feature = "docs"), doc(hidden))]
// TODO: workaround for https://github.com/rust-lang/rust/issues/130757
#![allow(improper_ctypes)]

#[allow(unused_extern_crates)]
extern crate self as windows_sys;
Expand Down
2 changes: 2 additions & 0 deletions crates/libs/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#![allow(non_snake_case, clashing_extern_declarations, non_upper_case_globals, non_camel_case_types, missing_docs, dead_code, clippy::all)]
#![cfg_attr(not(feature = "docs"), doc(hidden))]
#![cfg_attr(all(not(feature = "std")), no_std)]
// TODO: workaround for https://github.com/rust-lang/rust/issues/130757
#![allow(improper_ctypes)]

#[allow(unused_extern_crates)]
extern crate self as windows;
Expand Down
82 changes: 39 additions & 43 deletions crates/tests/misc/implement/tests/identity.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#![allow(non_snake_case)]

use std::sync::atomic::*;
use windows::{core::*, Foundation::*};

static mut COUNTER: isize = 0;
static COUNTER: AtomicIsize = AtomicIsize::new(0);

#[implement(IStringable, IClosable)]
struct Test(String);

impl Test {
fn new(value: &str) -> Self {
unsafe {
COUNTER += 1;
}
COUNTER.fetch_add(1, Ordering::Relaxed);
Self(value.to_string())
}
}

impl Drop for Test {
fn drop(&mut self) {
unsafe {
COUNTER -= 1;
}
COUNTER.fetch_sub(1, Ordering::Release);
}
}

Expand All @@ -38,48 +35,47 @@ impl IClosable_Impl for Test_Impl {

#[test]
fn identity() -> Result<()> {
unsafe {
assert_eq!(COUNTER, 0);
{
let a: IStringable = Test::new("test").into();
assert!(a.ToString()? == "test");
assert_eq!(COUNTER.load(Ordering::Acquire), 0);
{
let a: IStringable = Test::new("test").into();
assert_eq!(COUNTER.load(Ordering::Acquire), 1);
assert!(a.ToString()? == "test");

let b: IClosable = a.cast()?;
b.Close()?;
let b: IClosable = a.cast()?;
b.Close()?;

let c: IUnknown = b.cast()?;
let c: IUnknown = b.cast()?;

let d: IInspectable = c.cast()?;
let d: IInspectable = c.cast()?;

assert!(a == d.cast()?);
}
{
let a: IUnknown = Test::new("test").into();
let b: IClosable = a.cast()?;
let c: IStringable = b.cast()?;
assert!(c.ToString()? == "test");
}
{
let a: IInspectable = Test::new("test").into();
let b: IStringable = a.cast()?;
assert!(b.ToString()? == "test");
}
{
let a: IInspectable = Test::new("test").into();
assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
assert!(a == d.cast()?);
}
{
let a: IUnknown = Test::new("test").into();
let b: IClosable = a.cast()?;
let c: IStringable = b.cast()?;
assert!(c.ToString()? == "test");
}
{
let a: IInspectable = Test::new("test").into();
let b: IStringable = a.cast()?;
assert!(b.ToString()? == "test");
}
{
let a: IInspectable = Test::new("test").into();
assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable");

let b: IStringable = a.cast()?;
let c: &IInspectable = &b.cast()?;
assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
let b: IStringable = a.cast()?;
let c: &IInspectable = &b.cast()?;
assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable");

let d: IClosable = a.cast()?;
let e: &IInspectable = (&d).into();
assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable");
let d: IClosable = a.cast()?;
let e: &IInspectable = (&d).into();
assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable");

let f: IInspectable = e.cast()?;
assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
}
assert_eq!(COUNTER, 0);
Ok(())
let f: IInspectable = e.cast()?;
assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
}
assert_eq!(COUNTER.load(Ordering::Acquire), 0);
Ok(())
}

0 comments on commit bca9a76

Please sign in to comment.