on master help sign in
Fix new clippy lints (#5892)
commit8a3ec443f176218384db8c8610bbada9c43a6ea5 authorPascal Kuthe <pascal.kuthe@semimod.de> dateThu 9 Feb 2023, 23:27 (4 years ago) parent9d73a0d
18 files changed+32−37
helix-core/src/comment.rs+1−1 helix-core/src/increment/integer.rs+2−2 helix-core/src/indent.rs+2−2 helix-core/src/syntax.rs+1−1 helix-lsp/src/client.rs+1−1 helix-term/src/commands.rs+5−3 helix-term/src/lib.rs+1−1 helix-term/src/ui/document.rs+6−6 helix-term/src/ui/editor.rs+2−7 helix-term/src/ui/fuzzy_match.rs+1−1 helix-vcs/src/git/test.rs+1−1 helix-view/src/base64.rs+1−1 helix-view/src/clipboard.rs+1−1 helix-view/src/document.rs+1−1 helix-view/src/gutter.rs+3−5 helix-view/src/input.rs+1−1 helix-view/src/view.rs+1−1 xtask/src/themelint.rs+1−1
helix-core/src/comment.rs+1−1
@@ -68,7 +68,7 @@ pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&st
6868 let mut min_next_line = 0;
6969 for selection in selection {
7070 let (start, end) = selection.line_range(text);
71− let start = start.max(min_next_line).min(text.len_lines());
71+ let start = start.clamp(min_next_line, text.len_lines());
7272 let end = (end + 1).min(text.len_lines());
7373
7474 lines.extend(start..end);
helix-core/src/increment/integer.rs+2−2
@@ -69,8 +69,8 @@ pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
6969 let (lower_count, upper_count): (usize, usize) =
7070 number.chars().fold((0, 0), |(lower, upper), c| {
7171 (
72− lower + c.is_ascii_lowercase().then(|| 1).unwrap_or(0),
73− upper + c.is_ascii_uppercase().then(|| 1).unwrap_or(0),
72+ lower + c.is_ascii_lowercase() as usize,
73+ upper + c.is_ascii_uppercase() as usize,
7474 )
7575 });
7676 if upper_count > lower_count {
helix-core/src/indent.rs+2−2
@@ -604,7 +604,7 @@ pub fn treesitter_indent_for_pos(
604604 &mut cursor,
605605 text,
606606 query_range,
607− new_line.then(|| (line, byte_pos)),
607+ new_line.then_some((line, byte_pos)),
608608 );
609609 ts_parser.cursors.push(cursor);
610610 (query_result, deepest_preceding)
@@ -624,7 +624,7 @@ pub fn treesitter_indent_for_pos(
624624 tab_width,
625625 );
626626 }
627− let mut first_in_line = get_first_in_line(node, new_line.then(|| byte_pos));
627+ let mut first_in_line = get_first_in_line(node, new_line.then_some(byte_pos));
628628
629629 let mut result = Indentation::default();
630630 // We always keep track of all the indent changes on one line, in order to only indent once
helix-core/src/syntax.rs+1−1
@@ -427,7 +427,7 @@ impl TextObjectQuery {
427427 let nodes: Vec<_> = mat
428428 .captures
429429 .iter()
430− .filter_map(|cap| (cap.index == capture_idx).then(|| cap.node))
430+ .filter_map(|cap| (cap.index == capture_idx).then_some(cap.node))
431431 .collect();
432432
433433 if nodes.len() > 1 {
helix-lsp/src/client.rs+1−1
@@ -628,7 +628,7 @@ impl Client {
628628 Some(self.notify::<lsp::notification::DidSaveTextDocument>(
629629 lsp::DidSaveTextDocumentParams {
630630 text_document,
631− text: include_text.then(|| text.into()),
631+ text: include_text.then_some(text.into()),
632632 },
633633 ))
634634 }
helix-term/src/commands.rs+5−3
@@ -959,9 +959,11 @@ fn goto_window(cx: &mut Context, align: Align) {
959959 Align::Bottom => {
960960 view.offset.vertical_offset + last_visual_line.saturating_sub(scrolloff + count)
961961 }
962− }
963− .max(view.offset.vertical_offset + scrolloff)
964− .min(view.offset.vertical_offset + last_visual_line.saturating_sub(scrolloff));
962+ };
963+ let visual_line = visual_line.clamp(
964+ view.offset.vertical_offset + scrolloff,
965+ view.offset.vertical_offset + last_visual_line.saturating_sub(scrolloff),
966+ );
965967
966968 let pos = view
967969 .pos_at_visual_coords(doc, visual_line as u16, 0, false)
helix-term/src/lib.rs+1−1
@@ -42,7 +42,7 @@ fn filter_picker_entry(entry: &DirEntry, root: &Path, dedup_symlinks: bool) -> b
4242 .path()
4343 .canonicalize()
4444 .ok()
45− .map_or(false, |path| !path.starts_with(&root));
45+ .map_or(false, |path| !path.starts_with(root));
4646 }
4747
4848 true
helix-term/src/ui/document.rs+6−6
@@ -402,7 +402,7 @@ impl<'a> TextRenderer<'a> {
402402 is_in_indent_area: &mut bool,
403403 position: Position,
404404 ) {
405− let cut_off_start = self.col_offset.saturating_sub(position.col as usize);
405+ let cut_off_start = self.col_offset.saturating_sub(position.col);
406406 let is_whitespace = grapheme.is_whitespace();
407407
408408 // TODO is it correct to apply the whitspace style to all unicode white spaces?
@@ -413,7 +413,7 @@ impl<'a> TextRenderer<'a> {
413413 let width = grapheme.width();
414414 let grapheme = match grapheme {
415415 Grapheme::Tab { width } => {
416− let grapheme_tab_width = char_to_byte_idx(&self.tab, width as usize);
416+ let grapheme_tab_width = char_to_byte_idx(&self.tab, width);
417417 &self.tab[..grapheme_tab_width]
418418 }
419419 // TODO special rendering for other whitespaces?
@@ -423,8 +423,8 @@ impl<'a> TextRenderer<'a> {
423423 Grapheme::Newline => &self.newline,
424424 };
425425
426− let in_bounds = self.col_offset <= (position.col as usize)
427− && (position.col as usize) < self.viewport.width as usize + self.col_offset;
426+ let in_bounds = self.col_offset <= position.col
427+ && position.col < self.viewport.width as usize + self.col_offset;
428428
429429 if in_bounds {
430430 self.surface.set_string(
@@ -433,10 +433,10 @@ impl<'a> TextRenderer<'a> {
433433 grapheme,
434434 style,
435435 );
436− } else if cut_off_start != 0 && cut_off_start < width as usize {
436+ } else if cut_off_start != 0 && cut_off_start < width {
437437 // partially on screen
438438 let rect = Rect::new(
439− self.viewport.x as u16,
439+ self.viewport.x,
440440 self.viewport.y + position.row as u16,
441441 (width - cut_off_start) as u16,
442442 1,
helix-term/src/ui/editor.rs+2−7
@@ -206,7 +206,7 @@ impl EditorView {
206206 highlights,
207207 theme,
208208 &mut line_decorations,
209− &mut *translated_positions,
209+ &mut translated_positions,
210210 );
211211 Self::render_rulers(editor, doc, view, inner, surface, theme);
212212
@@ -723,12 +723,7 @@ impl EditorView {
723723 let viewport = view.area;
724724
725725 let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
726− let area = Rect::new(
727− viewport.x,
728− viewport.y + pos.visual_line as u16,
729− viewport.width,
730− 1,
731− );
726+ let area = Rect::new(viewport.x, viewport.y + pos.visual_line, viewport.width, 1);
732727 if primary_line == pos.doc_line {
733728 renderer.surface.set_style(area, primary_style);
734729 } else if secondary_lines.binary_search(&pos.doc_line).is_ok() {
helix-term/src/ui/fuzzy_match.rs+1−1
@@ -25,7 +25,7 @@ impl QueryAtom {
2525 _ => QueryAtomKind::Fuzzy,
2626 };
2727
28− if atom.starts_with(&['^', '\'']) {
28+ if atom.starts_with(['^', '\'']) {
2929 atom.remove(0);
3030 }
3131
helix-vcs/src/git/test.rs+1−1
@@ -89,7 +89,7 @@ fn directory() {
8989 std::fs::create_dir(&dir).expect("");
9090 let file = dir.join("file.txt");
9191 let contents = b"foo".as_slice();
92− File::create(&file).unwrap().write_all(contents).unwrap();
92+ File::create(file).unwrap().write_all(contents).unwrap();
9393
9494 create_commit(temp_git.path(), true);
9595
helix-view/src/base64.rs+1−1
@@ -36,7 +36,7 @@ const LOW_SIX_BITS: u32 = 0x3F;
3636pub fn encode(input: &[u8]) -> String {
3737 let rem = input.len() % 3;
3838 let complete_chunks = input.len() / 3;
39− let remainder_chunk = if rem == 0 { 0 } else { 1 };
39+ let remainder_chunk = usize::from(rem != 0);
4040 let encoded_size = (complete_chunks + remainder_chunk) * 4;
4141
4242 let mut output = vec![0; encoded_size];
helix-view/src/clipboard.rs+1−1
@@ -258,7 +258,7 @@ pub mod provider {
258258 .args(args)
259259 .output()
260260 .ok()
261− .and_then(|out| out.status.success().then(|| ())) // TODO: use then_some when stabilized
261+ .and_then(|out| out.status.success().then_some(()))
262262 .is_some()
263263 }
264264
helix-view/src/document.rs+1−1
@@ -1096,7 +1096,7 @@ impl Document {
10961096 /// Language server if it has been initialized.
10971097 pub fn language_server(&self) -> Option<&helix_lsp::Client> {
10981098 let server = self.language_server.as_deref()?;
1099− server.is_initialized().then(|| server)
1099+ server.is_initialized().then_some(server)
11001100 }
11011101
11021102 pub fn diff_handle(&self) -> Option<&DiffHandle> {
helix-view/src/gutter.rs+3−5
@@ -7,9 +7,8 @@ use crate::{
77};
88
99fn count_digits(n: usize) -> usize {
10− // NOTE: if int_log gets standardized in stdlib, can use checked_log10
11− // (https://github.com/rust-lang/rust/issues/70887#issue)
12− std::iter::successors(Some(n), |&n| (n >= 10).then(|| n / 10)).count()
10+ // TODO: use checked_log10 when MSRV reaches 1.67
11+ std::iter::successors(Some(n), |&n| (n >= 10).then_some(n / 10)).count()
1312}
1413
1514pub type GutterFn<'doc> = Box<dyn FnMut(usize, bool, bool, &mut String) -> Option<Style> + 'doc>;
@@ -199,8 +198,7 @@ pub fn line_numbers<'doc>(
199198 write!(out, "{:>1$}", " ", width).unwrap();
200199 }
201200
202− // TODO: Use then_some when MSRV reaches 1.62
203− first_visual_line.then(|| style)
201+ first_visual_line.then_some(style)
204202 }
205203 },
206204 )
helix-view/src/input.rs+1−1
@@ -380,7 +380,7 @@ impl std::str::FromStr for KeyEvent {
380380 let function: String = function.chars().skip(1).collect();
381381 let function = str::parse::<u8>(&function)?;
382382 (function > 0 && function < 13)
383− .then(|| KeyCode::F(function))
383+ .then_some(KeyCode::F(function))
384384 .ok_or_else(|| anyhow!("Invalid function key '{}'", function))?
385385 }
386386 invalid => return Err(anyhow!("Invalid key code '{}'", invalid)),
helix-view/src/view.rs+1−1
@@ -243,7 +243,7 @@ impl View {
243243 true
244244 }
245245 Some((visual_pos, _)) if visual_pos.row >= vertical_viewport_end - scrolloff => {
246− if CENTERING && visual_pos.row >= vertical_viewport_end as usize {
246+ if CENTERING && visual_pos.row >= vertical_viewport_end {
247247 // cursor out of view
248248 return None;
249249 }
xtask/src/themelint.rs+1−1
@@ -156,7 +156,7 @@ pub fn lint(file: String) -> Result<(), DynError> {
156156 return Ok(());
157157 }
158158 let path = path::themes().join(file.clone() + ".toml");
159− let theme = std::fs::read_to_string(&path).unwrap();
159+ let theme = std::fs::read_to_string(path).unwrap();
160160 let theme: Theme = toml::from_str(&theme).expect("Failed to parse theme");
161161
162162 let mut messages: Vec<String> = vec![];