diff --git a/clippy.toml b/clippy.toml index 74ba0ee0a..2dd9d6036 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,4 +1,11 @@ # Using allow-invalid because this is platform-specific code +disallowed-macros = [ + { path = "std::print", reason = "works badly on web", replacement = "tracing::info" }, + { path = "std::println", reason = "works badly on web", replacement = "tracing::info" }, + { path = "std::eprint", reason = "works badly on web", replacement = "tracing::error" }, + { path = "std::eprintln", reason = "works badly on web", replacement = "tracing::error" }, + { path = "std::dbg", reason = "leftover debugging aid, remove it or use tracing" }, +] disallowed-methods = [ { allow-invalid = true, path = "objc2_app_kit::NSView::visibleRect", reason = "We expose a render target to the user, and visibility is not really relevant to that (and can break if you don't use the rectangle position as well). Use `frame` instead." }, { allow-invalid = true, path = "objc2_app_kit::NSWindow::setFrameTopLeftPoint", reason = "Not sufficient when working with Winit's coordinate system, use `flip_window_screen_coordinates` instead" }, diff --git a/winit-common/src/event_handler.rs b/winit-common/src/event_handler.rs index 51d1b12ca..f19d2f218 100644 --- a/winit-common/src/event_handler.rs +++ b/winit-common/src/event_handler.rs @@ -79,6 +79,10 @@ impl EventHandler { // Allowed, happens if the handler was cleared manually // elsewhere (such as in `applicationWillTerminate:`). }, + // We use `eprintln!` here over `tracing::error!`, since we're going to abort + // immediately after this, and it'd be annoying for the user if they didn't get + // any feedback on that if they don't have a tracing subscriber. + #[allow(clippy::disallowed_macros)] Err(_) => { // Note: This is not expected to ever happen, this // module generally controls the `RefCell`, and diff --git a/winit-win32/src/keyboard_layout.rs b/winit-win32/src/keyboard_layout.rs index 7b6a370fd..f9dda3d3c 100644 --- a/winit-win32/src/keyboard_layout.rs +++ b/winit-win32/src/keyboard_layout.rs @@ -387,11 +387,7 @@ impl LayoutCache { let unicode = Self::to_unicode_string(&key_state, vk, scancode, locale_id); let key = match unicode { ToUnicodeResult::Str(str) => Key::Character(SmolStr::new(str)), - ToUnicodeResult::Dead(dead_char) => { - // println!("{:?} - {:?} produced dead {:?}", key_code, mod_state, - // dead_char); - Key::Dead(dead_char) - }, + ToUnicodeResult::Dead(dead_char) => Key::Dead(dead_char), ToUnicodeResult::None => { let has_alt = mod_state.contains(WindowsModifiers::ALT); let has_ctrl = mod_state.contains(WindowsModifiers::CONTROL); diff --git a/winit-x11/src/util/mod.rs b/winit-x11/src/util/mod.rs index 78ccfe091..41d0fca3d 100644 --- a/winit-x11/src/util/mod.rs +++ b/winit-x11/src/util/mod.rs @@ -66,7 +66,6 @@ impl XConnection { // All util functions that abstract an async function will return a `Flusher`. pub fn flush_requests(&self) -> Result<(), XError> { unsafe { (self.xlib.XFlush)(self.display) }; - // println!("XFlush"); // This isn't necessarily a useful time to check for errors (since our request hasn't // necessarily been processed yet) self.check_errors() @@ -74,7 +73,6 @@ impl XConnection { pub fn sync_with_server(&self) -> Result<(), XError> { unsafe { (self.xlib.XSync)(self.display, ffi::False) }; - // println!("XSync"); self.check_errors() } } diff --git a/winit/build.rs b/winit/build.rs index 1105d584e..93ce11e4f 100644 --- a/winit/build.rs +++ b/winit/build.rs @@ -1,7 +1,9 @@ use cfg_aliases::cfg_aliases; +// Only relevant for examples and Winit, our usage of println! is fine here. +#[allow(clippy::disallowed_macros)] fn main() { - // The script doesn't depend on our code. + // Dummy invocation to enable change-tracking in build scripts. println!("cargo:rerun-if-changed=build.rs"); // Setup cfg aliases. diff --git a/winit/examples/child_window.rs b/winit/examples/child_window.rs index e87207828..4077bca36 100644 --- a/winit/examples/child_window.rs +++ b/winit/examples/child_window.rs @@ -3,6 +3,7 @@ fn main() -> Result<(), impl std::error::Error> { use std::collections::HashMap; + use tracing::info; use winit::application::ApplicationHandler; use winit::dpi::{LogicalPosition, LogicalSize, Position}; use winit::event::{ElementState, KeyEvent, WindowEvent}; @@ -38,7 +39,7 @@ fn main() -> Result<(), impl std::error::Error> { .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) .with_surface_size(LogicalSize::new(640.0f32, 480.0f32)); let window = event_loop.create_window(attributes).unwrap(); - println!("Parent window id: {:?})", window.id()); + info!("Parent window id: {:?})", window.id()); self.parent_window_id = Some(window.id()); self.windows.insert(window.id(), WindowData::new(window, 0xffbbbbbb)); @@ -56,12 +57,12 @@ fn main() -> Result<(), impl std::error::Error> { event_loop.exit(); }, WindowEvent::PointerEntered { device_id: _, .. } => { - // On x11, println when the cursor entered in a window even if the child window + // On x11, log when the cursor entered in a window even if the child window // is created by some key inputs. // the child windows are always placed at (0, 0) with size (200, 200) in the // parent window, so we also can see this log when we move // the cursor around (200, 200) in parent window. - println!("cursor entered in the window {window_id:?}"); + info!("cursor entered in the window {window_id:?}"); }, WindowEvent::KeyboardInput { event: KeyEvent { state: ElementState::Pressed, .. }, @@ -75,7 +76,7 @@ fn main() -> Result<(), impl std::error::Error> { let child_window = spawn_child_window(parent_window.window.as_ref(), event_loop, child_index); let child_id = child_window.id(); - println!("Child window created with id: {child_id:?}"); + info!("Child window created with id: {child_id:?}"); self.windows.insert(child_id, WindowData::new(child_window, child_color)); }, WindowEvent::RedrawRequested => { diff --git a/winit/examples/control_flow.rs b/winit/examples/control_flow.rs index 8fb09bb3f..04e6a04d6 100644 --- a/winit/examples/control_flow.rs +++ b/winit/examples/control_flow.rs @@ -4,7 +4,7 @@ use std::thread; #[cfg(not(web_platform))] use std::time; -use ::tracing::{info, warn}; +use tracing::{info, warn}; #[cfg(web_platform)] use web_time as time; use winit::application::ApplicationHandler; diff --git a/winit/examples/dnd.rs b/winit/examples/dnd.rs index 8b21743bb..c8d033265 100644 --- a/winit/examples/dnd.rs +++ b/winit/examples/dnd.rs @@ -1,5 +1,6 @@ use std::error::Error; +use tracing::info; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; @@ -49,7 +50,7 @@ impl ApplicationHandler for Application { | WindowEvent::DragEntered { .. } | WindowEvent::DragMoved { .. } | WindowEvent::DragDropped { .. } => { - println!("{event:?}"); + info!("{event:?}"); }, WindowEvent::RedrawRequested => { let window = self.window.as_ref().unwrap(); diff --git a/winit/examples/ime.rs b/winit/examples/ime.rs index c2251fe9e..1aee54f11 100644 --- a/winit/examples/ime.rs +++ b/winit/examples/ime.rs @@ -76,7 +76,7 @@ impl ApplicationHandler for App { self.window = match event_loop.create_window(window_attributes) { Ok(window) => Some(window), Err(err) => { - eprintln!("error creating window: {err}"); + error!("error creating window: {err}"); event_loop.exit(); return; }, @@ -346,7 +346,7 @@ fn main() -> Result<(), Box> { let event_loop = EventLoop::new()?; - println!( + info!( r#"This showcases the use of an input method engine (IME) by emulating a text edit field. Use CTRL+i to toggle IME support. Use CTRL+p to cycle content purpose values. diff --git a/winit/examples/pump_events.rs b/winit/examples/pump_events.rs index 39885eb03..b8f05a050 100644 --- a/winit/examples/pump_events.rs +++ b/winit/examples/pump_events.rs @@ -7,6 +7,7 @@ fn main() -> std::process::ExitCode { use std::thread::sleep; use std::time::Duration; + use tracing::info; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::pump_events::{EventLoopExtPumpEvents, PumpStatus}; @@ -33,7 +34,7 @@ fn main() -> std::process::ExitCode { _window_id: WindowId, event: WindowEvent, ) { - println!("{event:?}"); + info!("{event:?}"); let window = match self.window.as_ref() { Some(window) => window, @@ -69,12 +70,12 @@ fn main() -> std::process::ExitCode { // // Since `pump_events` doesn't block it will be important to // throttle the loop in the app somehow. - println!("Update()"); + info!("Update()"); sleep(Duration::from_millis(16)); } } #[cfg(any(ios_platform, web_platform, orbital_platform))] fn main() { - println!("This platform doesn't support pump_events."); + panic!("This platform doesn't support pump_events.") } diff --git a/winit/examples/run_on_demand.rs b/winit/examples/run_on_demand.rs index f25bfc593..194f81a0f 100644 --- a/winit/examples/run_on_demand.rs +++ b/winit/examples/run_on_demand.rs @@ -5,6 +5,7 @@ fn main() -> Result<(), Box> { use std::time::Duration; + use tracing::info; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand; @@ -44,10 +45,7 @@ fn main() -> Result<(), Box> { event: WindowEvent, ) { if event == WindowEvent::Destroyed && self.window_id == Some(window_id) { - println!( - "--------------------------------------------------------- Window {} Destroyed", - self.idx - ); + info!("Window {} Destroyed", self.idx); self.window_id = None; event_loop.exit(); return; @@ -60,11 +58,7 @@ fn main() -> Result<(), Box> { match event { WindowEvent::CloseRequested => { - println!( - "--------------------------------------------------------- Window {} \ - CloseRequested", - self.idx - ); + info!("Window {} CloseRequested", self.idx); fill::cleanup_window(window.as_ref()); self.window = None; }, @@ -83,13 +77,13 @@ fn main() -> Result<(), Box> { let mut app = App { idx: 1, ..Default::default() }; event_loop.run_app_on_demand(&mut app)?; - println!("--------------------------------------------------------- Finished first loop"); - println!("--------------------------------------------------------- Waiting 5 seconds"); + info!("Finished first loop"); + info!("Waiting 5 seconds"); std::thread::sleep(Duration::from_secs(5)); app.idx += 1; event_loop.run_app_on_demand(&mut app)?; - println!("--------------------------------------------------------- Finished second loop"); + info!("Finished second loop"); Ok(()) } @@ -101,5 +95,5 @@ fn main() -> Result<(), Box> { orbital_platform )))] fn main() { - println!("This example is not supported on this platform"); + panic!("This example is not supported on this platform") } diff --git a/winit/examples/util/tracing.rs b/winit/examples/util/tracing.rs index bab7ced71..e1d36dcf3 100644 --- a/winit/examples/util/tracing.rs +++ b/winit/examples/util/tracing.rs @@ -23,3 +23,6 @@ pub fn init() { ) .init(); } + +#[allow(unused_imports)] +pub use ::tracing::*; diff --git a/winit/examples/window.rs b/winit/examples/window.rs index 76c60c39e..7d9fc59f4 100644 --- a/winit/examples/window.rs +++ b/winit/examples/window.rs @@ -2,6 +2,7 @@ use std::error::Error; +use tracing::{error, info}; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; @@ -29,7 +30,7 @@ impl ApplicationHandler for App { self.window = match event_loop.create_window(window_attributes) { Ok(window) => Some(window), Err(err) => { - eprintln!("error creating window: {err}"); + error!("error creating window: {err}"); event_loop.exit(); return; }, @@ -37,10 +38,10 @@ impl ApplicationHandler for App { } fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _: WindowId, event: WindowEvent) { - println!("{event:?}"); + info!("{event:?}"); match event { WindowEvent::CloseRequested => { - println!("Close was requested; stopping"); + info!("Close was requested; stopping"); event_loop.exit(); }, WindowEvent::SurfaceResized(_) => { diff --git a/winit/examples/x11_embed.rs b/winit/examples/x11_embed.rs index c047f71ef..dd454de7c 100644 --- a/winit/examples/x11_embed.rs +++ b/winit/examples/x11_embed.rs @@ -66,6 +66,5 @@ fn main() -> Result<(), Box> { #[cfg(not(x11_platform))] fn main() -> Result<(), Box> { - println!("This example is only supported on X11 platforms."); - Ok(()) + panic!("This example is only supported on X11 platforms.") }