Resolve new Clippy lints

This commit is contained in:
Michael Davis 2024-05-07 11:35:39 -04:00
parent 3cf2a91a25
commit 9dd51e75e0
8 changed files with 23 additions and 14 deletions

View File

@ -740,7 +740,7 @@ fn init_indent_query<'a, 'b>(
crate::syntax::PARSER.with(|ts_parser| { crate::syntax::PARSER.with(|ts_parser| {
let mut ts_parser = ts_parser.borrow_mut(); let mut ts_parser = ts_parser.borrow_mut();
let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new); let mut cursor = ts_parser.cursors.pop().unwrap_or_default();
let query_result = query_indents( let query_result = query_indents(
query, query,
syntax, syntax,

View File

@ -21,7 +21,7 @@
borrow::Cow, borrow::Cow,
cell::RefCell, cell::RefCell,
collections::{HashMap, HashSet, VecDeque}, collections::{HashMap, HashSet, VecDeque},
fmt::{self, Display}, fmt::{self, Display, Write},
hash::{Hash, Hasher}, hash::{Hash, Hasher},
mem::replace, mem::replace,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -729,8 +729,11 @@ pub fn read_query(language: &str, filename: &str) -> String {
.replace_all(&query, |captures: &regex::Captures| { .replace_all(&query, |captures: &regex::Captures| {
captures[1] captures[1]
.split(',') .split(',')
.map(|language| format!("\n{}\n", read_query(language, filename))) .fold(String::new(), |mut output, language| {
.collect::<String>() // `write!` to a String cannot fail.
write!(output, "\n{}\n", read_query(language, filename)).unwrap();
output
})
}) })
.to_string() .to_string()
} }
@ -1245,7 +1248,7 @@ fn point_sub(a: Point, b: Point) -> Point {
PARSER.with(|ts_parser| { PARSER.with(|ts_parser| {
let ts_parser = &mut ts_parser.borrow_mut(); let ts_parser = &mut ts_parser.borrow_mut();
ts_parser.parser.set_timeout_micros(1000 * 500); // half a second is pretty generours ts_parser.parser.set_timeout_micros(1000 * 500); // half a second is pretty generours
let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new); let mut cursor = ts_parser.cursors.pop().unwrap_or_default();
// TODO: might need to set cursor range // TODO: might need to set cursor range
cursor.set_byte_range(0..usize::MAX); cursor.set_byte_range(0..usize::MAX);
cursor.set_match_limit(TREE_SITTER_MATCH_LIMIT); cursor.set_match_limit(TREE_SITTER_MATCH_LIMIT);
@ -1419,7 +1422,7 @@ pub fn highlight_iter<'a>(
// Reuse a cursor from the pool if available. // Reuse a cursor from the pool if available.
let mut cursor = PARSER.with(|ts_parser| { let mut cursor = PARSER.with(|ts_parser| {
let highlighter = &mut ts_parser.borrow_mut(); let highlighter = &mut ts_parser.borrow_mut();
highlighter.cursors.pop().unwrap_or_else(QueryCursor::new) highlighter.cursors.pop().unwrap_or_default()
}); });
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which // The `captures` iterator borrows the `Tree` and the `QueryCursor`, which

View File

@ -378,7 +378,9 @@ pub fn update_positions<'a>(&self, positions: impl Iterator<Item = (&'a mut usiz
macro_rules! map { macro_rules! map {
($map: expr, $i: expr) => { ($map: expr, $i: expr) => {
loop { loop {
let Some((pos, assoc)) = positions.peek_mut() else { return; }; let Some((pos, assoc)) = positions.peek_mut() else {
return;
};
if **pos < old_pos { if **pos < old_pos {
// Positions are not sorted, revert to the last Operation that // Positions are not sorted, revert to the last Operation that
// contains this position and continue iterating from there. // contains this position and continue iterating from there.
@ -405,7 +407,10 @@ macro_rules! map {
debug_assert!(old_pos <= **pos, "Reverse Iter across changeset works"); debug_assert!(old_pos <= **pos, "Reverse Iter across changeset works");
continue 'outer; continue 'outer;
} }
let Some(new_pos) = $map(**pos, *assoc) else { break; }; #[allow(clippy::redundant_closure_call)]
let Some(new_pos) = $map(**pos, *assoc) else {
break;
};
**pos = new_pos; **pos = new_pos;
positions.next(); positions.next();
} }

View File

@ -36,7 +36,7 @@ fn test_treesitter_indent_rust_helix() {
.unwrap(); .unwrap();
let files = String::from_utf8(files.stdout).unwrap(); let files = String::from_utf8(files.stdout).unwrap();
let ignored_files = vec![ let ignored_files = [
// Contains many macros that tree-sitter does not parse in a meaningful way and is otherwise not very interesting // Contains many macros that tree-sitter does not parse in a meaningful way and is otherwise not very interesting
"helix-term/src/health.rs", "helix-term/src/health.rs",
]; ];
@ -45,6 +45,7 @@ fn test_treesitter_indent_rust_helix() {
if ignored_files.contains(&file) { if ignored_files.contains(&file) {
continue; continue;
} }
#[allow(clippy::single_range_in_vec_init)]
let ignored_lines: Vec<Range<usize>> = match file { let ignored_lines: Vec<Range<usize>> = match file {
"helix-term/src/application.rs" => vec![ "helix-term/src/application.rs" => vec![
// We can't handle complicated indent rules inside macros (`json!` in this case) since // We can't handle complicated indent rules inside macros (`json!` in this case) since

View File

@ -139,7 +139,7 @@ async fn run(mut rx: mpsc::UnboundedReceiver<Event>) {
registration_id registration_id
); );
let entry = state.entry(client_id).or_insert_with(ClientState::default); let entry = state.entry(client_id).or_default();
entry.client = client; entry.client = client;
let mut builder = GlobSetBuilder::new(); let mut builder = GlobSetBuilder::new();

View File

@ -724,7 +724,7 @@ macro_rules! language_server {
} }
Notification::PublishDiagnostics(mut params) => { Notification::PublishDiagnostics(mut params) => {
let path = match params.uri.to_file_path() { let path = match params.uri.to_file_path() {
Ok(path) => helix_stdx::path::normalize(&path), Ok(path) => helix_stdx::path::normalize(path),
Err(_) => { Err(_) => {
log::error!("Unsupported file URI: {}", params.uri); log::error!("Unsupported file URI: {}", params.uri);
return; return;

View File

@ -123,7 +123,7 @@ pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
_ => unreachable!(), _ => unreachable!(),
}; };
let contents = self.clipboard_provider.get_contents(clipboard_type)?; let contents = self.clipboard_provider.get_contents(clipboard_type)?;
let saved_values = self.inner.entry(name).or_insert_with(Vec::new); let saved_values = self.inner.entry(name).or_default();
if !contents_are_saved(saved_values, &contents) { if !contents_are_saved(saved_values, &contents) {
anyhow::bail!("Failed to push to register {name}: clipboard does not match register contents"); anyhow::bail!("Failed to push to register {name}: clipboard does not match register contents");
@ -140,7 +140,7 @@ pub fn push(&mut self, name: char, mut value: String) -> Result<()> {
Ok(()) Ok(())
} }
_ => { _ => {
self.inner.entry(name).or_insert_with(Vec::new).push(value); self.inner.entry(name).or_default().push(value);
Ok(()) Ok(())
} }
} }

View File

@ -560,7 +560,7 @@ pub fn prev(&self) -> ViewId {
id id
} else { } else {
// extremely crude, take the last item // extremely crude, take the last item
let (key, _) = self.traverse().rev().next().unwrap(); let (key, _) = self.traverse().next_back().unwrap();
key key
} }
} }