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

Address Rust nightly compiler warnings #3292

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
shared reference to mutable static
kennykerr committed Sep 23, 2024
commit 9863c4d40560439f4e80c6aa69f579a55274541f
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);
}
}

@@ -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(())
}