refactor: enable clippy::std_instead_of_core lint

This commit is contained in:
Benoît CORTIER
2024-11-20 01:28:31 +09:00
committed by Benoît Cortier
parent d26e64e4c2
commit 807eb59b07
74 changed files with 143 additions and 140 deletions
+1 -2
View File
@@ -129,8 +129,7 @@ get_unwrap = "warn"
similar_names = "warn" # Reduce risk of confusing similar names together, and protects against typos when variable shadowing was intended.
str_to_string = "warn"
string_to_string = "warn"
# TODO: std_instead_of_alloc = "warn"
# TODO: std_instead_of_core = "warn"
std_instead_of_core = "warn"
separated_literal_suffix = "warn"
unused_self = "warn"
useless_let_if_seq = "warn"
@@ -70,7 +70,7 @@ impl Sequence for ChannelConnectionSequence {
}
fn step(&mut self, input: &[u8], output: &mut WriteBuf) -> ConnectorResult<Written> {
let (written, next_state) = match std::mem::take(&mut self.state) {
let (written, next_state) = match core::mem::take(&mut self.state) {
ChannelConnectionState::WaitErectDomainRequest => {
let erect_domain_request = ironrdp_core::decode::<X224<mcs::ErectDomainPdu>>(input)
.map_err(ConnectorError::decode)
+2 -2
View File
@@ -1,5 +1,5 @@
use std::any::TypeId;
use std::mem;
use core::any::TypeId;
use core::mem;
use ironrdp_connector::{
encode_x224_packet, reason_err, ConnectorError, ConnectorErrorExt, ConnectorResult, DesktopSize, Sequence, State,
+1 -1
View File
@@ -78,7 +78,7 @@ impl Sequence for FinalizationSequence {
}
fn step(&mut self, input: &[u8], output: &mut WriteBuf) -> ConnectorResult<Written> {
let (written, next_state) = match std::mem::take(&mut self.state) {
let (written, next_state) = match core::mem::take(&mut self.state) {
FinalizationState::WaitSynchronize => {
let synchronize = decode_share_control(input);
+2 -2
View File
@@ -9,7 +9,7 @@ use ironrdp_pdu::PduHint;
// https://github.com/rust-lang/rust/issues/91611
pub trait FramedRead {
type ReadFut<'read>: std::future::Future<Output = io::Result<usize>> + 'read
type ReadFut<'read>: core::future::Future<Output = io::Result<usize>> + 'read
where
Self: 'read;
@@ -24,7 +24,7 @@ pub trait FramedRead {
}
pub trait FramedWrite {
type WriteAllFut<'write>: std::future::Future<Output = io::Result<()>> + 'write
type WriteAllFut<'write>: core::future::Future<Output = io::Result<()>> + 'write
where
Self: 'write;
+2 -2
View File
@@ -12,8 +12,8 @@ mod connector;
mod framed;
mod session;
use std::future::Future;
use std::pin::Pin;
use core::future::Future;
use core::pin::Pin;
use ironrdp_connector::sspi::generator::NetworkRequest;
use ironrdp_connector::ConnectorResult;
+7 -6
View File
@@ -1,8 +1,9 @@
#![allow(clippy::print_stderr, clippy::print_stdout)] // allowed in this module only
use std::num::NonZeroU32;
use core::num::NonZeroU32;
use core::time::Duration;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::Instant;
use raw_window_handle::{DisplayHandle, HasDisplayHandle};
use tokio::sync::mpsc;
@@ -37,7 +38,7 @@ impl App {
// SAFETY: We drop the softbuffer context right before the event loop is stopped, thus making this safe.
// FIXME: This is not a sufficient proof and the API is actually unsound as-is.
let display_handle = unsafe {
std::mem::transmute::<DisplayHandle<'_>, DisplayHandle<'static>>(event_loop.display_handle().unwrap())
core::mem::transmute::<DisplayHandle<'_>, DisplayHandle<'static>>(event_loop.display_handle().unwrap())
};
let context = softbuffer::Context::new(display_handle)
.map_err(|e| anyhow::anyhow!("unable to initialize softbuffer context: {e}"))?;
@@ -165,7 +166,7 @@ impl ApplicationHandler<RdpOutputEvent> for App {
event::ElementState::Released => ironrdp::input::Operation::KeyReleased(scancode),
};
let input_events = self.input_database.apply(std::iter::once(operation));
let input_events = self.input_database.apply(core::iter::once(operation));
send_fast_path_events(&self.input_event_sender, input_events);
}
@@ -202,7 +203,7 @@ impl ApplicationHandler<RdpOutputEvent> for App {
let y = (position.y / win_size.height as f64 * self.buffer_size.1 as f64) as u16;
let operation = ironrdp::input::Operation::MouseMove(ironrdp::input::MousePosition { x, y });
let input_events = self.input_database.apply(std::iter::once(operation));
let input_events = self.input_database.apply(core::iter::once(operation));
send_fast_path_events(&self.input_event_sender, input_events);
}
@@ -275,7 +276,7 @@ impl ApplicationHandler<RdpOutputEvent> for App {
event::ElementState::Released => ironrdp::input::Operation::MouseButtonReleased(mouse_button),
};
let input_events = self.input_database.apply(std::iter::once(operation));
let input_events = self.input_database.apply(core::iter::once(operation));
send_fast_path_events(&self.input_event_sender, input_events);
}
+2 -2
View File
@@ -1,6 +1,6 @@
use core::num::ParseIntError;
use core::str::FromStr;
use std::io;
use std::num::ParseIntError;
use std::str::FromStr;
use anyhow::Context as _;
use clap::clap_derive::ValueEnum;
+2 -2
View File
@@ -1,6 +1,6 @@
use std::future::Future;
use core::future::Future;
use core::pin::Pin;
use std::net::{IpAddr, Ipv4Addr};
use std::pin::Pin;
use ironrdp::connector::{custom_err, ConnectorResult};
use ironrdp_tokio::AsyncNetworkClient;
+1 -1
View File
@@ -83,7 +83,7 @@ pub fn cf_html_to_plain_html(input: &[u8]) -> Result<&str, HtmlError> {
}
}
fn header_value_to_u32(value: &str) -> Result<u32, std::num::ParseIntError> {
fn header_value_to_u32(value: &str) -> Result<u32, core::num::ParseIntError> {
value.trim_start_matches('0').parse::<u32>()
}
}
+1 -1
View File
@@ -111,7 +111,7 @@ pub struct WinClipboard {
/// ```
///
/// Therefore this type should be non-Send and non-Sync to prevent incorrect use.
_thread_marker: std::marker::PhantomData<*const ()>,
_thread_marker: core::marker::PhantomData<*const ()>,
}
impl WinClipboard {
@@ -56,7 +56,7 @@ impl<'a> ClipboardDataRef<'a> {
pub(crate) fn data(&self) -> &[u8] {
let size = self.size();
// SAFETY: `data` pointer is valid during the lifetime of the wrapper
unsafe { std::slice::from_raw_parts(self.data, size) }
unsafe { core::slice::from_raw_parts(self.data, size) }
}
}
@@ -1,6 +1,6 @@
use core::time::Duration;
use std::collections::HashSet;
use std::sync::mpsc;
use std::time::Duration;
use ironrdp_cliprdr::backend::{ClipboardMessage, ClipboardMessageProxy};
use ironrdp_cliprdr::pdu::{ClipboardFormat, ClipboardFormatId, FormatDataRequest, FormatDataResponse};
@@ -165,7 +165,7 @@ impl WinClipboardImpl {
}
};
let formats = std::mem::take(&mut self.available_formats_on_remote);
let formats = core::mem::take(&mut self.available_formats_on_remote);
// Clearing clipboard is not required, just render all available formats
@@ -87,7 +87,7 @@ impl OwnedOsClipboard {
pub(crate) fn delay_render(&mut self, format: ClipboardFormatId) -> Result<(), WinCliprdrError> {
// SAFETY: We own the clipboard at moment of method invocation, therefore it is safe to
// call `SetClipboardData`.
let result = unsafe { SetClipboardData(format.value(), HANDLE(std::ptr::null_mut())) };
let result = unsafe { SetClipboardData(format.value(), HANDLE(core::ptr::null_mut())) };
if let Err(err) = result {
// `windows` crate will return `Err(..)` on err zero handle, but for `SetClipboardData`
@@ -58,7 +58,7 @@ impl RemoteClipboardFormatRegistry {
let format_name_utf16 = format_name
.value()
.encode_utf16()
.chain(std::iter::once(0))
.chain(core::iter::once(0))
.collect::<Vec<_>>();
let format_name_pcwstr = PCWSTR::from_raw(format_name_utf16.as_ptr());
@@ -26,7 +26,7 @@ impl GlobalMemoryBuffer {
// - `dst` is valid for writes of `data.len()` bytes, we allocated enough above.
// - Both `data` and `dst` are properly aligned: u8 alignment is 1
// - Memory regions are not overlapping, `dst` was allocated by us just above.
unsafe { std::ptr::copy_nonoverlapping(data.as_ptr(), dst as *mut u8, data.len()) };
unsafe { core::ptr::copy_nonoverlapping(data.as_ptr(), dst as *mut u8, data.len()) };
// SAFETY: We called `GlobalLock` on this handle just above.
if let Err(error) = unsafe { GlobalUnlock(handle) } {
@@ -67,7 +67,7 @@ pub(crate) unsafe fn render_format(format: ClipboardFormatId, data: &[u8]) -> Wi
// We successfully transferred ownership of the data to the clipboard, we don't need to
// call drop on handle
std::mem::forget(global_data);
core::mem::forget(global_data);
Ok(())
}
+2 -2
View File
@@ -41,12 +41,12 @@ pub enum ClipboardMessage {
/// Proxy to send messages from the os clipboard backend to the main application event loop
/// (e.g. winit event loop).
pub trait ClipboardMessageProxy: std::fmt::Debug + Send {
pub trait ClipboardMessageProxy: core::fmt::Debug + Send {
fn send_clipboard_message(&self, message: ClipboardMessage);
}
/// OS-specific clipboard backend interface.
pub trait CliprdrBackend: AsAny + std::fmt::Debug + Send {
pub trait CliprdrBackend: AsAny + core::fmt::Debug + Send {
/// Returns path to local temporary directory where clipboard-transferred files should be
/// stored.
fn temporary_directory(&self) -> &str;
+3 -3
View File
@@ -50,7 +50,7 @@ enum CliprdrState {
Failed,
}
pub trait Role: std::fmt::Debug + Send + 'static {
pub trait Role: core::fmt::Debug + Send + 'static {
fn is_server() -> bool;
}
@@ -60,7 +60,7 @@ pub struct Cliprdr<R: Role> {
backend: Box<dyn CliprdrBackend>,
capabilities: Capabilities,
state: CliprdrState,
_marker: std::marker::PhantomData<R>,
_marker: core::marker::PhantomData<R>,
}
pub type CliprdrClient = Cliprdr<Client>;
@@ -103,7 +103,7 @@ impl<R: Role> Cliprdr<R> {
backend,
state: CliprdrState::Initialization,
capabilities: Capabilities::new(ClipboardProtocolVersion::V2, flags),
_marker: std::marker::PhantomData,
_marker: core::marker::PhantomData,
}
}
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::mem;
use core::mem;
use ironrdp_core::WriteBuf;
use ironrdp_pdu::{mcs, x224::X224, PduHint};
+1 -1
View File
@@ -1,5 +1,5 @@
use std::borrow::Cow;
use std::mem;
use core::mem;
use std::net::SocketAddr;
use ironrdp_core::{decode, encode_vec, Encode, WriteBuf};

Some files were not shown because too many files have changed in this diff Show More