Skip to content

Commit bca9a76

Browse files
authored
Address Rust nightly compiler warnings (#3292)
1 parent 26635b2 commit bca9a76

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

crates/libs/sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
88
#![doc(html_no_source)]
99
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)]
1010
#![cfg_attr(not(feature = "docs"), doc(hidden))]
11+
// TODO: workaround for https://github.com/rust-lang/rust/issues/130757
12+
#![allow(improper_ctypes)]
1113

1214
#[allow(unused_extern_crates)]
1315
extern crate self as windows_sys;

crates/libs/windows/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
1111
#![allow(non_snake_case, clashing_extern_declarations, non_upper_case_globals, non_camel_case_types, missing_docs, dead_code, clippy::all)]
1212
#![cfg_attr(not(feature = "docs"), doc(hidden))]
1313
#![cfg_attr(all(not(feature = "std")), no_std)]
14+
// TODO: workaround for https://github.com/rust-lang/rust/issues/130757
15+
#![allow(improper_ctypes)]
1416

1517
#[allow(unused_extern_crates)]
1618
extern crate self as windows;
Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
#![allow(non_snake_case)]
22

3+
use std::sync::atomic::*;
34
use windows::{core::*, Foundation::*};
45

5-
static mut COUNTER: isize = 0;
6+
static COUNTER: AtomicIsize = AtomicIsize::new(0);
67

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

1011
impl Test {
1112
fn new(value: &str) -> Self {
12-
unsafe {
13-
COUNTER += 1;
14-
}
13+
COUNTER.fetch_add(1, Ordering::Relaxed);
1514
Self(value.to_string())
1615
}
1716
}
1817

1918
impl Drop for Test {
2019
fn drop(&mut self) {
21-
unsafe {
22-
COUNTER -= 1;
23-
}
20+
COUNTER.fetch_sub(1, Ordering::Release);
2421
}
2522
}
2623

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

3936
#[test]
4037
fn identity() -> Result<()> {
41-
unsafe {
42-
assert_eq!(COUNTER, 0);
43-
{
44-
let a: IStringable = Test::new("test").into();
45-
assert!(a.ToString()? == "test");
38+
assert_eq!(COUNTER.load(Ordering::Acquire), 0);
39+
{
40+
let a: IStringable = Test::new("test").into();
41+
assert_eq!(COUNTER.load(Ordering::Acquire), 1);
42+
assert!(a.ToString()? == "test");
4643

47-
let b: IClosable = a.cast()?;
48-
b.Close()?;
44+
let b: IClosable = a.cast()?;
45+
b.Close()?;
4946

50-
let c: IUnknown = b.cast()?;
47+
let c: IUnknown = b.cast()?;
5148

52-
let d: IInspectable = c.cast()?;
49+
let d: IInspectable = c.cast()?;
5350

54-
assert!(a == d.cast()?);
55-
}
56-
{
57-
let a: IUnknown = Test::new("test").into();
58-
let b: IClosable = a.cast()?;
59-
let c: IStringable = b.cast()?;
60-
assert!(c.ToString()? == "test");
61-
}
62-
{
63-
let a: IInspectable = Test::new("test").into();
64-
let b: IStringable = a.cast()?;
65-
assert!(b.ToString()? == "test");
66-
}
67-
{
68-
let a: IInspectable = Test::new("test").into();
69-
assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
51+
assert!(a == d.cast()?);
52+
}
53+
{
54+
let a: IUnknown = Test::new("test").into();
55+
let b: IClosable = a.cast()?;
56+
let c: IStringable = b.cast()?;
57+
assert!(c.ToString()? == "test");
58+
}
59+
{
60+
let a: IInspectable = Test::new("test").into();
61+
let b: IStringable = a.cast()?;
62+
assert!(b.ToString()? == "test");
63+
}
64+
{
65+
let a: IInspectable = Test::new("test").into();
66+
assert_eq!(a.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
7067

71-
let b: IStringable = a.cast()?;
72-
let c: &IInspectable = &b.cast()?;
73-
assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
68+
let b: IStringable = a.cast()?;
69+
let c: &IInspectable = &b.cast()?;
70+
assert_eq!(c.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
7471

75-
let d: IClosable = a.cast()?;
76-
let e: &IInspectable = (&d).into();
77-
assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable");
72+
let d: IClosable = a.cast()?;
73+
let e: &IInspectable = (&d).into();
74+
assert_eq!(e.GetRuntimeClassName()?, "Windows.Foundation.IClosable");
7875

79-
let f: IInspectable = e.cast()?;
80-
assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
81-
}
82-
assert_eq!(COUNTER, 0);
83-
Ok(())
76+
let f: IInspectable = e.cast()?;
77+
assert_eq!(f.GetRuntimeClassName()?, "Windows.Foundation.IStringable");
8478
}
79+
assert_eq!(COUNTER.load(Ordering::Acquire), 0);
80+
Ok(())
8581
}

0 commit comments

Comments
 (0)