mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:26:23 -04:00
fix(rust): address new clippy lints
This commit is contained in:
parent
cc7be1fd47
commit
17a02fef5e
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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::<Vec<_>>();
|
||||
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::<Vec<_>>();
|
||||
parser.parse_utf16_be_with_options(
|
||||
&mut |i, _| {
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
})),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -152,14 +152,14 @@ impl BitVec {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get(&self, index: usize) -> Option<bool> {
|
||||
pub const fn get(&self, index: usize) -> Option<bool> {
|
||||
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<bool> {
|
||||
pub const fn last(&self) -> Option<bool> {
|
||||
if self.num_bits == 0 {
|
||||
return None;
|
||||
}
|
||||
self.get(self.num_bits as usize - 1)
|
||||
}
|
||||
|
||||
pub fn pop(&mut self) -> Option<bool> {
|
||||
pub const fn pop(&mut self) -> Option<bool> {
|
||||
if self.num_bits == 0 {
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<Vec<_>>();
|
||||
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::<Vec<_>>();
|
||||
highlighter
|
||||
.parser
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue