From 48bc59abcae33894986643f3d63cfda6e537e793 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Fri, 22 Nov 2024 11:57:35 -0800 Subject: [PATCH 1/2] style: simplify string formatting for readability --- src/event.rs | 2 +- src/platform_impl/apple/uikit/view.rs | 6 +++--- src/platform_impl/linux/x11/activation.rs | 2 +- src/platform_impl/linux/x11/mod.rs | 20 ++++++++++---------- src/platform_impl/linux/x11/xdisplay.rs | 2 +- src/platform_impl/orbital/window.rs | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/event.rs b/src/event.rs index 7c56417d4a..d3c10f9806 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1298,7 +1298,7 @@ mod tests { #[test] fn ensure_attrs_do_not_panic() { foreach_event!(|event: event::Event| { - let _ = format!("{:?}", event); + let _ = format!("{event:?}"); }); let _ = event::StartCause::Init.clone(); diff --git a/src/platform_impl/apple/uikit/view.rs b/src/platform_impl/apple/uikit/view.rs index 21fa353e4d..1651699d76 100644 --- a/src/platform_impl/apple/uikit/view.rs +++ b/src/platform_impl/apple/uikit/view.rs @@ -195,7 +195,7 @@ declare_class!( // Pass -delta so that action is reversed (TouchPhase::Cancelled, -recognizer.scale()) } - state => panic!("unexpected recognizer state: {:?}", state), + state => panic!("unexpected recognizer state: {state:?}"), }; let gesture_event = EventWrapper::StaticEvent(Event::WindowEvent { @@ -254,7 +254,7 @@ declare_class!( // Pass -delta so that action is reversed (TouchPhase::Cancelled, -recognizer.rotation()) } - state => panic!("unexpected recognizer state: {:?}", state), + state => panic!("unexpected recognizer state: {state:?}"), }; // Make delta negative to match macos, convert to degrees @@ -305,7 +305,7 @@ declare_class!( // Pass -delta so that action is reversed (TouchPhase::Cancelled, -last_pan.x, -last_pan.y) } - state => panic!("unexpected recognizer state: {:?}", state), + state => panic!("unexpected recognizer state: {state:?}"), }; diff --git a/src/platform_impl/linux/x11/activation.rs b/src/platform_impl/linux/x11/activation.rs index 3a3da9e90f..858ded73a5 100644 --- a/src/platform_impl/linux/x11/activation.rs +++ b/src/platform_impl/linux/x11/activation.rs @@ -172,7 +172,7 @@ fn push_display(buffer: &mut Vec, display: &impl std::fmt::Display) { } } - write!(Writer { buffer }, "{}", display).unwrap(); + write!(Writer { buffer }, "{display}").unwrap(); } #[cfg(test)] diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 6f1dae2aa2..11206326df 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -843,24 +843,24 @@ pub enum X11Error { impl fmt::Display for X11Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - X11Error::Xlib(e) => write!(f, "Xlib error: {}", e), - X11Error::Connect(e) => write!(f, "X11 connection error: {}", e), - X11Error::Connection(e) => write!(f, "X11 connection error: {}", e), - X11Error::XidsExhausted(e) => write!(f, "XID range exhausted: {}", e), - X11Error::GetProperty(e) => write!(f, "Failed to get X property {}", e), - X11Error::X11(e) => write!(f, "X11 error: {:?}", e), - X11Error::UnexpectedNull(s) => write!(f, "Xlib function returned null: {}", s), + X11Error::Xlib(e) => write!(f, "Xlib error: {e}"), + X11Error::Connect(e) => write!(f, "X11 connection error: {e}"), + X11Error::Connection(e) => write!(f, "X11 connection error: {e}"), + X11Error::XidsExhausted(e) => write!(f, "XID range exhausted: {e}"), + X11Error::GetProperty(e) => write!(f, "Failed to get X property {e}"), + X11Error::X11(e) => write!(f, "X11 error: {e:?}"), + X11Error::UnexpectedNull(s) => write!(f, "Xlib function returned null: {s}"), X11Error::InvalidActivationToken(s) => write!( f, "Invalid activation token: {}", std::str::from_utf8(s).unwrap_or("") ), - X11Error::MissingExtension(s) => write!(f, "Missing X11 extension: {}", s), + X11Error::MissingExtension(s) => write!(f, "Missing X11 extension: {s}"), X11Error::NoSuchVisual(visualid) => { - write!(f, "Could not find a matching X11 visual for ID `{:x}`", visualid) + write!(f, "Could not find a matching X11 visual for ID `{visualid:x}`") }, X11Error::XsettingsParse(err) => { - write!(f, "Failed to parse xsettings: {:?}", err) + write!(f, "Failed to parse xsettings: {err:?}") }, X11Error::NoArgb32Format => { f.write_str("winit only supports X11 displays with ARGB32 picture formats") diff --git a/src/platform_impl/linux/x11/xdisplay.rs b/src/platform_impl/linux/x11/xdisplay.rs index abce8eb59f..f14e5beb5b 100644 --- a/src/platform_impl/linux/x11/xdisplay.rs +++ b/src/platform_impl/linux/x11/xdisplay.rs @@ -164,7 +164,7 @@ impl XConnection { fn new_xsettings_screen(xcb: &XCBConnection, default_screen: usize) -> Option { // Fetch the _XSETTINGS_S[screen number] atom. let xsettings_screen = xcb - .intern_atom(false, format!("_XSETTINGS_S{}", default_screen).as_bytes()) + .intern_atom(false, format!("_XSETTINGS_S{default_screen}").as_bytes()) .ok()? .reply() .ok()? diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 76c698363d..9da826e560 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -410,7 +410,7 @@ impl CoreWindow for Window { window::ResizeDirection::West => "L", }; self.window_socket - .write(format!("D,{}", arg).as_bytes()) + .write(format!("D,{arg}").as_bytes()) .map_err(|err| os_error!(format!("{err}")))?; Ok(()) } From f72f9a2102e19a83782eefde8d7b9a8f963108d3 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Fri, 22 Nov 2024 12:31:53 -0800 Subject: [PATCH 2/2] guard against future style regression --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index bda0a32ba9..1424519acc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -238,6 +238,7 @@ // doc #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg_hide), doc(cfg_hide(doc, docsrs)))] #![allow(clippy::missing_safety_doc)] +#![warn(clippy::uninlined_format_args)] // Re-export DPI types so that users don't have to put it in Cargo.toml. #[doc(inline)]