summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVille Hakulinen <ville.hakulinen@gmail.com>2020-07-23 15:05:39 +0300
committerVille Hakulinen <ville.hakulinen@gmail.com>2020-07-23 15:05:39 +0300
commitac311da565d22149e58ebc4a4d1b58034925b094 (patch)
tree632a7450dc8fd7df63f3950a4298131df5726776
parent8c3f8471ffbf658c0a867e65ec73806f6c3e2cf5 (diff)
Fix bunch for cargo clippy errors
-rw-r--r--src/main.rs4
-rw-r--r--src/nvim_bridge/mod.rs15
-rw-r--r--src/nvim_gio/compat.rs1
-rw-r--r--src/nvim_gio/mod.rs2
-rw-r--r--src/thread_guard.rs4
-rw-r--r--src/ui/cmdline.rs5
-rw-r--r--src/ui/color.rs8
-rw-r--r--src/ui/common.rs2
-rw-r--r--src/ui/cursor_tooltip.rs6
-rw-r--r--src/ui/font.rs8
-rw-r--r--src/ui/grid/context.rs4
-rw-r--r--src/ui/grid/cursor.rs2
-rw-r--r--src/ui/grid/grid.rs3
-rw-r--r--src/ui/grid/render.rs7
-rw-r--r--src/ui/grid/row.rs2
-rw-r--r--src/ui/popupmenu/completion_item_widget.rs11
-rw-r--r--src/ui/popupmenu/lazy_loader.rs10
-rw-r--r--src/ui/popupmenu/popupmenu.rs24
-rw-r--r--src/ui/state.rs6
-rw-r--r--src/ui/tabline.rs9
-rw-r--r--src/ui/ui.rs8
-rw-r--r--src/ui/wildmenu.rs11
22 files changed, 58 insertions, 94 deletions
diff --git a/src/main.rs b/src/main.rs
index 864619b..985843f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -37,7 +37,7 @@ mod thread_guard;
mod ui;
fn parse_geometry(input: &str) -> Result<(i32, i32), String> {
- let ret_tuple: Vec<&str> = input.split("x").collect();
+ let ret_tuple: Vec<&str> = input.split('x').collect();
if ret_tuple.len() != 2 {
Err(String::from("must be of form 'width'x'height'"))
} else {
@@ -228,5 +228,5 @@ fn main() {
});
});
- app.run(&vec![]);
+ app.run(&[]);
}
diff --git a/src/nvim_bridge/mod.rs b/src/nvim_bridge/mod.rs
index 9a82571..c6d4bf6 100644
--- a/src/nvim_bridge/mod.rs
+++ b/src/nvim_bridge/mod.rs
@@ -74,7 +74,7 @@ macro_rules! try_u64 {
}
impl Highlight {
- fn from_map_val(map: &Vec<(Value, Value)>) -> Self {
+ fn from_map_val(map: &[(Value, Value)]) -> Self {
let mut hl = Highlight::default();
for (prop, val) in map {
hl.set(unwrap_str!(prop), val.clone());
@@ -386,7 +386,7 @@ impl From<Value> for CmdlineShow {
fn from(args: Value) -> Self {
let args = unwrap_array!(args);
let content: Vec<(u64, String)> = unwrap_array!(args[0])
- .into_iter()
+ .iter()
.map(|v| {
let hl_id = unwrap_u64!(v[0]);
let text = unwrap_str!(v[1]);
@@ -520,8 +520,7 @@ pub struct GridScroll {
impl From<Value> for GridScroll {
fn from(args: Value) -> Self {
let args = unwrap_array!(args);
- let reg: Vec<u64> =
- args[1..5].into_iter().map(|v| unwrap_u64!(v)).collect();
+ let reg: Vec<u64> = args[1..5].iter().map(|v| unwrap_u64!(v)).collect();
let reg = [reg[0], reg[1], reg[2], reg[3]];
GridScroll {
grid: unwrap_i64!(args[0]),
@@ -598,7 +597,7 @@ impl From<Value> for ModeInfoSet {
let cursor_shape_enabled = unwrap_bool!(args[0]);
let mut mode_info = vec![];
- for info in unwrap_array!(args[1]).into_iter() {
+ for info in unwrap_array!(args[1]).iter() {
let map = unwrap_map!(info);
let mut mode = ModeInfo::default();
@@ -722,10 +721,10 @@ pub struct CmdlineBlockShow {
impl From<Value> for CmdlineBlockShow {
fn from(args: Value) -> Self {
let lines = unwrap_array!(args)
- .into_iter()
+ .iter()
.map(|line| {
unwrap_array!(line[0])
- .into_iter()
+ .iter()
.map(|v| {
let hl_id = unwrap_u64!(v[0]);
let text = unwrap_str!(v[1]);
@@ -1076,8 +1075,6 @@ impl Spawner for NvimBridge {
let c = glib::MainContext::default();
c.spawn(future);
-
- ()
}
}
diff --git a/src/nvim_gio/compat.rs b/src/nvim_gio/compat.rs
index 1a16b60..e4eee06 100644
--- a/src/nvim_gio/compat.rs
+++ b/src/nvim_gio/compat.rs
@@ -4,7 +4,6 @@ use std::{
task::{Context, Poll},
};
-use gio;
use pin_project::pin_project;
use crate::thread_guard::ThreadGuard;
diff --git a/src/nvim_gio/mod.rs b/src/nvim_gio/mod.rs
index 19951e2..9350436 100644
--- a/src/nvim_gio/mod.rs
+++ b/src/nvim_gio/mod.rs
@@ -1,6 +1,4 @@
-use gio;
use gio::prelude::*;
-use glib;
use log::error;
diff --git a/src/thread_guard.rs b/src/thread_guard.rs
index 91116c4..97c571d 100644
--- a/src/thread_guard.rs
+++ b/src/thread_guard.rs
@@ -23,7 +23,7 @@ impl<T> ThreadGuard<T> {
pub fn borrow(&self) -> Ref<T> {
match self.check_thread() {
Ok(_) => self.data.borrow(),
- Err(_) => {
+ Err(()) => {
panic!(
"Data is only accessible on thread {:?} (current is {:?})",
self.thread_id,
@@ -36,7 +36,7 @@ impl<T> ThreadGuard<T> {
pub fn borrow_mut(&self) -> RefMut<T> {
match self.check_thread() {
Ok(_) => self.data.borrow_mut(),
- Err(_) => {
+ Err(()) => {
panic!(
"Data is only accessible on thread {:?} (current is {:?})",
self.thread_id,
diff --git a/src/ui/cmdline.rs b/src/ui/cmdline.rs
index e3b6b19..85d5c85 100644
--- a/src/ui/cmdline.rs
+++ b/src/ui/cmdline.rs
@@ -1,4 +1,3 @@
-use gtk;
use gtk::prelude::*;
use crate::nvim_bridge;
@@ -432,7 +431,7 @@ impl Cmdline {
let frame = gtk::Frame::new(None);
frame.add(&inner_box);
- let wildmenu = Wildmenu::new(nvim.clone());
+ let wildmenu = Wildmenu::new(nvim);
// box_ is the actual container for cmdline and wildmenu.
let box_ = gtk::Box::new(gtk::Orientation::Vertical, 0);
@@ -624,7 +623,7 @@ impl Cmdline {
self.block.append(line, &hl_defs);
}
- pub fn wildmenu_show(&mut self, items: &Vec<nvim_bridge::CompletionItem>) {
+ pub fn wildmenu_show(&mut self, items: &[nvim_bridge::CompletionItem]) {
self.show_wildmenu = true;
self.wildmenu.set_items(items);
self.wildmenu.show();
diff --git a/src/ui/color.rs b/src/ui/color.rs
index c73faba..e3d1f7b 100644
--- a/src/ui/color.rs
+++ b/src/ui/color.rs
@@ -1,7 +1,5 @@
use std::collections::HashMap;
-use glib;
-
#[derive(Hash, PartialEq, Eq)]
pub enum HlGroup {
Pmenu,
@@ -131,13 +129,13 @@ impl Color {
let res = u64::from_str_radix(hex.as_str(), 16);
if let Ok(res) = res {
- return Ok(Color::from_u64(res));
+ Ok(Color::from_u64(res))
} else {
- return Err(format!(
+ Err(format!(
"Failed to parse hex string '{}': {:?}",
hex,
res.err()
- ));
+ ))
}
}
diff --git a/src/ui/common.rs b/src/ui/common.rs
index bdbc172..cb22ef5 100644
--- a/src/ui/common.rs
+++ b/src/ui/common.rs
@@ -59,7 +59,7 @@ pub fn get_preferred_vertical_position(
}
}
- return (y, height);
+ (y, height)
}
#[cfg(test)]
diff --git a/src/ui/cursor_tooltip.rs b/src/ui/cursor_tooltip.rs
index 5e318a1..b78e62c 100644
--- a/src/ui/cursor_tooltip.rs
+++ b/src/ui/cursor_tooltip.rs
@@ -4,13 +4,11 @@ use std::collections::HashSet;
use std::path::Path;
use std::sync::Arc;
-use gtk;
use gtk::prelude::*;
use webkit2gtk as webkit;
use webkit2gtk::{SettingsExt, WebViewExt};
-use ammonia;
use pulldown_cmark as md;
use syntect::dumps::from_binary;
@@ -514,8 +512,8 @@ fn attribute_filter<'u>(
let mut new = String::new();
- for attrs in value.split(";") {
- if let [prop, val] = attrs.split(":").collect::<Vec<&str>>()[..]
+ for attrs in value.split(';') {
+ if let [prop, val] = attrs.split(':').collect::<Vec<&str>>()[..]
{
if let Some(vals) = allowed_fixed.get(&prop) {
if vals.contains(&val) {
diff --git a/src/ui/font.rs b/src/ui/font.rs
index 6f3a1d7..2e64584 100644
--- a/src/ui/font.rs
+++ b/src/ui/font.rs
@@ -28,11 +28,11 @@ impl Font {
///
/// If invalid height is specified, defaults to `DEFAULT_HEIGHT`.
pub fn from_guifont(guifont: &str) -> Result<Self, ()> {
- let mut parts = guifont.split(":").into_iter();
+ let mut parts = guifont.split(':');
let name = parts.next().ok_or(())?;
- if name.len() == 0 {
+ if name.is_empty() {
return Err(());
}
@@ -41,8 +41,8 @@ impl Font {
height: DEFAULT_HEIGHT,
};
- while let Some(part) = parts.next() {
- let mut chars = part.chars().into_iter();
+ for part in parts {
+ let mut chars = part.chars();
if let Some(ch) = chars.next() {
match ch {
'h' => {
diff --git a/src/ui/grid/context.rs b/src/ui/grid/context.rs
index 0b2d80f..6b12228 100644
--- a/src/ui/grid/context.rs
+++ b/src/ui/grid/context.rs
@@ -1,7 +1,5 @@
-use cairo;
use gtk::prelude::*;
use gtk::DrawingArea;
-use pango;
use crate::ui::color::HlDefs;
use crate::ui::font::Font;
@@ -216,7 +214,7 @@ impl Context {
pub fn get_cursor_rect(&self) -> (i32, i32, i32, i32) {
let double_width = self
.cell_at_cursor()
- .and_then(|cell| Some(cell.double_width))
+ .map(|cell| cell.double_width)
.unwrap_or(false);
// Dont use cursor.get_position here, because we want to use the position on the screen.
diff --git a/src/ui/grid/cursor.rs b/src/ui/grid/cursor.rs
index 6b4239c..16f8fcf 100644
--- a/src/ui/grid/cursor.rs
+++ b/src/ui/grid/cursor.rs
@@ -108,7 +108,7 @@ impl Cursor {
/// infamous easing equations, MIT license.
fn ease_out_cubic(t: f64) -> f64 {
let p = t - 1f64;
- return p * p * p + 1f64;
+ p * p * p + 1f64
}
#[cfg(test)]
diff --git a/src/ui/grid/grid.rs b/src/ui/grid/grid.rs
index f470467..9cad198 100644
--- a/src/ui/grid/grid.rs
+++ b/src/ui/grid/grid.rs
@@ -3,10 +3,7 @@ use std::fmt;
use std::fmt::Display;
use std::rc::Rc;
-use cairo;
-use gdk;
use gdk::{EventMask, ModifierType};
-use gtk;
use gtk::{DrawingArea, EventBox};
use gtk::prelude::*;
diff --git a/src/ui/grid/render.rs b/src/ui/grid/render.rs
index 8dab7e8..441db16 100644
--- a/src/ui/grid/render.rs
+++ b/src/ui/grid/render.rs
@@ -1,9 +1,6 @@
-use cairo;
use gtk::prelude::*;
use gtk::DrawingArea;
-use pango;
use pango::Attribute;
-use pangocairo;
use crate::nvim_bridge::GridLineSegment;
use crate::ui::color::Highlight;
@@ -119,7 +116,7 @@ pub fn cursor_cell(
cm: &CellMetrics,
hl_defs: &HlDefs,
) {
- let mut hl = hl_defs.get(&cell.hl_id).unwrap().clone();
+ let mut hl = *hl_defs.get(&cell.hl_id).unwrap();
hl.reverse = !hl.reverse;
@@ -194,7 +191,7 @@ pub fn put_line(
let mut affected_segments = context
.rows
.get_mut(row)
- .expect(&format!("Failed to get row {}", line.row))
+ .unwrap_or_else(|| panic!("Failed to get row {}", line.row))
.update(line);
// NOTE(ville): I haven't noticed any cases where a character is overflowing
diff --git a/src/ui/grid/row.rs b/src/ui/grid/row.rs
index e21507b..30c146d 100644
--- a/src/ui/grid/row.rs
+++ b/src/ui/grid/row.rs
@@ -168,7 +168,7 @@ impl Row {
segs.push(Segment {
text: cell.text.clone(),
hl_id: cell.hl_id,
- start: start,
+ start,
len: 1,
});
diff --git a/src/ui/popupmenu/completion_item_widget.rs b/src/ui/popupmenu/completion_item_widget.rs
index 7477fa4..b7325fc 100644
--- a/src/ui/popupmenu/completion_item_widget.rs
+++ b/src/ui/popupmenu/completion_item_widget.rs
@@ -1,4 +1,3 @@
-use gtk;
use gtk::prelude::*;
use crate::nvim_bridge::{CompletionItem, CompletionItemKind};
@@ -103,8 +102,8 @@ impl CompletionItemWidgetWrap {
}
/// Returns first line of `info`.
-fn shorten_info(info: &String) -> String {
- let lines = info.split("\n").collect::<Vec<&str>>();
+fn shorten_info(info: &str) -> String {
+ let lines = info.split('\n').collect::<Vec<&str>>();
let first_line = lines.get(0).unwrap();
first_line.to_string()
}
@@ -118,11 +117,9 @@ pub fn get_icon_pixbuf(
let stream = gio::MemoryInputStream::new_from_bytes(&glib::Bytes::from(
contents.as_bytes(),
));
- let buf =
- gdk_pixbuf::Pixbuf::new_from_stream(&stream, None::<&gio::Cancellable>)
- .unwrap();
- buf
+ gdk_pixbuf::Pixbuf::new_from_stream(&stream, None::<&gio::Cancellable>)
+ .unwrap()
}
fn get_icon_name_for_kind(
diff --git a/src/ui/popupmenu/lazy_loader.rs b/src/ui/popupmenu/lazy_loader.rs
index 06927ec..5397ef8 100644
--- a/src/ui/popupmenu/lazy_loader.rs
+++ b/src/ui/popupmenu/lazy_loader.rs
@@ -1,14 +1,15 @@
use std::cell::RefCell;
use std::rc::Rc;
-use glib;
-use gtk;
use gtk::prelude::*;
use crate::nvim_bridge::CompletionItem;
use crate::ui::color::Color;
use crate::ui::popupmenu::CompletionItemWidgetWrap;
+type OnceLoaded =
+ Option<(Option<i32>, Box<dyn Fn(&Vec<CompletionItemWidgetWrap>)>)>;
+
struct State {
items: Vec<CompletionItemWidgetWrap>,
items_to_load: Vec<CompletionItem>,
@@ -19,8 +20,7 @@ struct State {
/// Once we're loaded some (or all) data, this closure gets called if
/// one exists. The first value in the tuple can is indication on the
/// number of items needed before calling the closure.
- once_loaded:
- Option<(Option<i32>, Box<dyn Fn(&Vec<CompletionItemWidgetWrap>)>)>,
+ once_loaded: OnceLoaded,
list: gtk::ListBox,
css_provider: gtk::CssProvider,
@@ -85,7 +85,7 @@ impl LazyLoader {
// Load the rows in patches so we avoid renders of "half height"
// completion menus.
for _ in 0..40 {
- if state.items_to_load.len() == 0 {
+ if state.items_to_load.is_empty() {
state.source_id = None;
if let Some((_, cb)) = state.once_loaded.take() {
diff --git a/src/ui/popupmenu/popupmenu.rs b/src/ui/popupmenu/popupmenu.rs
index 98d1fae..2006060 100644
--- a/src/ui/popupmenu/popupmenu.rs
+++ b/src/ui/popupmenu/popupmenu.rs
@@ -1,10 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
-use gdk;
-use gtk;
use gtk::prelude::*;
-use pango;
use crate::nvim_bridge::CompletionItem;
use crate::nvim_gio::GioNeovim;
@@ -313,7 +310,7 @@ impl Popupmenu {
item.info.set_visible(!info_shown);
item.menu.set_visible(!info_shown);
- if item.item.info.len() == 0 {
+ if item.item.info.is_empty() {
item.info.set_visible(false);
}
@@ -398,8 +395,8 @@ impl Popupmenu {
pub fn select(&mut self, item_num: i32, hl_defs: &HlDefs) {
let state = self.state.clone();
let scrolled_list = self.scrolled_list.clone();
- let fg = self.colors.fg.unwrap_or(hl_defs.default_fg).clone();
- let fg_sel = self.colors.sel_fg.unwrap_or(hl_defs.default_fg).clone();
+ let fg = self.colors.fg.unwrap_or(hl_defs.default_fg);
+ let fg_sel = self.colors.sel_fg.unwrap_or(hl_defs.default_fg);
let font_height = self.font.height as f64;
let list = self.list.clone();
let info_label = self.info_label.clone();
@@ -444,7 +441,7 @@ impl Popupmenu {
item.info.set_visible(!info_shown);
item.menu.set_visible(!info_shown);
- if item.item.info.len() == 0 {
+ if item.item.info.is_empty() {
item.info.set_visible(false);
}
@@ -480,12 +477,13 @@ impl Popupmenu {
item.image.set_from_pixbuf(Some(&buf));
}
- let newline =
- if item.item.menu.len() > 0 && item.item.info.len() > 0 {
- "\n"
- } else {
- ""
- };
+ let newline = if !item.item.menu.is_empty()
+ && !item.item.info.is_empty()
+ {
+ "\n"
+ } else {
+ ""
+ };
info_label.set_text(&format!(
"{}{}{}",
diff --git a/src/ui/state.rs b/src/ui/state.rs
index 14ad151..a683c82 100644
--- a/src/ui/state.rs
+++ b/src/ui/state.rs
@@ -2,8 +2,6 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
-use glib;
-use gtk;
use gtk::prelude::*;
use log::{debug, error, warn};
@@ -296,7 +294,7 @@ impl UIState {
fn option_set(&mut self, opt: OptionSet) {
match opt {
OptionSet::GuiFont(font) => {
- let font = Font::from_guifont(&font).unwrap_or(Font::default());
+ let font = Font::from_guifont(&font).unwrap_or_default();
self.font = font.clone();
@@ -335,7 +333,7 @@ impl UIState {
}
fn mode_info_set(&mut self, ModeInfoSet { mode_info, .. }: ModeInfoSet) {
- self.mode_infos = mode_info.clone();
+ self.mode_infos = mode_info;
}
fn mode_change(&mut self, ModeChange { index, .. }: ModeChange) {
diff --git a/src/ui/tabline.rs b/src/ui/tabline.rs
index 8b51fe9..fb9727f 100644
--- a/src/ui/tabline.rs
+++ b/src/ui/tabline.rs
@@ -1,10 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
-use glib;
-use gtk;
use gtk::prelude::*;
-use pango;
use nvim_rs::Tabpage;
@@ -28,7 +25,7 @@ pub struct Tabline {
css_provider: gtk::CssProvider,
switch_tab_signal: glib::SignalHandlerId,
- tabpage_data: Rc<RefCell<Box<Vec<Tabpage<GioWriter>>>>>,
+ tabpage_data: Rc<RefCell<Vec<Tabpage<GioWriter>>>>,
/// Our colors.
colors: TablineColors,
@@ -46,7 +43,7 @@ impl Tabline {
let css_provider = gtk::CssProvider::new();
add_css_provider!(&css_provider, notebook);
- let tabpage_data = Rc::new(RefCell::new(Box::new(vec![])));
+ let tabpage_data = Rc::new(RefCell::new(vec![]));
let switch_tab_signal = notebook.connect_switch_page(
clone!(tabpage_data, nvim => move |_, _, page_num| {
let tabpage_data = tabpage_data.clone();
@@ -119,7 +116,7 @@ impl Tabline {
self.notebook.set_current_page(Some(page as u32));
self.tabpage_data
- .replace(Box::new(tabs.into_iter().map(|t| t.0).collect()));
+ .replace(tabs.into_iter().map(|t| t.0).collect());
glib::signal_handler_unblock(&self.notebook, &self.switch_tab_signal);
}
diff --git a/src/ui/ui.rs b/src/ui/ui.rs
index fcf4258..930098b 100644
--- a/src/ui/ui.rs
+++ b/src/ui/ui.rs
@@ -2,9 +2,6 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
-use gdk;
-use glib;
-use gtk;
use gtk::prelude::*;
use log::{debug, error};
@@ -124,9 +121,8 @@ impl UI {
let new = gtk::timeout_add(30, clone!(nvim, source_id => move || {
let nvim = nvim.clone();
spawn_local(async move {
- match nvim.ui_try_resize(cols as i64, rows as i64).await {
- Err(err) => error!("Error: failed to resize nvim when grid size changed ({:?})", err),
- Ok(_) => {},
+ if let Err(err) = nvim.ui_try_resize(cols as i64, rows as i64).await {
+ error!("Error: failed to resize nvim when grid size changed ({:?})", err);
}
});
diff --git a/src/ui/wildmenu.rs b/src/ui/wildmenu.rs
index a865f8a..4e2f20f 100644
--- a/src/ui/wildmenu.rs
+++ b/src/ui/wildmenu.rs
@@ -1,4 +1,3 @@
-use gtk;
use gtk::prelude::*;
use std::cell::RefCell;
use std::rc::Rc;
@@ -112,7 +111,7 @@ impl Wildmenu {
}
}
- pub fn set_items(&mut self, items: &Vec<nvim_bridge::CompletionItem>) {
+ pub fn set_items(&mut self, items: &[nvim_bridge::CompletionItem]) {
self.clear();
for item in items {
@@ -135,11 +134,9 @@ impl Wildmenu {
if item_num < 0 {
self.list.unselect_all();
- } else {
- if let Some(row) = self.list.get_row_at_index(item_num) {
- self.list.select_row(Some(&row));
- row.grab_focus();
- }
+ } else if let Some(row) = self.list.get_row_at_index(item_num) {
+ self.list.select_row(Some(&row));
+ row.grab_focus();
}
}