Skip to content

Commit 3ff1b09

Browse files
Apply even more of clippy's fixes
Expands neovide#1759. I don't know why the PR didn't contain everything, but here we go.
1 parent 29155b1 commit 3ff1b09

File tree

14 files changed

+58
-67
lines changed

14 files changed

+58
-67
lines changed

neovide-derive/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syn::{parse_macro_input, Attribute, Data, DataStruct, DeriveInput, Error, Id
66
pub fn setting_group(item: TokenStream) -> TokenStream {
77
let input = parse_macro_input!(item as DeriveInput);
88
let prefix = setting_prefix(input.attrs.as_ref())
9-
.map(|p| format!("{}_", p))
9+
.map(|p| format!("{p}_"))
1010
.unwrap_or_else(|| "".to_string());
1111
stream(input, prefix)
1212
}
@@ -27,7 +27,7 @@ fn stream(input: DeriveInput, prefix: String) -> TokenStream {
2727
fn struct_stream(name: Ident, prefix: String, data: &DataStruct) -> TokenStream {
2828
let fragments = data.fields.iter().map(|field| match field.ident {
2929
Some(ref ident) => {
30-
let vim_setting_name = format!("{}{}", prefix, ident);
30+
let vim_setting_name = format!("{prefix}{ident}");
3131
quote! {{
3232
fn update_func(value: rmpv::Value) {
3333
let mut s = crate::settings::SETTINGS.get::<#name>();

src/bridge/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn create_platform_shell_command(command: &str, args: &[&str]) -> Option<StdComm
5757
Some(result)
5858
} else if cfg!(target_os = "macos") {
5959
let shell = env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
60-
let mut result = StdCommand::new(&shell);
60+
let mut result = StdCommand::new(shell);
6161

6262
result.arg("-c");
6363
if env::var_os("TERM").is_none() {

src/bridge/events.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ type Result<T> = std::result::Result<T, ParseError>;
2727
impl fmt::Display for ParseError {
2828
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2929
match self {
30-
ParseError::Array(value) => write!(f, "invalid array format {}", value),
31-
ParseError::Map(value) => write!(f, "invalid map format {}", value),
32-
ParseError::String(value) => write!(f, "invalid string format {}", value),
33-
ParseError::U64(value) => write!(f, "invalid u64 format {}", value),
34-
ParseError::I64(value) => write!(f, "invalid i64 format {}", value),
35-
ParseError::F64(value) => write!(f, "invalid f64 format {}", value),
36-
ParseError::Bool(value) => write!(f, "invalid bool format {}", value),
30+
ParseError::Array(value) => write!(f, "invalid array format {value}"),
31+
ParseError::Map(value) => write!(f, "invalid map format {value}"),
32+
ParseError::String(value) => write!(f, "invalid string format {value}"),
33+
ParseError::U64(value) => write!(f, "invalid u64 format {value}"),
34+
ParseError::I64(value) => write!(f, "invalid i64 format {value}"),
35+
ParseError::F64(value) => write!(f, "invalid f64 format {value}"),
36+
ParseError::Bool(value) => write!(f, "invalid bool format {value}"),
3737
ParseError::WindowAnchor(value) => {
38-
write!(f, "invalid window anchor format {}", value)
38+
write!(f, "invalid window anchor format {value}")
3939
}
4040
ParseError::Format(debug_text) => {
41-
write!(f, "invalid event format {}", debug_text)
41+
write!(f, "invalid event format {debug_text}")
4242
}
4343
}
4444
}
@@ -291,7 +291,7 @@ fn unpack_color(packed_color: u64) -> Color4f {
291291

292292
fn extract_values<const REQ: usize>(values: Vec<Value>) -> Result<[Value; REQ]> {
293293
if REQ > values.len() {
294-
Err(ParseError::Format(format!("{:?}", values)))
294+
Err(ParseError::Format(format!("{values:?}")))
295295
} else {
296296
let mut required_values = vec![Value::Nil; REQ];
297297

@@ -309,7 +309,7 @@ fn extract_values_with_optional<const REQ: usize, const OPT: usize>(
309309
values: Vec<Value>,
310310
) -> Result<([Value; REQ], [Option<Value>; OPT])> {
311311
if REQ > values.len() {
312-
Err(ParseError::Format(format!("{:?}", values)))
312+
Err(ParseError::Format(format!("{values:?}")))
313313
} else {
314314
let mut required_values = vec![Value::Nil; REQ];
315315
let mut optional_values = vec![None; OPT];
@@ -541,7 +541,7 @@ fn parse_grid_line_cell(grid_line_cell: Value) -> Result<GridLineCell> {
541541
let text_value = cell_contents
542542
.first_mut()
543543
.map(take_value)
544-
.ok_or_else(|| ParseError::Format(format!("{:?}", cell_contents)))?;
544+
.ok_or_else(|| ParseError::Format(format!("{cell_contents:?}")))?;
545545

546546
let highlight_id = cell_contents
547547
.get_mut(1)
@@ -835,7 +835,7 @@ pub fn parse_redraw_event(event_value: Value) -> Result<Vec<RedrawEvent>> {
835835
let mut event_contents = parse_array(event_value)?.into_iter();
836836
let event_name = event_contents
837837
.next()
838-
.ok_or_else(|| ParseError::Format(format!("{:?}", event_contents)))
838+
.ok_or_else(|| ParseError::Format(format!("{event_contents:?}")))
839839
.and_then(parse_string)?;
840840

841841
let events = event_contents;

src/bridge/setup.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ pub async fn setup_neovide_specific_state(nvim: &Neovim<TxWrapper>, is_remote: b
6060

6161
if let Err(command_error) = nvim.command("runtime! ginit.vim").await {
6262
nvim.command(&format!(
63-
"echomsg \"error encountered in ginit.vim {:?}\"",
64-
command_error
63+
"echomsg \"error encountered in ginit.vim {command_error:?}\""
6564
))
6665
.await
6766
.ok();

src/bridge/ui_commands.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl ParallelCommand {
146146
.await
147147
.expect("Focus Gained Failed"),
148148
ParallelCommand::FileDrop(path) => {
149-
nvim.command(format!("e {}", path).as_str()).await.ok();
149+
nvim.command(format!("e {path}").as_str()).await.ok();
150150
}
151151
ParallelCommand::DisplayAvailableFonts(fonts) => {
152152
let mut content: Vec<String> = vec![

src/frame.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use clap::{builder::PossibleValue, ValueEnum};
44

55
// Options for the frame decorations
66
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
7+
#[derive(Default)]
78
pub enum Frame {
9+
#[default]
810
Full,
911
#[cfg(target_os = "macos")]
1012
Transparent,
@@ -28,11 +30,7 @@ impl From<&'_ Frame> for &'static str {
2830
}
2931
}
3032

31-
impl Default for Frame {
32-
fn default() -> Frame {
33-
Frame::Full
34-
}
35-
}
33+
3634

3735
impl ValueEnum for Frame {
3836
fn value_variants<'a>() -> &'a [Self] {

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn protected_main() {
144144

145145
//Will exit if -h or -v
146146
if let Err(err) = cmd_line::handle_command_line_arguments(args().collect()) {
147-
eprintln!("{}", err);
147+
eprintln!("{err}");
148148
return;
149149
}
150150

src/renderer/cursor_renderer/cursor_vfx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl CursorVfx for ParticleTrail {
249249
let travel_distance = travel.length();
250250

251251
// Increase amount of particles when cursor travels further
252-
let particle_count = ((travel_distance / cursor_dimensions.y as f32).powf(1.5)
252+
let particle_count = ((travel_distance / cursor_dimensions.y).powf(1.5)
253253
* settings.vfx_particle_density
254254
* 0.01) as usize;
255255

@@ -262,7 +262,7 @@ impl CursorVfx for ParticleTrail {
262262
TrailMode::Railgun => {
263263
let phase = t / std::f32::consts::PI
264264
* settings.vfx_particle_phase
265-
* (travel_distance / cursor_dimensions.y as f32);
265+
* (travel_distance / cursor_dimensions.y);
266266
Point::new(phase.sin(), phase.cos()) * 2.0 * settings.vfx_particle_speed
267267
}
268268
TrailMode::Torpedo => {
@@ -285,7 +285,7 @@ impl CursorVfx for ParticleTrail {
285285
TrailMode::PixieDust | TrailMode::Torpedo => {
286286
prev_p
287287
+ travel * self.rng.next_f32()
288-
+ Point::new(0.0, cursor_dimensions.y as f32 * 0.5)
288+
+ Point::new(0.0, cursor_dimensions.y * 0.5)
289289
}
290290
};
291291

src/renderer/fonts/font_options.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ fn parse_font_name(font_name: impl AsRef<str>) -> String {
101101
}
102102

103103
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
104+
#[derive(Default)]
104105
pub enum FontEdging {
106+
#[default]
105107
AntiAlias,
106108
SubpixelAntiAlias,
107109
Alias,
@@ -117,14 +119,12 @@ impl FontEdging {
117119
}
118120
}
119121

120-
impl Default for FontEdging {
121-
fn default() -> Self {
122-
FontEdging::AntiAlias
123-
}
124-
}
122+
125123

126124
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
125+
#[derive(Default)]
127126
pub enum FontHinting {
127+
#[default]
128128
Full,
129129
Normal,
130130
Slight,
@@ -142,11 +142,7 @@ impl FontHinting {
142142
}
143143
}
144144

145-
impl Default for FontHinting {
146-
fn default() -> Self {
147-
FontHinting::Full
148-
}
149-
}
145+
150146

151147
fn points_to_pixels(value: f32) -> f32 {
152148
// Fonts in neovim are using points, not pixels.

src/renderer/profiler.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ impl Profiler {
114114

115115
// Show min, max, avg (average).
116116
root_canvas.draw_str(
117-
format!("min: {:.1}ms", min_ft),
117+
format!("min: {min_ft:.1}ms"),
118118
(rect.left, rect.bottom),
119119
&self.font.skia_font,
120120
&paint,
121121
);
122122
root_canvas.draw_str(
123-
format!("avg: {:.1}ms", avg),
123+
format!("avg: {avg:.1}ms"),
124124
(rect.left, rect.bottom - graph_height * 0.5),
125125
&self.font.skia_font,
126126
&paint,
127127
);
128128
root_canvas.draw_str(
129-
format!("max: {:.1}ms", max_ft),
129+
format!("max: {max_ft:.1}ms"),
130130
(rect.left, rect.bottom - graph_height),
131131
&self.font.skia_font,
132132
&paint,

src/renderer/rendered_window.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl RenderedWindow {
312312
root_canvas.draw_image_rect(
313313
image,
314314
None,
315-
pixel_region.with_offset((0.0, scroll_offset as f32)),
315+
pixel_region.with_offset((0.0, scroll_offset)),
316316
&paint,
317317
);
318318
}
@@ -324,7 +324,7 @@ impl RenderedWindow {
324324
root_canvas.draw_image_rect(
325325
snapshot,
326326
None,
327-
pixel_region.with_offset((0.0, scroll_offset as f32)),
327+
pixel_region.with_offset((0.0, scroll_offset)),
328328
&paint,
329329
);
330330

src/settings/from_value.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ mod tests {
9191
let v3p = std::u64::MAX as f32;
9292

9393
v0.parse_from_value(v1);
94-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
94+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
9595
v0.parse_from_value(v2);
96-
assert_eq!(v0, v2p, "v0 should equal {} but is actually {}", v2p, v0);
96+
assert_eq!(v0, v2p, "v0 should equal {v2p} but is actually {v0}");
9797
v0.parse_from_value(v3);
98-
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
98+
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
9999

100100
// This is a noop and prints an error
101101
v0.parse_from_value(Value::from("asd"));
102-
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
102+
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
103103
}
104104

105105
#[test]
@@ -109,11 +109,11 @@ mod tests {
109109
let v1p = std::u64::MAX;
110110

111111
v0.parse_from_value(v1);
112-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
112+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
113113

114114
// This is a noop and prints an error
115115
v0.parse_from_value(Value::from(-1));
116-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
116+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
117117
}
118118

119119
#[test]
@@ -123,11 +123,11 @@ mod tests {
123123
let v1p = std::u64::MAX as u32;
124124

125125
v0.parse_from_value(v1);
126-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
126+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
127127

128128
// This is a noop and prints an error
129129
v0.parse_from_value(Value::from(-1));
130-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
130+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
131131
}
132132

133133
#[test]
@@ -137,11 +137,11 @@ mod tests {
137137
let v1p = std::i64::MAX as i32;
138138

139139
v0.parse_from_value(v1);
140-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
140+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
141141

142142
// This is a noop and prints an error
143143
v0.parse_from_value(Value::from(-1));
144-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
144+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
145145
}
146146

147147
#[test]
@@ -151,11 +151,11 @@ mod tests {
151151
let v1p = "bar";
152152

153153
v0.parse_from_value(v1);
154-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
154+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
155155

156156
// This is a noop and prints an error
157157
v0.parse_from_value(Value::from(-1));
158-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
158+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
159159
}
160160

161161
#[test]
@@ -169,14 +169,14 @@ mod tests {
169169
let v3p = true;
170170

171171
v0.parse_from_value(v1);
172-
assert_eq!(v0, v1p, "v0 should equal {} but is actually {}", v1p, v0);
172+
assert_eq!(v0, v1p, "v0 should equal {v1p} but is actually {v0}");
173173
v0.parse_from_value(v2);
174-
assert_eq!(v0, v2p, "v0 should equal {} but is actually {}", v2p, v0);
174+
assert_eq!(v0, v2p, "v0 should equal {v2p} but is actually {v0}");
175175
v0.parse_from_value(v3);
176-
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
176+
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
177177

178178
// This is a noop and prints an error
179179
v0.parse_from_value(Value::from(-1));
180-
assert_eq!(v0, v3p, "v0 should equal {} but is actually {}", v3p, v0);
180+
assert_eq!(v0, v3p, "v0 should equal {v3p} but is actually {v0}");
181181
}
182182
}

src/settings/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Settings {
8888
let keys: Vec<String> = self.listeners.read().keys().cloned().collect();
8989

9090
for name in keys {
91-
let variable_name = format!("neovide_{}", name);
91+
let variable_name = format!("neovide_{name}");
9292
match nvim.get_var(&variable_name).await {
9393
Ok(value) => {
9494
self.listeners.read().get(&name).unwrap()(value);
@@ -119,8 +119,7 @@ impl Settings {
119119
nvim.command(&vimscript)
120120
.await
121121
.unwrap_or_explained_panic(&format!(
122-
"Could not setup setting notifier for {}",
123-
name
122+
"Could not setup setting notifier for {name}"
124123
));
125124
}
126125
}
@@ -246,8 +245,8 @@ mod tests {
246245
let v1: String = "foo".to_string();
247246
let v2: String = "bar".to_string();
248247
let v3: String = "baz".to_string();
249-
let v4: String = format!("neovide_{}", v1);
250-
let v5: String = format!("neovide_{}", v2);
248+
let v4: String = format!("neovide_{v1}");
249+
let v5: String = format!("neovide_{v2}");
251250

252251
//create_nvim_command tries to read from CmdLineSettings.neovim_args
253252
//TODO: this sets a static variable. Can this have side effects on other tests?

src/settings/window_geometry.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn settings_path() -> PathBuf {
4949

5050
fn load_settings() -> Result<PersistentSettings, String> {
5151
let settings_path = settings_path();
52-
let json = std::fs::read_to_string(&settings_path).map_err(|e| e.to_string())?;
52+
let json = std::fs::read_to_string(settings_path).map_err(|e| e.to_string())?;
5353
serde_json::from_str(&json).map_err(|e| e.to_string())
5454
}
5555

@@ -118,8 +118,7 @@ pub fn save_window_geometry(
118118

119119
pub fn parse_window_geometry(input: &str) -> Result<Dimensions, String> {
120120
let invalid_parse_err = format!(
121-
"Invalid geometry: {}\nValid format: <width>x<height>",
122-
input
121+
"Invalid geometry: {input}\nValid format: <width>x<height>"
123122
);
124123

125124
input

0 commit comments

Comments
 (0)