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:
parent
630fa52717
commit
ffd777ba65
29 changed files with 169 additions and 158 deletions
|
|
@ -4,7 +4,7 @@ use super::{scope_sequence::ScopeSequence, LOG_ENABLED, LOG_GRAPH_ENABLED};
|
|||
use crate::util;
|
||||
|
||||
pub fn check_consistent_sizes(tree: &Tree, input: &[u8]) {
|
||||
fn check(node: Node, line_offsets: &[usize]) {
|
||||
fn check(node: Node<'_>, line_offsets: &[usize]) {
|
||||
let start_byte = node.start_byte();
|
||||
let end_byte = node.end_byte();
|
||||
let start_point = node.start_position();
|
||||
|
|
|
|||
|
|
@ -1188,7 +1188,7 @@ fn generate_file(
|
|||
path: &Path,
|
||||
template: &str,
|
||||
language_name: &str,
|
||||
generate_opts: &GenerateOpts,
|
||||
generate_opts: &GenerateOpts<'_>,
|
||||
) -> Result<()> {
|
||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ pub fn paint(color: Option<impl Into<Color>>, text: &str) -> String {
|
|||
struct Logger;
|
||||
|
||||
impl Log for Logger {
|
||||
fn enabled(&self, _: &Metadata) -> bool {
|
||||
fn enabled(&self, _: &Metadata<'_>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
fn log(&self, record: &Record<'_>) {
|
||||
match record.level() {
|
||||
Level::Error => eprintln!(
|
||||
"{} {}",
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ pub fn parse_file_at_path(
|
|||
path: &Path,
|
||||
name: &str,
|
||||
max_path_length: usize,
|
||||
opts: &mut ParseFileOptions,
|
||||
opts: &mut ParseFileOptions<'_>,
|
||||
) -> Result<()> {
|
||||
let mut _log_session = None;
|
||||
parser.set_language(language)?;
|
||||
|
|
@ -774,7 +774,7 @@ pub fn render_cst<'a, 'b: 'a>(
|
|||
source_code: &[u8],
|
||||
tree: &'b Tree,
|
||||
cursor: &mut TreeCursor<'a>,
|
||||
opts: &ParseFileOptions,
|
||||
opts: &ParseFileOptions<'_>,
|
||||
out: &mut impl Write,
|
||||
) -> Result<()> {
|
||||
let lossy_source_code = String::from_utf8_lossy(source_code);
|
||||
|
|
@ -841,9 +841,9 @@ fn render_node_text(source: &str) -> String {
|
|||
}
|
||||
|
||||
fn write_node_text(
|
||||
opts: &ParseFileOptions,
|
||||
opts: &ParseFileOptions<'_>,
|
||||
out: &mut impl Write,
|
||||
cursor: &TreeCursor,
|
||||
cursor: &TreeCursor<'_>,
|
||||
is_named: bool,
|
||||
source: &str,
|
||||
color: Option<impl Into<Color> + Copy>,
|
||||
|
|
@ -906,7 +906,7 @@ fn write_node_text(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn render_line_feed(source: &str, opts: &ParseFileOptions) -> String {
|
||||
fn render_line_feed(source: &str, opts: &ParseFileOptions<'_>) -> String {
|
||||
if cfg!(windows) {
|
||||
source.replace("\r\n", &paint(opts.parse_theme.line_feed, "\r\n"))
|
||||
} else {
|
||||
|
|
@ -915,8 +915,8 @@ fn render_line_feed(source: &str, opts: &ParseFileOptions) -> String {
|
|||
}
|
||||
|
||||
fn render_node_range(
|
||||
opts: &ParseFileOptions,
|
||||
cursor: &TreeCursor,
|
||||
opts: &ParseFileOptions<'_>,
|
||||
cursor: &TreeCursor<'_>,
|
||||
is_named: bool,
|
||||
is_multiline: bool,
|
||||
total_width: usize,
|
||||
|
|
@ -952,8 +952,8 @@ fn render_node_range(
|
|||
}
|
||||
|
||||
fn cst_render_node(
|
||||
opts: &ParseFileOptions,
|
||||
cursor: &mut TreeCursor,
|
||||
opts: &ParseFileOptions<'_>,
|
||||
cursor: &TreeCursor<'_>,
|
||||
source_code: &[u8],
|
||||
out: &mut impl Write,
|
||||
total_width: usize,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub struct Utf8Point {
|
|||
}
|
||||
|
||||
impl std::fmt::Display for Utf8Point {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "({}, {})", self.row, self.column)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -603,7 +603,7 @@ impl std::fmt::Display for TestSummary {
|
|||
|
||||
pub fn run_tests_at_path(
|
||||
parser: &mut Parser,
|
||||
opts: &TestOptions,
|
||||
opts: &TestOptions<'_>,
|
||||
test_summary: &mut TestSummary,
|
||||
) -> Result<()> {
|
||||
let test_entry = parse_tests(&opts.path)?;
|
||||
|
|
@ -814,7 +814,7 @@ impl TestCorrection {
|
|||
fn run_tests(
|
||||
parser: &mut Parser,
|
||||
test_entry: TestEntry,
|
||||
opts: &TestOptions,
|
||||
opts: &TestOptions<'_>,
|
||||
test_summary: &mut TestSummary,
|
||||
corrected_entries: &mut Vec<TestCorrection>,
|
||||
is_root: bool,
|
||||
|
|
@ -1070,7 +1070,9 @@ fn run_tests(
|
|||
|
||||
let mut ran_test_in_group = false;
|
||||
|
||||
let matches_filter = |name: &str, file_name: &Option<String>, opts: &TestOptions| {
|
||||
let matches_filter = |name: &str,
|
||||
file_name: &Option<String>,
|
||||
opts: &TestOptions<'_>| {
|
||||
if let (Some(test_file_path), Some(filter_file_name)) = (file_name, &opts.file_name)
|
||||
{
|
||||
if !filter_file_name.eq(test_file_path) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub struct Failure {
|
|||
impl std::error::Error for Failure {}
|
||||
|
||||
impl std::fmt::Display for Failure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Failure - row: {}, column: {}, expected highlight '{}', actual highlights: ",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub struct Failure {
|
|||
impl std::error::Error for Failure {}
|
||||
|
||||
impl std::fmt::Display for Failure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Failure - row: {}, column: {}, expected tag: '{}', actual tag: ",
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ impl Pattern {
|
|||
(pattern, pattern_start..pattern_end)
|
||||
}
|
||||
|
||||
fn random_pattern_for_node(cursor: &mut TreeCursor, rng: &mut impl Rng) -> Self {
|
||||
fn random_pattern_for_node(cursor: &mut TreeCursor<'_>, rng: &mut impl Rng) -> Self {
|
||||
let node = cursor.node();
|
||||
|
||||
// Sometimes specify the node's type, sometimes use a wildcard.
|
||||
|
|
@ -225,7 +225,7 @@ impl Pattern {
|
|||
}
|
||||
|
||||
// Find every matching combination of child patterns and child nodes.
|
||||
let mut finished_matches = Vec::<Match>::new();
|
||||
let mut finished_matches = Vec::<Match<'_, 'tree>>::new();
|
||||
if cursor.goto_first_child() {
|
||||
let mut match_states = vec![(0, mat)];
|
||||
loop {
|
||||
|
|
@ -306,7 +306,7 @@ impl Ord for Match<'_, '_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn compare_depth_first(a: Node, b: Node) -> Ordering {
|
||||
fn compare_depth_first(a: Node<'_>, b: Node<'_>) -> Ordering {
|
||||
let a = a.byte_range();
|
||||
let b = b.byte_range();
|
||||
a.start.cmp(&b.start).then_with(|| b.end.cmp(&a.end))
|
||||
|
|
|
|||
|
|
@ -1219,7 +1219,7 @@ private:
|
|||
);
|
||||
}
|
||||
|
||||
fn get_all_nodes(tree: &Tree) -> Vec<Node> {
|
||||
fn get_all_nodes(tree: &Tree) -> Vec<Node<'_>> {
|
||||
let mut result = Vec::new();
|
||||
let mut visited_children = false;
|
||||
let mut cursor = tree.walk();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ pub fn test_with_seed(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
impl Parse for Args {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
||||
let mut retry = None;
|
||||
let mut seed = None;
|
||||
let mut seed_fn = None;
|
||||
|
|
|
|||
|
|
@ -3971,7 +3971,7 @@ fn test_query_text_callback_returns_chunks() {
|
|||
parser.set_language(&language).unwrap();
|
||||
let tree = parser.parse(source, None).unwrap();
|
||||
let mut cursor = QueryCursor::new();
|
||||
let captures = cursor.captures(&query, tree.root_node(), |node: Node| {
|
||||
let captures = cursor.captures(&query, tree.root_node(), |node: Node<'_>| {
|
||||
chunks_in_range(node.byte_range())
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue