diff --git a/crates/cli/src/fuzz/scope_sequence.rs b/crates/cli/src/fuzz/scope_sequence.rs index 686470151..7bf342425 100644 --- a/crates/cli/src/fuzz/scope_sequence.rs +++ b/crates/cli/src/fuzz/scope_sequence.rs @@ -49,7 +49,7 @@ impl ScopeSequence { for i in 0..(self.0.len().max(other.0.len())) { let stack = &self.0.get(i); let other_stack = &other.0.get(i); - if *stack != *other_stack && ![b'\r', b'\n'].contains(&text[i]) { + if *stack != *other_stack && !b"\r\n".contains(&text[i]) { let containing_range = known_changed_ranges .iter() .find(|range| range.start_point <= position && position < range.end_point); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index c182940cd..c9162d7af 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -2003,7 +2003,7 @@ impl DumpLanguages { concat!( "name: {}\n", "scope: {}\n", - "parser: {:?}\n", + "parser: {}\n", "highlights: {:?}\n", "file_types: {:?}\n", "content_regex: {:?}\n", @@ -2011,7 +2011,7 @@ impl DumpLanguages { ), configuration.language_name, configuration.scope.as_ref().unwrap_or(&String::new()), - language_path, + language_path.display(), configuration.highlights_filenames, configuration.file_types, configuration.content_regex, diff --git a/crates/cli/src/parse.rs b/crates/cli/src/parse.rs index 190fee367..e0a990326 100644 --- a/crates/cli/src/parse.rs +++ b/crates/cli/src/parse.rs @@ -380,8 +380,10 @@ pub fn parse_file_at_path( let tree = match encoding { Some(encoding) if encoding == ffi::TSInputEncodingUTF16LE => { let source_code_utf16 = source_code - .chunks_exact(2) - .map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]])) + .as_chunks::<2>() + .0 + .iter() + .map(|&chunk| u16::from_le_bytes(chunk)) .collect::>(); parser.parse_utf16_le_with_options( &mut |i, _| { @@ -397,8 +399,10 @@ pub fn parse_file_at_path( } Some(encoding) if encoding == ffi::TSInputEncodingUTF16BE => { let source_code_utf16 = source_code - .chunks_exact(2) - .map(|chunk| u16::from_be_bytes([chunk[0], chunk[1]])) + .as_chunks::<2>() + .0 + .iter() + .map(|&chunk| u16::from_be_bytes(chunk)) .collect::>(); parser.parse_utf16_be_with_options( &mut |i, _| { diff --git a/crates/cli/src/tags.rs b/crates/cli/src/tags.rs index 2529bf5b1..81e478469 100644 --- a/crates/cli/src/tags.rs +++ b/crates/cli/src/tags.rs @@ -49,7 +49,7 @@ pub fn generate_tags( &mut stdout, "{indent_str}{:<10}\t | {:<8}\t{} {} - {} `{}`", str::from_utf8(&source[tag.name_range]).unwrap_or(""), - &config.syntax_type_name(tag.syntax_type_id), + config.syntax_type_name(tag.syntax_type_id), if tag.is_definition { "def" } else { "ref" }, tag.span.start, tag.span.end, @@ -59,7 +59,7 @@ pub fn generate_tags( if docs.len() > 120 { write!(&mut stdout, "\t{:?}...", docs.get(0..120).unwrap_or(""))?; } else { - write!(&mut stdout, "\t{:?}", &docs)?; + write!(&mut stdout, "\t{docs:?}")?; } } writeln!(&mut stdout)?; diff --git a/crates/cli/src/tests/parser_test.rs b/crates/cli/src/tests/parser_test.rs index 2660794fc..32e6e5872 100644 --- a/crates/cli/src/tests/parser_test.rs +++ b/crates/cli/src/tests/parser_test.rs @@ -1117,7 +1117,7 @@ fn test_parsing_with_timeout_during_balancing() { Some(ParseOptions::new().progress_callback(&mut |state| { // Because we've already finished parsing, we should only be resuming the // balancing phase. - assert!(state.current_byte_offset() == current_byte_offset); + assert_eq!(state.current_byte_offset(), current_byte_offset); ControlFlow::Continue(()) })), ) diff --git a/crates/generate/src/bitvec.rs b/crates/generate/src/bitvec.rs index 28be2f817..e7e04fd7a 100644 --- a/crates/generate/src/bitvec.rs +++ b/crates/generate/src/bitvec.rs @@ -152,14 +152,14 @@ impl BitVec { } #[must_use] - pub fn get(&self, index: usize) -> Option { + pub const fn get(&self, index: usize) -> Option { if index >= self.num_bits as usize { return None; } Some(self.as_slice()[index / 64] >> (index % 64) & 1 != 0) } - pub fn set(&mut self, index: usize, val: bool) { + pub const fn set(&mut self, index: usize, val: bool) { let word_idx = index / 64; let bit_idx = index % 64; let words = self.as_full_slice_mut(); @@ -213,14 +213,14 @@ impl BitVec { } #[must_use] - pub fn last(&self) -> Option { + pub const fn last(&self) -> Option { if self.num_bits == 0 { return None; } self.get(self.num_bits as usize - 1) } - pub fn pop(&mut self) -> Option { + pub const fn pop(&mut self) -> Option { if self.num_bits == 0 { return None; } diff --git a/crates/highlight/src/highlight.rs b/crates/highlight/src/highlight.rs index 34b34f468..82d5d945f 100644 --- a/crates/highlight/src/highlight.rs +++ b/crates/highlight/src/highlight.rs @@ -562,8 +562,10 @@ impl<'a> HighlightIterLayer<'a> { let tree = match encoding { Some(encoding) if encoding == ffi::TSInputEncodingUTF16LE => { let source_code_utf16 = source - .chunks_exact(2) - .map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]])) + .as_chunks::<2>() + .0 + .iter() + .map(|&chunk| u16::from_le_bytes(chunk)) .collect::>(); highlighter .parser @@ -582,8 +584,10 @@ impl<'a> HighlightIterLayer<'a> { } Some(encoding) if encoding == ffi::TSInputEncodingUTF16BE => { let source_code_utf16 = source - .chunks_exact(2) - .map(|chunk| u16::from_be_bytes([chunk[0], chunk[1]])) + .as_chunks::<2>() + .0 + .iter() + .map(|&chunk| u16::from_be_bytes(chunk)) .collect::>(); highlighter .parser diff --git a/crates/tags/src/tags.rs b/crates/tags/src/tags.rs index cd667dcc7..40dfc75e4 100644 --- a/crates/tags/src/tags.rs +++ b/crates/tags/src/tags.rs @@ -516,13 +516,10 @@ where // reuse results from the previous tag. let mut prev_utf16_column = 0; let mut prev_utf8_byte = name_range.start - span.start.column; - let line_info = self.prev_line_info.as_ref().and_then(|info| { - if info.utf8_position.row == span.start.row { - Some(info) - } else { - None - } - }); + let line_info = self + .prev_line_info + .as_ref() + .filter(|&info| info.utf8_position.row == span.start.row); let line_range = if let Some(line_info) = line_info { if line_info.utf8_position.column <= span.start.column { prev_utf8_byte = line_info.utf8_byte; diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index a5192c1f0..de2331752 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -2439,9 +2439,7 @@ impl Query { } let column = offset - line_start; - let kind; - let message; - match error_type { + let (message, kind) = match error_type { // Error types that report names ffi::TSQueryErrorNodeType | ffi::TSQueryErrorField | ffi::TSQueryErrorCapture => { let suffix = source.split_at(offset).1; @@ -2464,27 +2462,29 @@ impl Query { } }) .unwrap_or(suffix.len()); - message = format!("\"{}\"", suffix.split_at(end_offset).0); - kind = match error_type { - ffi::TSQueryErrorNodeType => QueryErrorKind::NodeType, - ffi::TSQueryErrorField => QueryErrorKind::Field, - ffi::TSQueryErrorCapture => QueryErrorKind::Capture, - _ => unreachable!(), - }; + ( + format!("\"{}\"", suffix.split_at(end_offset).0), + match error_type { + ffi::TSQueryErrorNodeType => QueryErrorKind::NodeType, + ffi::TSQueryErrorField => QueryErrorKind::Field, + ffi::TSQueryErrorCapture => QueryErrorKind::Capture, + _ => unreachable!(), + }, + ) } // Error types that report positions - _ => { - message = line_containing_error.map_or_else( + _ => ( + line_containing_error.map_or_else( || "Unexpected EOF".to_string(), |line| line.to_string() + "\n" + &" ".repeat(offset - line_start) + "^", - ); - kind = match error_type { + ), + match error_type { ffi::TSQueryErrorStructure => QueryErrorKind::Structure, _ => QueryErrorKind::Syntax, - }; - } - } + }, + ), + }; Err(QueryError { row,