Fix: Clippy lint 'uninlined_format_args'

This commit is contained in:
13r0ck 2023-01-27 13:25:04 -07:00
parent e6092e81a4
commit 42b1bfe66d
25 changed files with 47 additions and 54 deletions

View file

@ -177,7 +177,7 @@ impl Download {
.into() .into()
} }
State::Downloading { .. } => { State::Downloading { .. } => {
text(format!("Downloading... {:.2}%", current_progress)).into() text(format!("Downloading... {current_progress:.2}%")).into()
} }
State::Errored => column![ State::Errored => column![
"Something went wrong :(", "Something went wrong :(",

View file

@ -77,7 +77,7 @@ impl Application for Events {
let events = Column::with_children( let events = Column::with_children(
self.last self.last
.iter() .iter()
.map(|event| text(format!("{:?}", event)).size(40)) .map(|event| text(format!("{event:?}")).size(40))
.map(Element::from) .map(Element::from)
.collect(), .collect(),
); );

View file

@ -176,7 +176,7 @@ fn view_controls<'a>(
let speed_controls = row![ let speed_controls = row![
slider(1.0..=1000.0, speed as f32, Message::SpeedChanged), slider(1.0..=1000.0, speed as f32, Message::SpeedChanged),
text(format!("x{}", speed)).size(16), text(format!("x{speed}")).size(16),
] ]
.width(Length::Fill) .width(Length::Fill)
.align_items(Alignment::Center) .align_items(Alignment::Center)

View file

@ -90,7 +90,7 @@ impl Program for Controls {
) )
.push(sliders) .push(sliders)
.push( .push(
Text::new(format!("{:?}", background_color)) Text::new(format!("{background_color:?}"))
.size(14) .size(14)
.style(Color::WHITE), .style(Color::WHITE),
), ),

View file

@ -49,7 +49,7 @@ impl Scene {
.expect("Cannot create shader"); .expect("Cannot create shader");
gl.shader_source( gl.shader_source(
shader, shader,
&format!("{}\n{}", shader_version, shader_source), &format!("{shader_version}\n{shader_source}"),
); );
gl.compile_shader(shader); gl.compile_shader(shader);
if !gl.get_shader_compile_status(shader) { if !gl.get_shader_compile_status(shader) {

View file

@ -96,7 +96,7 @@ impl Program for Controls {
) )
.push(sliders) .push(sliders)
.push( .push(
Text::new(format!("{:?}", background_color)) Text::new(format!("{background_color:?}"))
.size(14) .size(14)
.style(Color::WHITE), .style(Color::WHITE),
) )

View file

@ -274,7 +274,7 @@ pub fn main() {
} }
Err(error) => match error { Err(error) => match error {
wgpu::SurfaceError::OutOfMemory => { wgpu::SurfaceError::OutOfMemory => {
panic!("Swapchain error: {}. Rendering cannot continue.", error) panic!("Swapchain error: {error}. Rendering cannot continue.")
} }
_ => { _ => {
// Try rendering again next frame. // Try rendering again next frame.

View file

@ -41,7 +41,7 @@ impl Application for Pokedex {
Pokedex::Errored { .. } => "Whoops!", Pokedex::Errored { .. } => "Whoops!",
}; };
format!("{} - Pokédex", subtitle) format!("{subtitle} - Pokédex")
} }
fn update(&mut self, message: Message) -> Command<Message> { fn update(&mut self, message: Message) -> Command<Message> {
@ -157,8 +157,7 @@ impl Pokemon {
}; };
let fetch_entry = async { let fetch_entry = async {
let url = let url = format!("https://pokeapi.co/api/v2/pokemon-species/{id}");
format!("https://pokeapi.co/api/v2/pokemon-species/{}", id);
reqwest::get(&url).await?.json().await reqwest::get(&url).await?.json().await
}; };
@ -187,8 +186,7 @@ impl Pokemon {
async fn fetch_image(id: u16) -> Result<image::Handle, reqwest::Error> { async fn fetch_image(id: u16) -> Result<image::Handle, reqwest::Error> {
let url = format!( let url = format!(
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{id}.png"
id
); );
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]

View file

@ -78,7 +78,7 @@ impl Sandbox for Styling {
column![text("Choose a theme:")].spacing(10), column![text("Choose a theme:")].spacing(10),
|column, theme| { |column, theme| {
column.push(radio( column.push(radio(
format!("{:?}", theme), format!("{theme:?}"),
*theme, *theme,
Some(match self.theme { Some(match self.theme {
Theme::Light => ThemeType::Light, Theme::Light => ThemeType::Light,

View file

@ -114,13 +114,12 @@ impl Application for Example {
{ {
let memory_readable = ByteSize::kb(memory_used).to_string(); let memory_readable = ByteSize::kb(memory_used).to_string();
format!("{} kb ({})", memory_used, memory_readable) format!("{memory_used} kb ({memory_readable})")
} else { } else {
String::from("None") String::from("None")
}; };
let memory_used = let memory_used = text(format!("Memory (used): {memory_text}"));
text(format!("Memory (used): {}", memory_text));
let graphics_adapter = text(format!( let graphics_adapter = text(format!(
"Graphics adapter: {}", "Graphics adapter: {}",

View file

@ -303,7 +303,7 @@ pub enum TaskMessage {
impl Task { impl Task {
fn text_input_id(i: usize) -> text_input::Id { fn text_input_id(i: usize) -> text_input::Id {
text_input::Id::new(format!("task-{}", i)) text_input::Id::new(format!("task-{i}"))
} }
fn new(description: String) -> Self { fn new(description: String) -> Self {

View file

@ -388,7 +388,7 @@ impl<'a> Step {
let spacing_section = column![ let spacing_section = column![
slider(0..=80, spacing, StepMessage::SpacingChanged), slider(0..=80, spacing, StepMessage::SpacingChanged),
text(format!("{} px", spacing)) text(format!("{spacing} px"))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center), .horizontal_alignment(alignment::Horizontal::Center),
] ]
@ -412,7 +412,7 @@ impl<'a> Step {
fn text(size: u16, color: Color) -> Column<'a, StepMessage> { fn text(size: u16, color: Color) -> Column<'a, StepMessage> {
let size_section = column![ let size_section = column![
"You can change its size:", "You can change its size:",
text(format!("This text is {} pixels", size)).size(size), text(format!("This text is {size} pixels")).size(size),
slider(10..=70, size, StepMessage::TextSizeChanged), slider(10..=70, size, StepMessage::TextSizeChanged),
] ]
.padding(20) .padding(20)
@ -427,7 +427,7 @@ impl<'a> Step {
let color_section = column![ let color_section = column![
"And its color:", "And its color:",
text(format!("{:?}", color)).style(color), text(format!("{color:?}")).style(color),
color_sliders, color_sliders,
] ]
.padding(20) .padding(20)
@ -497,7 +497,7 @@ impl<'a> Step {
.push(ferris(width)) .push(ferris(width))
.push(slider(100..=500, width, StepMessage::ImageWidthChanged)) .push(slider(100..=500, width, StepMessage::ImageWidthChanged))
.push( .push(
text(format!("Width: {} px", width)) text(format!("Width: {width} px"))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )

View file

@ -141,7 +141,7 @@ impl fmt::Display for Message {
Message::Disconnected => { Message::Disconnected => {
write!(f, "Connection lost... Retrying...") write!(f, "Connection lost... Retrying...")
} }
Message::User(message) => write!(f, "{}", message), Message::User(message) => write!(f, "{message}"),
} }
} }
} }

View file

@ -41,7 +41,7 @@ async fn user_connected(ws: WebSocket) {
tokio::task::spawn(async move { tokio::task::spawn(async move {
while let Some(message) = rx.next().await { while let Some(message) = rx.next().await {
user_ws_tx.send(message).await.unwrap_or_else(|e| { user_ws_tx.send(message).await.unwrap_or_else(|e| {
eprintln!("websocket send error: {}", e); eprintln!("websocket send error: {e}");
}); });
} }
}); });

View file

@ -54,7 +54,7 @@ impl Version {
String::from("#version 120\n#define in varying"), String::from("#version 120\n#define in varying"),
), ),
// OpenGL 1.1+ // OpenGL 1.1+
_ => panic!("Incompatible context version: {:?}", version), _ => panic!("Incompatible context version: {version:?}"),
}; };
log::info!("Shader directive: {}", vertex.lines().next().unwrap()); log::info!("Shader directive: {}", vertex.lines().next().unwrap());

View file

@ -58,10 +58,10 @@ impl<T> fmt::Debug for Action<T> {
match self { match self {
Self::Future(_) => write!(f, "Action::Future"), Self::Future(_) => write!(f, "Action::Future"),
Self::Clipboard(action) => { Self::Clipboard(action) => {
write!(f, "Action::Clipboard({:?})", action) write!(f, "Action::Clipboard({action:?})")
} }
Self::Window(action) => write!(f, "Action::Window({:?})", action), Self::Window(action) => write!(f, "Action::Window({action:?})"),
Self::System(action) => write!(f, "Action::System({:?})", action), Self::System(action) => write!(f, "Action::System({action:?})"),
Self::Widget(_action) => write!(f, "Action::Widget"), Self::Widget(_action) => write!(f, "Action::Widget"),
} }
} }

View file

@ -133,7 +133,7 @@ impl Debug {
} }
pub fn log_message<Message: std::fmt::Debug>(&mut self, message: &Message) { pub fn log_message<Message: std::fmt::Debug>(&mut self, message: &Message) {
self.last_messages.push_back(format!("{:?}", message)); self.last_messages.push_back(format!("{message:?}"));
if self.last_messages.len() > 10 { if self.last_messages.len() > 10 {
let _ = self.last_messages.pop_front(); let _ = self.last_messages.pop_front();
@ -150,7 +150,7 @@ impl Debug {
let mut lines = Vec::new(); let mut lines = Vec::new();
fn key_value<T: std::fmt::Debug>(key: &str, value: T) -> String { fn key_value<T: std::fmt::Debug>(key: &str, value: T) -> String {
format!("{} {:?}", key, value) format!("{key} {value:?}")
} }
lines.push(format!( lines.push(format!(
@ -176,9 +176,9 @@ impl Debug {
lines.push(String::from("Last messages:")); lines.push(String::from("Last messages:"));
lines.extend(self.last_messages.iter().map(|msg| { lines.extend(self.last_messages.iter().map(|msg| {
if msg.len() <= 100 { if msg.len() <= 100 {
format!(" {}", msg) format!(" {msg}")
} else { } else {
format!(" {:.100}...", msg) format!(" {msg:.100}...")
} }
})); }));

View file

@ -107,10 +107,10 @@ pub enum Data {
impl std::fmt::Debug for Data { impl std::fmt::Debug for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Data::Path(path) => write!(f, "Path({:?})", path), Data::Path(path) => write!(f, "Path({path:?})"),
Data::Bytes(_) => write!(f, "Bytes(...)"), Data::Bytes(_) => write!(f, "Bytes(...)"),
Data::Rgba { width, height, .. } => { Data::Rgba { width, height, .. } => {
write!(f, "Pixels({} * {})", width, height) write!(f, "Pixels({width} * {height})")
} }
} }
} }

View file

@ -71,7 +71,7 @@ pub enum Data {
impl std::fmt::Debug for Data { impl std::fmt::Debug for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Data::Path(path) => write!(f, "Path({:?})", path), Data::Path(path) => write!(f, "Path({path:?})"),
Data::Bytes(_) => write!(f, "Bytes(...)"), Data::Bytes(_) => write!(f, "Bytes(...)"),
} }
} }

View file

@ -62,7 +62,7 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::None => write!(f, "Outcome::None"), Self::None => write!(f, "Outcome::None"),
Self::Some(output) => write!(f, "Outcome::Some({:?})", output), Self::Some(output) => write!(f, "Outcome::Some({output:?})"),
Self::Chain(_) => write!(f, "Outcome::Chain(...)"), Self::Chain(_) => write!(f, "Outcome::Chain(...)"),
} }
} }

View file

@ -106,15 +106,14 @@ impl<T> fmt::Debug for Action<T> {
Self::Drag => write!(f, "Action::Drag"), Self::Drag => write!(f, "Action::Drag"),
Self::Resize { width, height } => write!( Self::Resize { width, height } => write!(
f, f,
"Action::Resize {{ widget: {}, height: {} }}", "Action::Resize {{ widget: {width}, height: {height} }}"
width, height
), ),
Self::Maximize(value) => write!(f, "Action::Maximize({})", value), Self::Maximize(value) => write!(f, "Action::Maximize({value})"),
Self::Minimize(value) => write!(f, "Action::Minimize({}", value), Self::Minimize(value) => write!(f, "Action::Minimize({value}"),
Self::Move { x, y } => { Self::Move { x, y } => {
write!(f, "Action::Move {{ x: {}, y: {} }}", x, y) write!(f, "Action::Move {{ x: {x}, y: {y} }}")
} }
Self::SetMode(mode) => write!(f, "Action::SetMode({:?})", mode), Self::SetMode(mode) => write!(f, "Action::SetMode({mode:?})"),
Self::FetchMode(_) => write!(f, "Action::FetchMode"), Self::FetchMode(_) => write!(f, "Action::FetchMode"),
Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"), Self::ToggleMaximize => write!(f, "Action::ToggleMaximize"),
Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"), Self::ToggleDecorations => write!(f, "Action::ToggleDecorations"),

View file

@ -133,10 +133,9 @@ impl fmt::Display for Error {
Error::InvalidData { byte_count } => { Error::InvalidData { byte_count } => {
write!( write!(
f, f,
"The provided RGBA data (with length {:?}) isn't divisble by \ "The provided RGBA data (with length {byte_count:?}) isn't divisble by \
4. Therefore, it cannot be safely interpreted as 32bpp RGBA \ 4. Therefore, it cannot be safely interpreted as 32bpp RGBA \
pixels.", pixels."
byte_count,
) )
} }
Error::DimensionsMismatch { Error::DimensionsMismatch {
@ -146,20 +145,18 @@ impl fmt::Display for Error {
} => { } => {
write!( write!(
f, f,
"The number of RGBA pixels ({:?}) does not match the provided \ "The number of RGBA pixels ({pixel_count:?}) does not match the provided \
dimensions ({:?}x{:?}).", dimensions ({width:?}x{height:?})."
pixel_count, width, height,
) )
} }
Error::OsError(e) => write!( Error::OsError(e) => write!(
f, f,
"The underlying OS failed to create the window \ "The underlying OS failed to create the window \
icon: {:?}", icon: {e:?}"
e
), ),
#[cfg(feature = "image_rs")] #[cfg(feature = "image_rs")]
Error::ImageError(e) => { Error::ImageError(e) => {
write!(f, "Unable to create icon from a file: {:?}", e) write!(f, "Unable to create icon from a file: {e:?}")
} }
} }
} }

View file

@ -83,7 +83,7 @@ fn backend_from_env() -> Option<wgpu::Backends> {
"gl" => wgpu::Backends::GL, "gl" => wgpu::Backends::GL,
"webgpu" => wgpu::Backends::BROWSER_WEBGPU, "webgpu" => wgpu::Backends::BROWSER_WEBGPU,
"primary" => wgpu::Backends::PRIMARY, "primary" => wgpu::Backends::PRIMARY,
other => panic!("Unknown backend: {}", other), other => panic!("Unknown backend: {other}"),
} }
}) })
} }

View file

@ -535,7 +535,7 @@ async fn run_instance<A, E, C>(
Err(error) => match error { Err(error) => match error {
// This is an unrecoverable error. // This is an unrecoverable error.
compositor::SurfaceError::OutOfMemory => { compositor::SurfaceError::OutOfMemory => {
panic!("{:?}", error); panic!("{error:?}");
} }
_ => { _ => {
debug.render_finished(); debug.render_finished();

View file

@ -49,8 +49,8 @@ impl Profiler {
.to_str() .to_str()
.unwrap_or("trace"); .unwrap_or("trace");
let path = out_dir let path =
.join(format!("{}_trace_{}.json", curr_exe_name, time)); out_dir.join(format!("{curr_exe_name}_trace_{time}.json"));
layer = layer.file(path); layer = layer.file(path);
} else { } else {