refactor(rust): misc fixes & tidying

This commit is contained in:
Amaan Qureshi 2024-04-09 21:42:59 -04:00
parent 5825e24d56
commit abc7910381
23 changed files with 137 additions and 127 deletions

View file

@ -91,7 +91,7 @@ impl<'tree> Node<'tree> {
///
/// `ptr` must be non-null.
#[must_use]
pub const unsafe fn from_raw(raw: TSNode) -> Node<'tree> {
pub const unsafe fn from_raw(raw: TSNode) -> Self {
Self(raw, PhantomData)
}
@ -109,7 +109,7 @@ impl<'a> TreeCursor<'a> {
///
/// `ptr` must be non-null.
#[must_use]
pub const unsafe fn from_raw(raw: TSTreeCursor) -> TreeCursor<'a> {
pub const unsafe fn from_raw(raw: TSTreeCursor) -> Self {
Self(raw, PhantomData)
}

View file

@ -1486,7 +1486,7 @@ impl fmt::Display for Node<'_> {
if sexp.is_empty() {
write!(f, "")
} else if !f.alternate() {
write!(f, "{}", sexp)
write!(f, "{sexp}")
} else {
write!(f, "{}", format_sexp(&sexp, f.width().unwrap_or(0)))
}
@ -1781,7 +1781,7 @@ impl Query {
let mut line_start = 0;
let mut row = 0;
let mut line_containing_error = None;
for line in source.split('\n') {
for line in source.lines() {
let line_end = line_start + line.len() + 1;
if line_end > offset {
line_containing_error = Some(line);
@ -2511,7 +2511,7 @@ impl<'tree> QueryMatch<'_, 'tree> {
} else if let Some(ref first_chunk) = self.first_chunk {
first_chunk.as_ref()
} else {
Default::default()
&[]
}
}
}
@ -2823,7 +2823,7 @@ impl<'a> Iterator for LossyUtf8<'a> {
}
match std::str::from_utf8(self.bytes) {
Ok(valid) => {
self.bytes = Default::default();
self.bytes = &[];
Some(valid)
}
Err(error) => {
@ -2901,6 +2901,7 @@ impl fmt::Display for QueryError {
}
#[doc(hidden)]
#[must_use]
pub fn format_sexp(sexp: &str, initial_indent_level: usize) -> String {
let mut indent_level = initial_indent_level;
let mut formatted = String::new();