Skip to content

Commit

Permalink
chore: a few minor lints
Browse files Browse the repository at this point in the history
* do not use `&` for the format args as it cannot (yet) be optimized by the compiler
* a few format inlining
  • Loading branch information
nyurik authored and amaanq committed Jan 21, 2025
1 parent c8353a5 commit 9dbe165
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 36 deletions.
4 changes: 2 additions & 2 deletions cli/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl Config {
};

let content = fs::read_to_string(&location)
.with_context(|| format!("Failed to read {}", &location.to_string_lossy()))?;
.with_context(|| format!("Failed to read {}", location.to_string_lossy()))?;
let config = serde_json::from_str(&content)
.with_context(|| format!("Bad JSON config {}", &location.to_string_lossy()))?;
.with_context(|| format!("Bad JSON config {}", location.to_string_lossy()))?;
Ok(Self { location, config })
}

Expand Down
3 changes: 1 addition & 2 deletions cli/generate/src/build_tables/build_lex_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ impl<'a> LexTableBuilder<'a> {

if is_new {
info!(
"entry point state: {}, tokens: {:?}",
state_id,
"entry point state: {state_id}, tokens: {:?}",
tokens
.iter()
.map(|t| &self.lexical_grammar.variables[t.index].name)
Expand Down
2 changes: 1 addition & 1 deletion cli/generate/src/build_tables/build_parse_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ impl<'a> ParseTableBuilder<'a> {
if variable.kind == VariableType::Named {
variable.name.clone()
} else {
format!("'{}'", &variable.name)
format!("'{}'", variable.name)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions cli/generate/src/build_tables/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl fmt::Display for ParseItemDisplay<'_> {
write!(
f,
"{} →",
&self.1.variables[self.0.variable_index as usize].name
self.1.variables[self.0.variable_index as usize].name
)?;
}

Expand Down Expand Up @@ -220,14 +220,14 @@ impl fmt::Display for ParseItemDisplay<'_> {
write!(f, " ")?;
if step.symbol.is_terminal() {
if let Some(variable) = self.2.variables.get(step.symbol.index) {
write!(f, "{}", &variable.name)?;
write!(f, "{}", variable.name)?;
} else {
write!(f, "terminal-{}", step.symbol.index)?;
}
} else if step.symbol.is_external() {
write!(f, "{}", &self.1.external_tokens[step.symbol.index].name)?;
write!(f, "{}", self.1.external_tokens[step.symbol.index].name)?;
} else {
write!(f, "{}", &self.1.variables[step.symbol.index].name)?;
write!(f, "{}", self.1.variables[step.symbol.index].name)?;
}

if let Some(alias) = &step.alias {
Expand Down Expand Up @@ -295,9 +295,9 @@ impl fmt::Display for TokenSetDisplay<'_> {
write!(f, "terminal-{}", symbol.index)?;
}
} else if symbol.is_external() {
write!(f, "{}", &self.1.external_tokens[symbol.index].name)?;
write!(f, "{}", self.1.external_tokens[symbol.index].name)?;
} else {
write!(f, "{}", &self.1.variables[symbol.index].name)?;
write!(f, "{}", self.1.variables[symbol.index].name)?;
}
}
write!(f, "]")?;
Expand Down
2 changes: 1 addition & 1 deletion cli/generate/src/build_tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ fn report_state_info<'a>(
}
eprintln!(
"\nitems:\n{}",
self::item::ParseItemSetDisplay(item_set, syntax_grammar, lexical_grammar,),
item::ParseItemSetDisplay(item_set, syntax_grammar, lexical_grammar),
);
}
}
Expand Down
25 changes: 11 additions & 14 deletions cli/generate/src/nfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,48 +949,45 @@ mod tests {
assert_eq!(
left.remove_intersection(&mut right),
row.intersection,
"row {}a: {:?} && {:?}",
i,
"row {i}a: {:?} && {:?}",
row.left,
row.right
);
assert_eq!(
left, row.left_only,
"row {}a: {:?} - {:?}",
i, row.left, row.right
"row {i}a: {:?} - {:?}",
row.left, row.right
);
assert_eq!(
right, row.right_only,
"row {}a: {:?} - {:?}",
i, row.right, row.left
"row {i}a: {:?} - {:?}",
row.right, row.left
);

let mut left = row.left.clone();
let mut right = row.right.clone();
assert_eq!(
right.remove_intersection(&mut left),
row.intersection,
"row {}b: {:?} && {:?}",
i,
"row {i}b: {:?} && {:?}",
row.left,
row.right
);
assert_eq!(
left, row.left_only,
"row {}b: {:?} - {:?}",
i, row.left, row.right
"row {i}b: {:?} - {:?}",
row.left, row.right
);
assert_eq!(
right, row.right_only,
"row {}b: {:?} - {:?}",
i, row.right, row.left
"row {i}b: {:?} - {:?}",
row.right, row.left
);

assert_eq!(
row.left.clone().difference(row.right.clone()),
row.left_only,
"row {}b: {:?} -- {:?}",
i,
"row {i}b: {:?} -- {:?}",
row.left,
row.right
);
Expand Down
2 changes: 1 addition & 1 deletion cli/generate/src/prepare_grammar/extract_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl TokenExtractor {
Variable {
name: format!(
"{}_token{}",
&self.current_variable_name, self.current_variable_token_count
self.current_variable_name, self.current_variable_token_count
),
kind: VariableType::Auxiliary,
rule: rule.clone(),
Expand Down
10 changes: 5 additions & 5 deletions cli/generate/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl Generator {
self.parse_table.symbols.len()
);
add_line!(self, "#define ALIAS_COUNT {}", self.unique_aliases.len());
add_line!(self, "#define TOKEN_COUNT {}", token_count);
add_line!(self, "#define TOKEN_COUNT {token_count}");
add_line!(
self,
"#define EXTERNAL_TOKEN_COUNT {}",
Expand Down Expand Up @@ -991,7 +991,7 @@ impl Generator {
add!(
self,
"set_contains({}, {}, lookahead)",
&char_set_info.constant_name,
char_set_info.constant_name,
large_set.range_count(),
);
if check_eof {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl Generator {
indent!(self);
for (i, state) in self.parse_table.states.iter().enumerate() {
add_whitespace!(self);
add!(self, "[{}] = {{", i);
add!(self, "[{i}] = {{");
if state.is_end_of_non_terminal_extra() {
add!(self, "(TSStateId)(-1),");
} else {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ impl Generator {
if id == 0 {
continue;
}
add_line!(self, "[{}] = {{", id);
add_line!(self, "[{id}] = {{");
indent!(self);
for token in set.iter() {
add_line!(self, "{},", self.symbol_ids[&token]);
Expand Down Expand Up @@ -1250,7 +1250,7 @@ impl Generator {
indent!(self);
for i in 0..self.parse_table.external_lex_states.len() {
if !self.parse_table.external_lex_states[i].is_empty() {
add_line!(self, "[{}] = {{", i);
add_line!(self, "[{i}] = {{");
indent!(self);
for token in self.parse_table.external_lex_states[i].iter() {
add_line!(
Expand Down
2 changes: 1 addition & 1 deletion cli/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ impl Loader {
.with_context(|| {
format!(
"Failed to load language for file name {}",
&path.file_name().unwrap().to_string_lossy()
path.file_name().unwrap().to_string_lossy()
)
})?
{
Expand Down
2 changes: 1 addition & 1 deletion cli/src/test_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn test_tags_indented(
})?;
let tags_config = language_config
.tags_config(language)?
.ok_or_else(|| anyhow!("No tags config found for {:?}", test_file_path))?;
.ok_or_else(|| anyhow!("No tags config found for {test_file_path:?}"))?;
match test_tag(
tags_context,
tags_config,
Expand Down
4 changes: 2 additions & 2 deletions highlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ let highlights = highlighter.highlight(
for event in highlights {
match event.unwrap() {
HighlightEvent::Source {start, end} => {
eprintln!("source: {}-{}", start, end);
eprintln!("source: {start}-{end}");
},
HighlightEvent::HighlightStart(s) => {
eprintln!("highlight style started: {:?}", s);
eprintln!("highlight style started: {s:?}");
},
HighlightEvent::HighlightEnd => {
eprintln!("highlight style ended");
Expand Down

0 comments on commit 9dbe165

Please sign in to comment.