fix: Naming; Lifetimes; deny(rust_2018_idioms)

- One has to think about lifetimes if a type has one:
  - `<&'a Node<'tree>>::language` now returns `Language<'tree>` instead of
    `Language<'a>`, as it should;
- Renamed `struct TreeCursor<'cursor>` into `struct TreeCursor<'tree>`,
  to be consistant with the usages and reduse confusion;
- Remove explicit "outlives" requirements from `QueryMatches`, `QueryCaptures`,
  and their impl blocks, because they're inferred
- TODO: should `'query` be renamed into `'cursor`?
This commit is contained in:
DanikVitek 2026-01-10 23:01:55 +02:00
parent 630fa52717
commit ffd777ba65
29 changed files with 169 additions and 158 deletions

View file

@ -765,7 +765,7 @@ impl Loader {
}
#[must_use]
pub fn get_all_language_configurations(&self) -> Vec<(&LanguageConfiguration, &Path)> {
pub fn get_all_language_configurations(&self) -> Vec<(&LanguageConfiguration<'static>, &Path)> {
self.language_configurations
.iter()
.map(|c| (c, self.languages_by_id[c.language_id].0.as_ref()))
@ -775,7 +775,7 @@ impl Loader {
pub fn language_configuration_for_scope(
&self,
scope: &str,
) -> LoaderResult<Option<(Language, &LanguageConfiguration)>> {
) -> LoaderResult<Option<(Language, &LanguageConfiguration<'static>)>> {
for configuration in &self.language_configurations {
if configuration.scope.as_ref().is_some_and(|s| s == scope) {
let language = self.language_for_id(configuration.language_id)?;
@ -788,7 +788,7 @@ impl Loader {
pub fn language_configuration_for_first_line_regex(
&self,
path: &Path,
) -> LoaderResult<Option<(Language, &LanguageConfiguration)>> {
) -> LoaderResult<Option<(Language, &LanguageConfiguration<'static>)>> {
self.language_configuration_ids_by_first_line_regex
.iter()
.try_fold(None, |_, (regex, ids)| {
@ -817,7 +817,7 @@ impl Loader {
pub fn language_configuration_for_file_name(
&self,
path: &Path,
) -> LoaderResult<Option<(Language, &LanguageConfiguration)>> {
) -> LoaderResult<Option<(Language, &LanguageConfiguration<'static>)>> {
// Find all the language configurations that match this file name
// or a suffix of the file name.
let configuration_ids = path
@ -889,7 +889,7 @@ impl Loader {
pub fn language_configuration_for_injection_string(
&self,
string: &str,
) -> LoaderResult<Option<(Language, &LanguageConfiguration)>> {
) -> LoaderResult<Option<(Language, &LanguageConfiguration<'static>)>> {
let mut best_match_length = 0;
let mut best_match_position = None;
for (i, configuration) in self.language_configurations.iter().enumerate() {
@ -915,7 +915,7 @@ impl Loader {
pub fn language_for_configuration(
&self,
configuration: &LanguageConfiguration,
configuration: &LanguageConfiguration<'_>,
) -> LoaderResult<Language> {
self.language_for_id(configuration.language_id)
}
@ -946,7 +946,7 @@ impl Loader {
self.load_language_at_path(config).map(|_| ())
}
pub fn load_language_at_path(&self, mut config: CompileConfig) -> LoaderResult<Language> {
pub fn load_language_at_path(&self, mut config: CompileConfig<'_>) -> LoaderResult<Language> {
let grammar_path = config.src_path.join("grammar.json");
config.name = Self::grammar_json_name(&grammar_path)?;
self.load_language_at_path_with_name(config)
@ -954,7 +954,7 @@ impl Loader {
pub fn load_language_at_path_with_name(
&self,
mut config: CompileConfig,
mut config: CompileConfig<'_>,
) -> LoaderResult<Language> {
let mut lib_name = config.name.clone();
let language_fn_name = format!("tree_sitter_{}", config.name.replace('-', "_"));
@ -1128,7 +1128,7 @@ impl Loader {
})?;
let language = unsafe {
let language_fn = library
.get::<Symbol<unsafe extern "C" fn() -> Language>>(function_name.as_bytes())
.get::<Symbol<'_, unsafe extern "C" fn() -> Language>>(function_name.as_bytes())
.map_err(|e| {
LoaderError::Symbol(SymbolError {
error: e,
@ -1144,7 +1144,7 @@ impl Loader {
fn compile_parser_to_dylib(
&self,
config: &CompileConfig,
config: &CompileConfig<'_>,
lock_file: &fs::File,
lock_path: &Path,
) -> LoaderResult<()> {
@ -1534,7 +1534,9 @@ impl Loader {
}
#[must_use]
pub fn get_language_configuration_in_current_path(&self) -> Option<&LanguageConfiguration> {
pub fn get_language_configuration_in_current_path(
&self,
) -> Option<&LanguageConfiguration<'static>> {
self.language_configuration_in_current_path
.map(|i| &self.language_configurations[i])
}
@ -1543,7 +1545,7 @@ impl Loader {
&mut self,
parser_path: &Path,
set_current_path_config: bool,
) -> LoaderResult<&[LanguageConfiguration]> {
) -> LoaderResult<&[LanguageConfiguration<'static>]> {
let initial_language_configuration_count = self.language_configurations.len();
match TreeSitterJSON::from_file(parser_path) {