mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
const-field-offset: fix a bunch of clippy warnings in tests
This commit is contained in:
parent
73ec3e6701
commit
4af34a8de1
3 changed files with 7 additions and 10 deletions
|
@ -17,4 +17,3 @@ field-offset = "0.3.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
memoffset = "0.6"
|
memoffset = "0.6"
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
|
|
@ -100,8 +100,8 @@ mod tests {
|
||||||
// Get a pointer to `b` within `Foo`
|
// Get a pointer to `b` within `Foo`
|
||||||
let foo_b = Foo::FIELD_OFFSETS.b;
|
let foo_b = Foo::FIELD_OFFSETS.b;
|
||||||
let foo_b_pin = unsafe { foo_b.as_pinned_projection() };
|
let foo_b_pin = unsafe { foo_b.as_pinned_projection() };
|
||||||
let foo = Box::pin(Foo { a: 21, b: 22.0, c: true });
|
let foo_object = Box::pin(Foo { a: 21, b: 22.0, c: true });
|
||||||
let pb: Pin<&f64> = foo_b_pin.apply_pin(foo.as_ref());
|
let pb: Pin<&f64> = foo_b_pin.apply_pin(foo_object.as_ref());
|
||||||
assert_eq!(*pb, 22.0);
|
assert_eq!(*pb, 22.0);
|
||||||
|
|
||||||
let mut x = Box::pin(Bar { x: 0, y: Foo { a: 1, b: 52.0, c: false } });
|
let mut x = Box::pin(Bar { x: 0, y: Foo { a: 1, b: 52.0, c: false } });
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
Please contact info@sixtyfps.io for more information.
|
Please contact info@sixtyfps.io for more information.
|
||||||
LICENSE END */
|
LICENSE END */
|
||||||
use const_field_offset::*;
|
use const_field_offset::*;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use memoffset::offset_of;
|
use memoffset::offset_of;
|
||||||
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
|
|
||||||
#[derive(FieldOffsets)]
|
#[derive(FieldOffsets)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -111,9 +111,7 @@ fn test_pin() {
|
||||||
assert_eq!(D_STATIC_PIN, offset_of!(MyStructPin, d));
|
assert_eq!(D_STATIC_PIN, offset_of!(MyStructPin, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static DROP_CALLED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||||
static ref DROP_CALLED: std::sync::Mutex<bool> = std::sync::Mutex::new(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FieldOffsets)]
|
#[derive(FieldOffsets)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -125,15 +123,15 @@ struct MyPinnedStructWithDrop {
|
||||||
|
|
||||||
impl PinnedDrop for MyPinnedStructWithDrop {
|
impl PinnedDrop for MyPinnedStructWithDrop {
|
||||||
fn drop(self: core::pin::Pin<&mut MyPinnedStructWithDrop>) {
|
fn drop(self: core::pin::Pin<&mut MyPinnedStructWithDrop>) {
|
||||||
*DROP_CALLED.lock().unwrap() = true;
|
DROP_CALLED.store(true, SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pin_drop() {
|
fn test_pin_drop() {
|
||||||
*DROP_CALLED.lock().unwrap() = false;
|
DROP_CALLED.store(false, SeqCst);
|
||||||
{
|
{
|
||||||
let _instance = Box::pin(MyPinnedStructWithDrop { x: 42 });
|
let _instance = Box::pin(MyPinnedStructWithDrop { x: 42 });
|
||||||
}
|
}
|
||||||
assert!(*DROP_CALLED.lock().unwrap());
|
assert!(DROP_CALLED.load(SeqCst));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue