Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippy warnings #1487

Merged
merged 10 commits into from Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions espanso-clipboard/src/x11/xclip/mod.rs
Expand Up @@ -46,7 +46,7 @@ impl Clipboard for XClipClipboard {
return None;
}

match Command::new("xclip").args(&["-o", "-sel", "clip"]).output() {
match Command::new("xclip").args(["-o", "-sel", "clip"]).output() {
Ok(output) => {
if output.status.success() {
let s = String::from_utf8_lossy(&output.stdout);
Expand All @@ -67,7 +67,7 @@ impl Clipboard for XClipClipboard {
}

let mut child = Command::new("xclip")
.args(&["-sel", "clip"])
.args(["-sel", "clip"])
.stdin(Stdio::piped())
.spawn()?;

Expand Down Expand Up @@ -107,7 +107,7 @@ impl Clipboard for XClipClipboard {
let image_path = image_path.to_string_lossy();

Command::new("xclip")
.args(&["-selection", "clipboard", "-t", mime, "-i", &image_path])
.args(["-selection", "clipboard", "-t", mime, "-i", &image_path])
.spawn()?;

Ok(())
Expand All @@ -124,7 +124,7 @@ impl Clipboard for XClipClipboard {
}

let mut child = Command::new("xclip")
.args(&["-sel", "clip", "-t", "text/html"])
.args(["-sel", "clip", "-t", "text/html"])
.stdin(Stdio::piped())
.spawn()?;

Expand Down
2 changes: 1 addition & 1 deletion espanso-detect/src/evdev/device.rs
Expand Up @@ -61,7 +61,7 @@ impl Device {
let file = OpenOptions::new()
.read(true)
.custom_flags(O_NONBLOCK | O_CLOEXEC | O_RDONLY)
.open(&path)?;
.open(path)?;

if unsafe { is_keyboard_or_mouse(file.as_raw_fd()) == 0 } {
return Err(DeviceError::InvalidDevice(path.to_string()).into());
Expand Down
8 changes: 4 additions & 4 deletions espanso-detect/src/x11/mod.rs
Expand Up @@ -239,10 +239,10 @@ fn convert_hotkey_to_raw(hk: &HotKey) -> Option<RawHotKeyRequest> {
let key_sym = hk.key.to_code()?;
Some(RawHotKeyRequest {
key_sym,
ctrl: if hk.has_ctrl() { 1 } else { 0 },
alt: if hk.has_alt() { 1 } else { 0 },
shift: if hk.has_shift() { 1 } else { 0 },
meta: if hk.has_meta() { 1 } else { 0 },
ctrl: i32::from(hk.has_ctrl()),
alt: i32::from(hk.has_alt()),
shift: i32::from(hk.has_shift()),
meta: i32::from(hk.has_meta()),
})
}

Expand Down
2 changes: 1 addition & 1 deletion espanso-inject/src/evdev/uinput.rs
Expand Up @@ -77,7 +77,7 @@ impl UInputDevice {
}

pub fn emit(&self, key_code: u32, pressed: bool) {
let pressed = if pressed { 1 } else { 0 };
let pressed = i32::from(pressed);
unsafe {
uinput_emit(self.fd, key_code, pressed);
}
Expand Down
1 change: 1 addition & 0 deletions espanso-inject/src/lib.rs
Expand Up @@ -75,6 +75,7 @@ impl Default for InjectionOptions {
} else if cfg!(target_os = "macos") {
1
} else if cfg!(target_os = "linux") {
#[allow(clippy::bool_to_int_with_if)]
if cfg!(feature = "wayland") {
1
} else {
Expand Down
4 changes: 2 additions & 2 deletions espanso-inject/src/x11/default/mod.rs
Expand Up @@ -414,7 +414,7 @@ impl X11DefaultInjector {
for (mod_index, modifier_codes) in modifiers_codes.into_iter().enumerate() {
if (modmask & (1 << mod_index)) != 0 {
for keycode in modifier_codes {
let is_press = if pressed { 1 } else { 0 };
let is_press = i32::from(pressed);
unsafe {
XTestFakeKeyEvent(self.display, keycode as u32, is_press, 0);
XSync(self.display, 0);
Expand All @@ -430,7 +430,7 @@ impl X11DefaultInjector {
self.xtest_send_modifiers(record.state, pressed);
}

let is_press = if pressed { 1 } else { 0 };
let is_press = i32::from(pressed);
unsafe {
XTestFakeKeyEvent(self.display, record.code, is_press, 0);
XSync(self.display, 0);
Expand Down
2 changes: 1 addition & 1 deletion espanso-ipc/src/unix.rs
Expand Up @@ -108,7 +108,7 @@ pub struct UnixIPCClient {
impl UnixIPCClient {
pub fn new(id: &str, parent_dir: &Path) -> Result<Self> {
let socket_path = parent_dir.join(format!("{}.sock", id));
let stream = UnixStream::connect(&socket_path)?;
let stream = UnixStream::connect(socket_path)?;

Ok(Self { stream })
}
Expand Down
2 changes: 1 addition & 1 deletion espanso-ipc/src/windows.rs
Expand Up @@ -107,7 +107,7 @@ impl WinIPCClient {
pub fn new(id: &str) -> Result<Self> {
let pipe_name = format!("\\\\.\\pipe\\{}", id);

let stream = PipeClient::connect_ms(&pipe_name, DEFAULT_CLIENT_TIMEOUT)?;
let stream = PipeClient::connect_ms(pipe_name, DEFAULT_CLIENT_TIMEOUT)?;
Ok(Self { stream })
}
}
Expand Down
8 changes: 4 additions & 4 deletions espanso-match/src/rolling/tree.rs
Expand Up @@ -129,7 +129,7 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
insert_items_recursively(id, next_node.as_mut(), &items[1..])
}
None => {
let mut next_node = Box::new(MatcherTreeNode::default());
let mut next_node = Box::<MatcherTreeNode<Id>>::default();
insert_items_recursively(id, next_node.as_mut(), &items[1..]);
node.word_separators = Some(MatcherTreeRef::Node(next_node));
}
Expand All @@ -141,7 +141,7 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
insert_items_recursively(id, next_node, &items[1..])
}
} else {
let mut next_node = Box::new(MatcherTreeNode::default());
let mut next_node = Box::<MatcherTreeNode<Id>>::default();
insert_items_recursively(id, next_node.as_mut(), &items[1..]);
node
.keys
Expand All @@ -154,7 +154,7 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
insert_items_recursively(id, next_node, &items[1..])
}
} else {
let mut next_node = Box::new(MatcherTreeNode::default());
let mut next_node = Box::<MatcherTreeNode<Id>>::default();
insert_items_recursively(id, next_node.as_mut(), &items[1..]);
node
.chars
Expand All @@ -172,7 +172,7 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
insert_items_recursively(id, next_node, &items[1..])
}
} else {
let mut next_node = Box::new(MatcherTreeNode::default());
let mut next_node = Box::<MatcherTreeNode<Id>>::default();
insert_items_recursively(id, next_node.as_mut(), &items[1..]);
node
.chars_insensitive
Expand Down
16 changes: 8 additions & 8 deletions espanso-modulo/build.rs
Expand Up @@ -88,7 +88,7 @@ fn build_native() {
.to_string_lossy()
.to_string(),
)
.args(&[
.args([
"/k",
&vcvars_path.to_string_lossy(),
"&",
Expand Down Expand Up @@ -212,7 +212,7 @@ fn build_native() {
// See: https://github.com/actions/virtual-environments/issues/3288#issuecomment-830207746
Command::new(out_wx_dir.join("configure"))
.current_dir(build_dir.to_string_lossy().to_string())
.args(&[
.args([
"--disable-shared",
"--without-libtiff",
"--without-liblzma",
Expand All @@ -225,7 +225,7 @@ fn build_native() {
} else {
Command::new(out_wx_dir.join("configure"))
.current_dir(build_dir.to_string_lossy().to_string())
.args(&[
.args([
"--disable-shared",
"--without-libtiff",
"--without-liblzma",
Expand All @@ -247,7 +247,7 @@ fn build_native() {

let mut handle = Command::new("make")
.current_dir(build_dir.to_string_lossy().to_string())
.args(&["-j8"])
.args(["-j8"])
.spawn()
.expect("failed to execute make");
if !handle
Expand Down Expand Up @@ -320,7 +320,7 @@ fn convert_fat_libraries_to_arm(lib_dir: &Path) {

// Make sure it's a fat library
let lipo_output = std::process::Command::new("lipo")
.args(&["-detailed_info", &path.to_string_lossy()])
.args(["-detailed_info", &path.to_string_lossy()])
.output()
.expect("unable to check if library is fat");
let lipo_output = String::from_utf8_lossy(&lipo_output.stdout);
Expand All @@ -336,7 +336,7 @@ fn convert_fat_libraries_to_arm(lib_dir: &Path) {
println!("converting {} to arm", path.to_string_lossy(),);

let result = std::process::Command::new("lipo")
.args(&[
.args([
"-thin",
"arm64",
&path.to_string_lossy(),
Expand All @@ -354,7 +354,7 @@ fn convert_fat_libraries_to_arm(lib_dir: &Path) {

#[cfg(not(target_os = "windows"))]
fn get_cpp_flags(wx_config_path: &Path) -> Vec<String> {
let config_output = std::process::Command::new(&wx_config_path)
let config_output = std::process::Command::new(wx_config_path)
.arg("--cxxflags")
.output()
.expect("unable to execute wx-config");
Expand All @@ -376,7 +376,7 @@ fn get_cpp_flags(wx_config_path: &Path) -> Vec<String> {
#[cfg(not(target_os = "windows"))]
fn generate_linker_flags(wx_config_path: &Path) {
use regex::Regex;
let config_output = std::process::Command::new(&wx_config_path)
let config_output = std::process::Command::new(wx_config_path)
.arg("--libs")
.output()
.expect("unable to execute wx-config libs");
Expand Down
2 changes: 1 addition & 1 deletion espanso-modulo/src/sys/form/mod.rs
Expand Up @@ -252,7 +252,7 @@ mod interop {
.expect("unable to convert default text to CString");
let _interop = Box::new(TextMetadata {
defaultText: default_text.as_ptr(),
multiline: if text_metadata.multiline { 1 } else { 0 },
multiline: i32::from(text_metadata.multiline),
});
Self {
default_text,
Expand Down
2 changes: 1 addition & 1 deletion espanso-modulo/src/sys/troubleshooting/mod.rs
Expand Up @@ -156,7 +156,7 @@ pub fn show(options: TroubleshootingOptions) -> Result<()> {

let troubleshooting_metadata = TroubleshootingMetadata {
window_icon_path: c_window_icon_path_ptr,
is_fatal_error: if options.is_fatal_error { 1 } else { 0 },
is_fatal_error: i32::from(options.is_fatal_error),
error_sets: error_sets.as_ptr(),
error_sets_count: error_sets.len() as c_int,
dont_show_again_changed,
Expand Down
2 changes: 1 addition & 1 deletion espanso-modulo/src/sys/welcome/mod.rs
Expand Up @@ -55,7 +55,7 @@ pub fn show(options: WelcomeOptions) {
let welcome_metadata = WelcomeMetadata {
window_icon_path: c_window_icon_path_ptr,
tray_image_path: c_tray_image_path_ptr,
already_running: if options.is_already_running { 1 } else { 0 },
already_running: i32::from(options.is_already_running),
dont_show_again_changed,
};

Expand Down
72 changes: 12 additions & 60 deletions espanso-modulo/src/sys/wizard/mod.rs
Expand Up @@ -54,11 +54,7 @@ pub fn show(options: WizardOptions) -> bool {
.expect("unable to acquire lock in is_legacy_version_running method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.is_legacy_version_running.as_ref() {
if (*handler_ref)() {
1
} else {
0
}
i32::from((*handler_ref)())
} else {
-1
}
Expand Down Expand Up @@ -87,11 +83,7 @@ pub fn show(options: WizardOptions) -> bool {
.expect("unable to acquire lock in auto_start method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.auto_start.as_ref() {
if (*handler_ref)(auto_start != 0) {
1
} else {
0
}
i32::from((*handler_ref)(auto_start != 0))
} else {
-1
}
Expand All @@ -103,11 +95,7 @@ pub fn show(options: WizardOptions) -> bool {
.expect("unable to acquire lock in add_to_path method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.add_to_path.as_ref() {
if (*handler_ref)() {
1
} else {
0
}
i32::from((*handler_ref)())
} else {
-1
}
Expand All @@ -132,11 +120,7 @@ pub fn show(options: WizardOptions) -> bool {
.expect("unable to acquire lock in is_accessibility_enabled method");
let handlers_ref = (*lock).as_ref().expect("unable to unwrap handlers");
if let Some(handler_ref) = handlers_ref.is_accessibility_enabled.as_ref() {
if (*handler_ref)() {
1
} else {
0
}
i32::from((*handler_ref)())
} else {
-1
}
Expand All @@ -160,46 +144,14 @@ pub fn show(options: WizardOptions) -> bool {
let wizard_metadata = WizardMetadata {
version: c_version.as_ptr(),

is_welcome_page_enabled: if options.is_welcome_page_enabled {
1
} else {
0
},
is_move_bundle_page_enabled: if options.is_move_bundle_page_enabled {
1
} else {
0
},
is_legacy_version_page_enabled: if options.is_legacy_version_page_enabled {
1
} else {
0
},
is_wrong_edition_page_enabled: if options.is_wrong_edition_page_enabled {
1
} else {
0
},
is_migrate_page_enabled: if options.is_migrate_page_enabled {
1
} else {
0
},
is_auto_start_page_enabled: if options.is_auto_start_page_enabled {
1
} else {
0
},
is_add_path_page_enabled: if options.is_add_path_page_enabled {
1
} else {
0
},
is_accessibility_page_enabled: if options.is_accessibility_page_enabled {
1
} else {
0
},
is_welcome_page_enabled: i32::from(options.is_welcome_page_enabled),
is_move_bundle_page_enabled: i32::from(options.is_move_bundle_page_enabled),
is_legacy_version_page_enabled: i32::from(options.is_legacy_version_page_enabled),
is_wrong_edition_page_enabled: i32::from(options.is_wrong_edition_page_enabled),
is_migrate_page_enabled: i32::from(options.is_migrate_page_enabled),
is_auto_start_page_enabled: i32::from(options.is_auto_start_page_enabled),
is_add_path_page_enabled: i32::from(options.is_add_path_page_enabled),
is_accessibility_page_enabled: i32::from(options.is_accessibility_page_enabled),

window_icon_path: c_window_icon_path_ptr,
welcome_image_path: c_welcome_image_path_ptr,
Expand Down
2 changes: 1 addition & 1 deletion espanso-package/src/archive/default.rs
Expand Up @@ -52,7 +52,7 @@ impl Archiver for DefaultArchiver {
}

// Backup the previous directory if present
let backup_dir = self.package_dir.join(&format!("{}.old", package.name()));
let backup_dir = self.package_dir.join(format!("{}.old", package.name()));
let _backup_guard = if target_dir.is_dir() {
std::fs::rename(&target_dir, &backup_dir)
.context("unable to backup old package directory")?;
Expand Down
2 changes: 1 addition & 1 deletion espanso-package/src/provider/hub.rs
Expand Up @@ -144,7 +144,7 @@ impl EspansoHubPackageProvider {
index,
};
let serialized = serde_json::to_string(&cached_index)?;
std::fs::write(&target_file, serialized)?;
std::fs::write(target_file, serialized)?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion espanso-package/src/util/download.rs
Expand Up @@ -87,7 +87,7 @@ fn extract_zip(data: Vec<u8>, dest_dir: &Path) -> Result<()> {
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
std::fs::create_dir_all(&p)?;
std::fs::create_dir_all(p)?;
}
}
let mut outfile = std::fs::File::create(&outpath)?;
Expand Down
2 changes: 1 addition & 1 deletion espanso-render/src/extension/exec_util.rs
Expand Up @@ -50,7 +50,7 @@ pub fn determine_default_macos_shell() -> Option<MacShell> {
use std::process::Command;

let output = Command::new("sh")
.args(&["--login", "-c", "dscl . -read ~/ UserShell"])
.args(["--login", "-c", "dscl . -read ~/ UserShell"])
.output()
.ok()?;

Expand Down