chore: misc clippy lints
This commit is contained in:
parent
50bea73ce3
commit
5c6445edea
22 changed files with 74 additions and 72 deletions
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
|
|
@ -17,6 +17,7 @@ jobs:
|
|||
- run: rustup toolchain install stable --profile minimal
|
||||
- run: rustup toolchain install nightly --profile minimal
|
||||
- run: rustup component add --toolchain nightly rustfmt
|
||||
- run: rustup component add --toolchain nightly clippy
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: make lint
|
||||
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -107,7 +107,7 @@ lint:
|
|||
cargo update --workspace --locked --quiet
|
||||
cargo check --workspace --all-targets
|
||||
cargo +nightly fmt --all --check
|
||||
cargo clippy --workspace --all-targets -- -D warnings
|
||||
cargo +nightly clippy --workspace --all-targets -- -D warnings
|
||||
|
||||
format:
|
||||
cargo +nightly fmt --all
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
[npmjs.com]: https://www.npmjs.org/package/tree-sitter-cli
|
||||
[npmjs.com badge]: https://img.shields.io/npm/v/tree-sitter-cli.svg?color=%23BF4A4A
|
||||
|
||||
The Tree-sitter CLI allows you to develop, test, and use Tree-sitter grammars from the command line. It works on MacOS, Linux, and Windows.
|
||||
The Tree-sitter CLI allows you to develop, test, and use Tree-sitter grammars from the command line. It works on `MacOS`, `Linux`, and `Windows`.
|
||||
|
||||
### Installation
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl<'a> CoincidentTokenIndex<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for CoincidentTokenIndex<'a> {
|
||||
impl fmt::Debug for CoincidentTokenIndex<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "CoincidentTokenIndex {{")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ impl<'a> ParseItemSet<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for ParseItemDisplay<'a> {
|
||||
impl fmt::Display for ParseItemDisplay<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
if self.0.is_augmented() {
|
||||
write!(f, "START →")?;
|
||||
|
|
@ -243,7 +243,7 @@ impl<'a> fmt::Display for ParseItemDisplay<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for TokenSetDisplay<'a> {
|
||||
impl fmt::Display for TokenSetDisplay<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "[")?;
|
||||
for (i, symbol) in self.0.iter().enumerate() {
|
||||
|
|
@ -268,7 +268,7 @@ impl<'a> fmt::Display for TokenSetDisplay<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for ParseItemSetDisplay<'a> {
|
||||
impl fmt::Display for ParseItemSetDisplay<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
for (item, lookaheads) in &self.0.entries {
|
||||
writeln!(
|
||||
|
|
@ -282,7 +282,7 @@ impl<'a> fmt::Display for ParseItemSetDisplay<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Hash for ParseItem<'a> {
|
||||
impl Hash for ParseItem<'_> {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_u32(self.variable_index);
|
||||
hasher.write_u32(self.step_index);
|
||||
|
|
@ -311,7 +311,7 @@ impl<'a> Hash for ParseItem<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for ParseItem<'a> {
|
||||
impl PartialEq for ParseItem<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if self.variable_index != other.variable_index
|
||||
|| self.step_index != other.step_index
|
||||
|
|
@ -348,7 +348,7 @@ impl<'a> PartialEq for ParseItem<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Ord for ParseItem<'a> {
|
||||
impl Ord for ParseItem<'_> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.step_index
|
||||
.cmp(&other.step_index)
|
||||
|
|
@ -388,15 +388,15 @@ impl<'a> Ord for ParseItem<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialOrd for ParseItem<'a> {
|
||||
impl PartialOrd for ParseItem<'_> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Eq for ParseItem<'a> {}
|
||||
impl Eq for ParseItem<'_> {}
|
||||
|
||||
impl<'a> Hash for ParseItemSet<'a> {
|
||||
impl Hash for ParseItemSet<'_> {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_usize(self.entries.len());
|
||||
for (item, lookaheads) in &self.entries {
|
||||
|
|
@ -406,7 +406,7 @@ impl<'a> Hash for ParseItemSet<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Hash for ParseItemSetCore<'a> {
|
||||
impl Hash for ParseItemSetCore<'_> {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_usize(self.entries.len());
|
||||
for item in &self.entries {
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ impl<'a> ParseItemSetBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for ParseItemSetBuilder<'a> {
|
||||
impl fmt::Debug for ParseItemSetBuilder<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "ParseItemSetBuilder {{")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ struct Minimizer<'a> {
|
|||
simple_aliases: &'a AliasMap,
|
||||
}
|
||||
|
||||
impl<'a> Minimizer<'a> {
|
||||
impl Minimizer<'_> {
|
||||
fn remove_unit_reductions(&mut self) {
|
||||
let mut aliased_symbols = HashSet::new();
|
||||
for variable in &self.syntax_grammar.variables {
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ impl<'a> TokenConflictMap<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for TokenConflictMap<'a> {
|
||||
impl fmt::Debug for TokenConflictMap<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "TokenConflictMap {{")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -66,16 +66,12 @@ pub fn generate_parser_in_directory(
|
|||
}
|
||||
}
|
||||
|
||||
let grammar_path = grammar_path
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_path.join("grammar.js"));
|
||||
let grammar_path = grammar_path.map_or_else(|| repo_path.join("grammar.js"), PathBuf::from);
|
||||
|
||||
// Read the grammar file.
|
||||
let grammar_json = load_grammar_file(&grammar_path, js_runtime)?;
|
||||
|
||||
let src_path = out_path
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| repo_path.join("src"));
|
||||
let src_path = out_path.map_or_else(|| repo_path.join("src"), PathBuf::from);
|
||||
let header_path = src_path.join("tree_sitter");
|
||||
|
||||
// Ensure that the output directories exist.
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ struct Interner<'a> {
|
|||
grammar: &'a InputGrammar,
|
||||
}
|
||||
|
||||
impl<'a> Interner<'a> {
|
||||
impl Interner<'_> {
|
||||
fn intern_rule(&self, rule: &Rule, name: Option<&str>) -> Result<Rule> {
|
||||
match rule {
|
||||
Rule::Choice(elements) => {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl PathsJSON {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
const fn is_empty(&self) -> bool {
|
||||
matches!(self, Self::Empty)
|
||||
}
|
||||
}
|
||||
|
|
@ -141,6 +141,7 @@ pub struct TreeSitterJSON {
|
|||
}
|
||||
|
||||
impl TreeSitterJSON {
|
||||
#[must_use]
|
||||
pub fn from_file(path: &Path) -> Option<Self> {
|
||||
if let Ok(file) = fs::File::open(path.join("tree-sitter.json")) {
|
||||
Some(serde_json::from_reader(file).ok()?)
|
||||
|
|
@ -149,6 +150,7 @@ impl TreeSitterJSON {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_multiple_language_configs(&self) -> bool {
|
||||
self.grammars.len() > 1
|
||||
}
|
||||
|
|
@ -366,7 +368,6 @@ impl<'a> CompileConfig<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Loader {}
|
||||
unsafe impl Sync for Loader {}
|
||||
|
||||
impl Loader {
|
||||
|
|
@ -1004,7 +1005,7 @@ impl Loader {
|
|||
let mut command = match source {
|
||||
EmccSource::Docker => Command::new("docker"),
|
||||
EmccSource::Podman => Command::new("podman"),
|
||||
_ => unreachable!(),
|
||||
EmccSource::Native => unreachable!(),
|
||||
};
|
||||
command.args(["run", "--rm"]);
|
||||
|
||||
|
|
@ -1344,7 +1345,7 @@ impl Loader {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> LanguageConfiguration<'a> {
|
||||
impl LanguageConfiguration<'_> {
|
||||
#[cfg(feature = "tree-sitter-highlight")]
|
||||
pub fn highlight_config(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ const TEST_BINDING_PY_TEMPLATE: &str = include_str!("./templates/test_binding.py
|
|||
const PACKAGE_SWIFT_TEMPLATE: &str = include_str!("./templates/package.swift");
|
||||
const TESTS_SWIFT_TEMPLATE: &str = include_str!("./templates/tests.swift");
|
||||
|
||||
#[must_use]
|
||||
pub fn path_in_ignore(repo_path: &Path) -> bool {
|
||||
[
|
||||
"bindings",
|
||||
|
|
@ -130,6 +131,7 @@ pub struct JsonConfigOpts {
|
|||
}
|
||||
|
||||
impl JsonConfigOpts {
|
||||
#[must_use]
|
||||
pub fn to_tree_sitter_json(self) -> TreeSitterJSON {
|
||||
TreeSitterJSON {
|
||||
grammars: vec![Grammar {
|
||||
|
|
@ -255,8 +257,7 @@ pub fn migrate_package_json(repo_path: &Path) -> Result<bool> {
|
|||
authors: {
|
||||
let authors = old_config
|
||||
.author
|
||||
.map(|a| vec![a].into_iter())
|
||||
.unwrap_or_else(|| vec![].into_iter())
|
||||
.map_or_else(|| vec![].into_iter(), |a| vec![a].into_iter())
|
||||
.chain(old_config.maintainers.unwrap_or_default())
|
||||
.filter_map(|a| match a {
|
||||
PackageJSONAuthor::String(s) => {
|
||||
|
|
@ -362,7 +363,7 @@ pub fn generate_grammar_files(
|
|||
repo_path: &Path,
|
||||
language_name: &str,
|
||||
_allow_update: bool,
|
||||
opts: Option<JsonConfigOpts>,
|
||||
opts: Option<&JsonConfigOpts>,
|
||||
) -> Result<()> {
|
||||
let dashed_language_name = language_name.to_kebab_case();
|
||||
|
||||
|
|
@ -371,17 +372,15 @@ pub fn generate_grammar_files(
|
|||
true,
|
||||
|path| {
|
||||
// invariant: opts is always Some when `tree-sitter.json` doesn't exist
|
||||
let Some(opts) = opts.clone() else {
|
||||
unreachable!()
|
||||
};
|
||||
let Some(opts) = opts else { unreachable!() };
|
||||
|
||||
let tree_sitter_json = opts.to_tree_sitter_json();
|
||||
let tree_sitter_json = opts.clone().to_tree_sitter_json();
|
||||
write_file(path, serde_json::to_string_pretty(&tree_sitter_json)?)
|
||||
},
|
||||
|path| {
|
||||
// updating the config, if needed
|
||||
if let Some(opts) = opts.clone() {
|
||||
let tree_sitter_json = opts.to_tree_sitter_json();
|
||||
if let Some(opts) = opts {
|
||||
let tree_sitter_json = opts.clone().to_tree_sitter_json();
|
||||
write_file(path, serde_json::to_string_pretty(&tree_sitter_json)?)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -674,7 +673,7 @@ pub fn get_root_path(path: &Path) -> Result<PathBuf> {
|
|||
}
|
||||
})
|
||||
.transpose()?;
|
||||
if let Some(true) = json {
|
||||
if json == Some(true) {
|
||||
return Ok(pathbuf.parent().unwrap().to_path_buf());
|
||||
}
|
||||
pathbuf.pop(); // filename
|
||||
|
|
@ -838,7 +837,7 @@ fn generate_file(
|
|||
|
||||
match generate_opts.description {
|
||||
Some(description) => {
|
||||
replacement = replacement.replace(PARSER_DESCRIPTION_PLACEHOLDER, description)
|
||||
replacement = replacement.replace(PARSER_DESCRIPTION_PLACEHOLDER, description);
|
||||
}
|
||||
_ => {
|
||||
replacement = replacement.replace(
|
||||
|
|
@ -847,7 +846,7 @@ fn generate_file(
|
|||
"{} grammar for tree-sitter",
|
||||
language_name.to_upper_camel_case()
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -858,7 +857,7 @@ fn generate_file(
|
|||
PARSER_URL_STRIPPED_PLACEHOLDER,
|
||||
&repository.replace("https://", "").to_lowercase(),
|
||||
)
|
||||
.replace(PARSER_URL_PLACEHOLDER, &repository.to_lowercase())
|
||||
.replace(PARSER_URL_PLACEHOLDER, &repository.to_lowercase());
|
||||
}
|
||||
_ => {
|
||||
replacement = replacement
|
||||
|
|
@ -875,7 +874,7 @@ fn generate_file(
|
|||
"https://github.com/tree-sitter/tree-sitter-{}",
|
||||
language_name.to_lowercase()
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -674,7 +674,12 @@ impl Init {
|
|||
(json.grammars[0].name.clone(), None)
|
||||
};
|
||||
|
||||
generate_grammar_files(current_dir, &language_name, self.update, json_config_opts)?;
|
||||
generate_grammar_files(
|
||||
current_dir,
|
||||
&language_name,
|
||||
self.update,
|
||||
json_config_opts.as_ref(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,9 +372,8 @@ pub fn parse_file_at_path(parser: &mut Parser, opts: &ParseFileOptions) -> Resul
|
|||
bytes: source_code.len(),
|
||||
duration: Some(duration),
|
||||
});
|
||||
} else {
|
||||
parser.stop_printing_dot_graphs();
|
||||
}
|
||||
parser.stop_printing_dot_graphs();
|
||||
|
||||
if opts.print_time {
|
||||
let duration = time.elapsed();
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ fn run_tests(
|
|||
parser: &mut Parser,
|
||||
test_entry: TestEntry,
|
||||
opts: &mut TestOptions,
|
||||
mut indent_level: i32,
|
||||
mut indent_level: u32,
|
||||
failures: &mut Vec<(String, String, String)>,
|
||||
corrected_entries: &mut Vec<(String, String, String, String, usize, usize)>,
|
||||
has_parse_errors: &mut bool,
|
||||
|
|
|
|||
|
|
@ -273,13 +273,13 @@ impl std::fmt::Display for Pattern {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tree> PartialOrd for Match<'a, 'tree> {
|
||||
impl PartialOrd for Match<'_, '_> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tree> Ord for Match<'a, 'tree> {
|
||||
impl Ord for Match<'_, '_> {
|
||||
// Tree-sitter returns matches in the order that they terminate
|
||||
// during a depth-first walk of the tree. If multiple matches
|
||||
// terminate on the same node, those matches are produced in the
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ fn test_parsing_with_custom_utf16le_input() {
|
|||
|
||||
let lines = ["pub fn foo() {", " 1", "}"]
|
||||
.iter()
|
||||
.map(|s| s.encode_utf16().map(|u| u.to_le()).collect::<Vec<_>>())
|
||||
.map(|s| s.encode_utf16().map(u16::to_le).collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let newline = [('\n' as u16).to_le()];
|
||||
|
|
@ -267,7 +267,7 @@ fn test_parsing_text_with_byte_order_mark() {
|
|||
.parse_utf16_le(
|
||||
"\u{FEFF}fn a() {}"
|
||||
.encode_utf16()
|
||||
.map(|u| u.to_le())
|
||||
.map(u16::to_le)
|
||||
.collect::<Vec<_>>(),
|
||||
None,
|
||||
)
|
||||
|
|
@ -1134,7 +1134,7 @@ fn test_parsing_utf16_code_with_errors_at_the_end_of_an_included_range() {
|
|||
let source_code = "<script>a.</script>";
|
||||
let utf16_source_code = source_code
|
||||
.encode_utf16()
|
||||
.map(|u| u.to_le())
|
||||
.map(u16::to_le)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let start_byte = 2 * source_code.find("a.").unwrap();
|
||||
|
|
|
|||
|
|
@ -3488,10 +3488,10 @@ fn test_query_captures_with_matches_removed() {
|
|||
|
||||
let mut captures = cursor.captures(&query, tree.root_node(), source.as_bytes());
|
||||
while let Some((m, i)) = captures.next() {
|
||||
println!("captured: {:?}, {}", m, i);
|
||||
println!("captured: {m:?}, {i}");
|
||||
let capture = m.captures[*i];
|
||||
let text = capture.node.utf8_text(source.as_bytes()).unwrap();
|
||||
println!("captured: {:?}", text);
|
||||
println!("captured: {text:?}");
|
||||
if text == "a" {
|
||||
m.remove();
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -705,11 +705,11 @@ fn test_consistency_with_mid_codepoint_edit() {
|
|||
|
||||
#[test]
|
||||
fn test_tree_cursor_on_aliased_root_with_extra_child() {
|
||||
let source = r#"
|
||||
let source = r"
|
||||
fn main() {
|
||||
C/* hi */::<D>::E;
|
||||
}
|
||||
"#;
|
||||
";
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(&get_language("rust")).unwrap();
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl Tree {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tree> Node<'tree> {
|
||||
impl Node<'_> {
|
||||
/// Reconstructs a [`Node`] from a raw pointer.
|
||||
///
|
||||
/// # Safety
|
||||
|
|
@ -103,7 +103,7 @@ impl<'tree> Node<'tree> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TreeCursor<'a> {
|
||||
impl TreeCursor<'_> {
|
||||
/// Reconstructs a [`TreeCursor`] from a raw pointer.
|
||||
///
|
||||
/// # Safety
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ impl Drop for Language {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for LanguageRef<'a> {
|
||||
impl Deref for LanguageRef<'_> {
|
||||
type Target = Language;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
@ -692,7 +692,7 @@ impl Parser {
|
|||
position: ffi::TSPoint,
|
||||
bytes_read: *mut u32,
|
||||
) -> *const c_char {
|
||||
let (callback, text) = (payload as *mut (&mut F, Option<T>)).as_mut().unwrap();
|
||||
let (callback, text) = payload.cast::<(&mut F, Option<T>)>().as_mut().unwrap();
|
||||
*text = Some(callback(byte_offset as usize, position.into()));
|
||||
let slice = text.as_ref().unwrap().as_ref();
|
||||
*bytes_read = slice.len() as u32;
|
||||
|
|
@ -700,7 +700,7 @@ impl Parser {
|
|||
}
|
||||
|
||||
let c_input = ffi::TSInput {
|
||||
payload: &mut payload as *mut (&mut F, Option<T>) as *mut c_void,
|
||||
payload: core::ptr::addr_of_mut!(payload).cast::<c_void>(),
|
||||
read: Some(read::<T, F>),
|
||||
encoding: ffi::TSInputEncodingUTF8,
|
||||
};
|
||||
|
|
@ -737,7 +737,7 @@ impl Parser {
|
|||
/// * `text` The UTF16-encoded text to parse.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [Tree::edit].
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16_le(
|
||||
&mut self,
|
||||
input: impl AsRef<[u16]>,
|
||||
|
|
@ -760,7 +760,7 @@ impl Parser {
|
|||
/// empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [Tree::edit].
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16_le_with<T: AsRef<[u16]>, F: FnMut(usize, Point) -> T>(
|
||||
&mut self,
|
||||
callback: &mut F,
|
||||
|
|
@ -780,7 +780,7 @@ impl Parser {
|
|||
position: ffi::TSPoint,
|
||||
bytes_read: *mut u32,
|
||||
) -> *const c_char {
|
||||
let (callback, text) = (payload as *mut (&mut F, Option<T>)).as_mut().unwrap();
|
||||
let (callback, text) = payload.cast::<(&mut F, Option<T>)>().as_mut().unwrap();
|
||||
*text = Some(callback(
|
||||
(byte_offset / 2) as usize,
|
||||
Point {
|
||||
|
|
@ -794,7 +794,7 @@ impl Parser {
|
|||
}
|
||||
|
||||
let c_input = ffi::TSInput {
|
||||
payload: &mut payload as *mut (&mut F, Option<T>) as *mut c_void,
|
||||
payload: core::ptr::addr_of_mut!(payload).cast::<c_void>(),
|
||||
read: Some(read::<T, F>),
|
||||
encoding: ffi::TSInputEncodingUTF16LE,
|
||||
};
|
||||
|
|
@ -812,7 +812,7 @@ impl Parser {
|
|||
/// * `text` The UTF16-encoded text to parse.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [Tree::edit].
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16_be(
|
||||
&mut self,
|
||||
input: impl AsRef<[u16]>,
|
||||
|
|
@ -835,7 +835,7 @@ impl Parser {
|
|||
/// empty slice.
|
||||
/// * `old_tree` A previous syntax tree parsed from the same document. If the text of the
|
||||
/// document has changed since `old_tree` was created, then you must edit `old_tree` to match
|
||||
/// the new text using [Tree::edit].
|
||||
/// the new text using [`Tree::edit`].
|
||||
pub fn parse_utf16_be_with<T: AsRef<[u16]>, F: FnMut(usize, Point) -> T>(
|
||||
&mut self,
|
||||
callback: &mut F,
|
||||
|
|
@ -855,7 +855,7 @@ impl Parser {
|
|||
position: ffi::TSPoint,
|
||||
bytes_read: *mut u32,
|
||||
) -> *const c_char {
|
||||
let (callback, text) = (payload as *mut (&mut F, Option<T>)).as_mut().unwrap();
|
||||
let (callback, text) = payload.cast::<(&mut F, Option<T>)>().as_mut().unwrap();
|
||||
*text = Some(callback(
|
||||
(byte_offset / 2) as usize,
|
||||
Point {
|
||||
|
|
@ -865,10 +865,10 @@ impl Parser {
|
|||
));
|
||||
let slice = text.as_ref().unwrap().as_ref();
|
||||
*bytes_read = slice.len() as u32 * 2;
|
||||
slice.as_ptr() as *const c_char
|
||||
slice.as_ptr().cast::<c_char>()
|
||||
}
|
||||
let c_input = ffi::TSInput {
|
||||
payload: &mut payload as *mut (&mut F, Option<T>) as *mut c_void,
|
||||
payload: core::ptr::addr_of_mut!(payload).cast::<c_void>(),
|
||||
read: Some(read::<T, F>),
|
||||
encoding: ffi::TSInputEncodingUTF16BE,
|
||||
};
|
||||
|
|
@ -1394,6 +1394,7 @@ impl<'tree> Node<'tree> {
|
|||
}
|
||||
|
||||
/// Get the field name of this node's named child at the given index.
|
||||
#[must_use]
|
||||
pub fn field_name_for_named_child(&self, named_child_index: u32) -> Option<&'static str> {
|
||||
unsafe {
|
||||
let ptr = ffi::ts_node_field_name_for_named_child(self.0, named_child_index);
|
||||
|
|
@ -2842,9 +2843,9 @@ impl QueryProperty {
|
|||
}
|
||||
}
|
||||
|
||||
/// Provide StreamingIterator instead of traditional one as the underlying object in the C library
|
||||
/// gets updated on each iteration. Created copies would have their internal state overwritten,
|
||||
/// leading to Undefined Behavior
|
||||
/// Provide a `StreamingIterator` instead of the traditional `Iterator`, as the
|
||||
/// underlying object in the C library gets updated on each iteration. Copies would
|
||||
/// have their internal state overwritten, leading to Undefined Behavior
|
||||
impl<'query, 'tree: 'query, T: TextProvider<I>, I: AsRef<[u8]>> StreamingIterator
|
||||
for QueryMatches<'query, 'tree, T, I>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl WasmStore {
|
|||
unsafe {
|
||||
let mut error = MaybeUninit::<ffi::TSWasmError>::uninit();
|
||||
let store = ffi::ts_wasm_store_new(
|
||||
(engine as *const wasmtime::Engine as *mut wasmtime::Engine).cast(),
|
||||
(engine as *const wasmtime::Engine).cast_mut().cast(),
|
||||
error.as_mut_ptr(),
|
||||
);
|
||||
if store.is_null() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue