Make DeviceId/WindowId::dummy() safe (#3784)
This commit is contained in:
parent
bf97def398
commit
5b8f5cb54a
15 changed files with 28 additions and 33 deletions
15
src/event.rs
15
src/event.rs
|
|
@ -440,16 +440,13 @@ pub struct DeviceId(pub(crate) platform_impl::DeviceId);
|
|||
impl DeviceId {
|
||||
/// Returns a dummy id, useful for unit testing.
|
||||
///
|
||||
/// # Safety
|
||||
/// # Notes
|
||||
///
|
||||
/// The only guarantee made about the return value of this function is that
|
||||
/// it will always be equal to itself and to future values returned by this function.
|
||||
/// No other guarantees are made. This may be equal to a real `DeviceId`.
|
||||
///
|
||||
/// **Passing this into a winit function will result in undefined behavior.**
|
||||
pub const unsafe fn dummy() -> Self {
|
||||
#[allow(unused_unsafe)]
|
||||
DeviceId(unsafe { platform_impl::DeviceId::dummy() })
|
||||
pub const fn dummy() -> Self {
|
||||
DeviceId(platform_impl::DeviceId::dummy())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1013,7 +1010,7 @@ mod tests {
|
|||
($closure:expr) => {{
|
||||
#[allow(unused_mut)]
|
||||
let mut x = $closure;
|
||||
let did = unsafe { event::DeviceId::dummy() };
|
||||
let did = event::DeviceId::dummy();
|
||||
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
|
|
@ -1023,7 +1020,7 @@ mod tests {
|
|||
use crate::window::WindowId;
|
||||
|
||||
// Mainline events.
|
||||
let wid = unsafe { WindowId::dummy() };
|
||||
let wid = WindowId::dummy();
|
||||
x(NewEvents(event::StartCause::Init));
|
||||
x(AboutToWait);
|
||||
x(LoopExiting);
|
||||
|
|
@ -1138,7 +1135,7 @@ mod tests {
|
|||
});
|
||||
let _ = event::StartCause::Init.clone();
|
||||
|
||||
let did = unsafe { crate::event::DeviceId::dummy() }.clone();
|
||||
let did = crate::event::DeviceId::dummy().clone();
|
||||
HashSet::new().insert(did);
|
||||
let mut set = [did, did, did];
|
||||
set.sort_unstable();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue