Skip to content

Commit 6447e03

Browse files
authored
Appease most of the Clippy lints (#673)
Part of #155 These should all be more or less obvious, maybe with the exception of: - ~`comparison_chain` - in this case it might be more noise than it's worth, I'm fine with silencing it here, instead~ EDIT: Actually, let's drop it for now - `single_char_pattern` - in our case we do less `"`-escaping, so that's good enough for me (but I know it might be considered controversial) - `clippy::upper_case_acronyms` - this helps follow the Rust naming convention (`CLI` -> `Cli`, which I'm strongly in favour; it's not a SCREAMING_CASE_CONSTANT) Some select lints are explicitly allowed on a case-by-case basis here but in general are worthwhile to be linted against, e.g. `enum_variant_names` or `manual_range_contains`. The only ones left now are: - `comparison_chain` - in this case it might be more noise than it's worth, I'm fine with silencing it here, instead - `needless_return`, which we will have *many* instances of and I'd like to have a separate PR for that (but I'm *strongly* in favour, as I find it to be one of the signature aspects of Rust) - `should_implement_trait` - needs to be silenced in one case for `#[napi] fn clone`, but `ParserContext::next` might or might not implement the `Iterator`, I'm not sure yet, so I'd like to defer it for now.
1 parent 0434b68 commit 6447e03

File tree

85 files changed

+328
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+328
-405
lines changed

.cargo/config.toml

-65
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,9 @@ rustflags = [
1212
# This is a list of allowed Clippy rules for the purposes of gradual migration.
1313
# See https://github.com/NomicFoundation/slang/pull/626
1414
"-A",
15-
"clippy::bool_assert_comparison",
16-
"-A",
17-
"clippy::cmp_owned",
18-
"-A",
19-
"clippy::collapsible_if",
20-
"-A",
2115
"clippy::comparison_chain",
2216
"-A",
23-
"clippy::enum_variant_names",
24-
"-A",
25-
"clippy::expect_fun_call",
26-
"-A",
27-
"clippy::explicit_auto_deref",
28-
"-A",
29-
"clippy::from_over_into",
30-
"-A",
31-
"clippy::inherent_to_string",
32-
"-A",
33-
"clippy::into_iter_on_ref",
34-
"-A",
35-
"clippy::len_without_is_empty",
36-
"-A",
37-
"clippy::len_zero",
38-
"-A",
39-
"clippy::manual_range_contains",
40-
"-A",
41-
"clippy::match_like_matches_macro",
42-
"-A",
43-
"clippy::needless_borrow",
44-
"-A",
45-
"clippy::needless_range_loop",
46-
"-A",
4717
"clippy::needless_return",
4818
"-A",
49-
"clippy::new_without_default",
50-
"-A",
51-
"clippy::println_empty_string",
52-
"-A",
53-
"clippy::ptr_arg",
54-
"-A",
55-
"clippy::redundant_closure",
56-
"-A",
57-
"clippy::redundant_pattern",
58-
"-A",
59-
"clippy::redundant_pattern_matching",
60-
"-A",
61-
"clippy::redundant_static_lifetimes",
62-
"-A",
6319
"clippy::should_implement_trait",
64-
"-A",
65-
"clippy::single_char_add_str",
66-
"-A",
67-
"clippy::single_char_pattern",
68-
"-A",
69-
"clippy::to_string_in_format_args",
70-
"-A",
71-
"clippy::upper_case_acronyms",
72-
"-A",
73-
"clippy::useless_asref",
74-
"-A",
75-
"clippy::useless_conversion",
76-
"-A",
77-
"clippy::useless_format",
78-
"-A",
79-
"clippy::write_literal",
80-
"-A",
81-
"clippy::writeln_empty_string",
82-
"-A",
83-
"clippy::wrong_self_convention",
84-
8520
]

crates/codegen/ebnf/src/parser.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ impl EbnfNode {
1616
} => {
1717
return Self::sequence(vec![
1818
Self::production_ref(&open.reference),
19-
Self::from_parser(&parser),
19+
Self::from_parser(parser),
2020
Self::production_ref(&close.reference),
2121
]);
2222
}
2323

2424
ParserDefinition::OneOrMore(parser) => {
25-
return Self::one_or_more(Self::from_parser(&parser));
25+
return Self::one_or_more(Self::from_parser(parser));
2626
}
2727

2828
ParserDefinition::Optional(parser) => {
29-
return Self::optional(Self::from_parser(&parser));
29+
return Self::optional(Self::from_parser(parser));
3030
}
3131

3232
ParserDefinition::Reference(name) => {
33-
return Self::production_ref(&name);
33+
return Self::production_ref(name);
3434
}
3535

3636
ParserDefinition::SeparatedBy { parser, separator } => {
3737
return Self::sequence(vec![
38-
Self::from_parser(&parser),
38+
Self::from_parser(parser),
3939
Self::zero_or_more(Self::sequence(vec![
4040
Self::production_ref(&separator.reference),
41-
Self::from_parser(&parser),
41+
Self::from_parser(parser),
4242
])),
4343
]);
4444
}
@@ -49,13 +49,13 @@ impl EbnfNode {
4949

5050
ParserDefinition::TerminatedBy { parser, terminator } => {
5151
return Self::sequence(vec![
52-
Self::from_parser(&parser),
52+
Self::from_parser(parser),
5353
Self::production_ref(&terminator.reference),
5454
]);
5555
}
5656

5757
ParserDefinition::ZeroOrMore(parser) => {
58-
return Self::zero_or_more(Self::from_parser(&parser));
58+
return Self::zero_or_more(Self::from_parser(parser));
5959
}
6060
};
6161
}

crates/codegen/ebnf/src/serialization.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ impl EbnfSerializer {
7070
buffer.push_str(&self.display_name(name));
7171
buffer.push_str(" = ");
7272
buffer.push_str(&self.serialize_root_node(name, root_node));
73-
buffer.push_str(";");
73+
buffer.push(';');
7474

7575
match self.outputs.get_mut(name) {
7676
Some(existing) => {
7777
if !existing.is_empty() {
78-
existing.push_str("\n");
78+
existing.push('\n');
7979
}
8080

8181
existing.push_str(&buffer);
@@ -127,7 +127,7 @@ impl EbnfSerializer {
127127
pub fn serialize_node(&mut self, top_node: &EbnfNode, buffer: &mut String) {
128128
match top_node {
129129
EbnfNode::Choice { nodes } => {
130-
for (i, node) in nodes.into_iter().enumerate() {
130+
for (i, node) in nodes.iter().enumerate() {
131131
if i > 0 {
132132
buffer.push_str(" | ");
133133
}
@@ -144,29 +144,29 @@ impl EbnfSerializer {
144144
self.serialize_child_node(top_node, subtrahend, buffer);
145145
}
146146
EbnfNode::Not { node } => {
147-
buffer.push_str("!");
147+
buffer.push('!');
148148
self.serialize_child_node(top_node, node, buffer);
149149
}
150150
EbnfNode::OneOrMore { node } => {
151151
self.serialize_child_node(top_node, node, buffer);
152-
buffer.push_str("+");
152+
buffer.push('+');
153153
}
154154
EbnfNode::Optional { node } => {
155155
self.serialize_child_node(top_node, node, buffer);
156-
buffer.push_str("?");
156+
buffer.push('?');
157157
}
158158
EbnfNode::Range { from, to } => {
159159
buffer.push_str(&format_string_literal(&from.to_string()));
160-
buffer.push_str("…");
160+
buffer.push('…');
161161
buffer.push_str(&format_string_literal(&to.to_string()));
162162
}
163163
EbnfNode::ProductionRef { name } => {
164164
buffer.push_str(&self.display_name(name));
165165
}
166166
EbnfNode::Sequence { nodes } => {
167-
for (i, node) in nodes.into_iter().enumerate() {
167+
for (i, node) in nodes.iter().enumerate() {
168168
if i > 0 {
169-
buffer.push_str(" ");
169+
buffer.push(' ');
170170
}
171171

172172
self.serialize_child_node(top_node, node, buffer);
@@ -178,22 +178,22 @@ impl EbnfSerializer {
178178
EbnfNode::WithComment { node, comment } => {
179179
self.serialize_child_node(top_node, node, buffer);
180180
buffer.push_str(" (* ");
181-
buffer.push_str(&comment);
181+
buffer.push_str(comment);
182182
buffer.push_str(" *)");
183183
}
184184
EbnfNode::ZeroOrMore { node } => {
185185
self.serialize_child_node(top_node, node, buffer);
186-
buffer.push_str("*");
186+
buffer.push('*');
187187
}
188188
};
189189
}
190190

191191
fn serialize_child_node(&mut self, parent: &EbnfNode, child: &EbnfNode, buffer: &mut String) {
192192
if discriminant(parent) != discriminant(child) && child.precedence() <= parent.precedence()
193193
{
194-
buffer.push_str("(");
194+
buffer.push('(');
195195
self.serialize_node(child, buffer);
196-
buffer.push_str(")");
196+
buffer.push(')');
197197
} else {
198198
self.serialize_node(child, buffer);
199199
}
@@ -224,7 +224,7 @@ impl EbnfSerializer {
224224
}
225225

226226
fn format_string_literal(value: &str) -> String {
227-
let delimiter = if value.contains('"') && !value.contains("'") {
227+
let delimiter = if value.contains('"') && !value.contains('\'') {
228228
'\''
229229
} else {
230230
'"'
@@ -241,7 +241,7 @@ fn format_string_literal(value: &str) -> String {
241241
_ => {
242242
panic!(
243243
"Unexpected character in string literal: '{c}'",
244-
c = c.escape_unicode().to_string()
244+
c = c.escape_unicode()
245245
);
246246
}
247247
})

crates/codegen/grammar/src/grammar.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ impl GrammarElement {
5050
}
5151
}
5252

53-
impl Into<GrammarElement> for ScannerDefinitionRef {
54-
fn into(self) -> GrammarElement {
55-
GrammarElement::ScannerDefinition(self)
53+
impl From<ScannerDefinitionRef> for GrammarElement {
54+
fn from(def: ScannerDefinitionRef) -> Self {
55+
GrammarElement::ScannerDefinition(def)
5656
}
5757
}
5858

59-
impl Into<GrammarElement> for TriviaParserDefinitionRef {
60-
fn into(self) -> GrammarElement {
61-
GrammarElement::TriviaParserDefinition(self)
59+
impl From<TriviaParserDefinitionRef> for GrammarElement {
60+
fn from(def: TriviaParserDefinitionRef) -> Self {
61+
GrammarElement::TriviaParserDefinition(def)
6262
}
6363
}
6464

65-
impl Into<GrammarElement> for ParserDefinitionRef {
66-
fn into(self) -> GrammarElement {
67-
GrammarElement::ParserDefinition(self)
65+
impl From<ParserDefinitionRef> for GrammarElement {
66+
fn from(def: ParserDefinitionRef) -> Self {
67+
GrammarElement::ParserDefinition(def)
6868
}
6969
}
7070

71-
impl Into<GrammarElement> for PrecedenceParserDefinitionRef {
72-
fn into(self) -> GrammarElement {
73-
GrammarElement::PrecedenceParserDefinition(self)
71+
impl From<PrecedenceParserDefinitionRef> for GrammarElement {
72+
fn from(def: PrecedenceParserDefinitionRef) -> Self {
73+
GrammarElement::PrecedenceParserDefinition(def)
7474
}
7575
}
7676

crates/codegen/grammar/src/parser_definition.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ pub enum ParserDefinitionNode {
5151
TerminatedBy(Box<Self>, Box<Self>),
5252
}
5353

54-
impl Into<ParserDefinitionNode> for ScannerDefinitionRef {
55-
fn into(self) -> ParserDefinitionNode {
56-
ParserDefinitionNode::ScannerDefinition(self)
54+
impl From<ScannerDefinitionRef> for ParserDefinitionNode {
55+
fn from(def: ScannerDefinitionRef) -> Self {
56+
ParserDefinitionNode::ScannerDefinition(def)
5757
}
5858
}
5959

60-
impl Into<ParserDefinitionNode> for TriviaParserDefinitionRef {
61-
fn into(self) -> ParserDefinitionNode {
62-
ParserDefinitionNode::TriviaParserDefinition(self)
60+
impl From<TriviaParserDefinitionRef> for ParserDefinitionNode {
61+
fn from(def: TriviaParserDefinitionRef) -> Self {
62+
ParserDefinitionNode::TriviaParserDefinition(def)
6363
}
6464
}
6565

66-
impl Into<ParserDefinitionNode> for ParserDefinitionRef {
67-
fn into(self) -> ParserDefinitionNode {
68-
ParserDefinitionNode::ParserDefinition(self)
66+
impl From<ParserDefinitionRef> for ParserDefinitionNode {
67+
fn from(def: ParserDefinitionRef) -> Self {
68+
ParserDefinitionNode::ParserDefinition(def)
6969
}
7070
}
7171

72-
impl Into<ParserDefinitionNode> for PrecedenceParserDefinitionRef {
73-
fn into(self) -> ParserDefinitionNode {
74-
ParserDefinitionNode::PrecedenceParserDefinition(self)
72+
impl From<PrecedenceParserDefinitionRef> for ParserDefinitionNode {
73+
fn from(def: PrecedenceParserDefinitionRef) -> Self {
74+
ParserDefinitionNode::PrecedenceParserDefinition(def)
7575
}
7676
}
7777

crates/codegen/grammar/src/scanner_definition.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ pub enum ScannerDefinitionNode {
3232
ScannerDefinition(ScannerDefinitionRef),
3333
}
3434

35-
impl Into<ScannerDefinitionNode> for ScannerDefinitionRef {
36-
fn into(self) -> ScannerDefinitionNode {
37-
ScannerDefinitionNode::ScannerDefinition(self)
35+
impl From<ScannerDefinitionRef> for ScannerDefinitionNode {
36+
fn from(def_ref: ScannerDefinitionRef) -> Self {
37+
ScannerDefinitionNode::ScannerDefinition(def_ref)
3838
}
3939
}
4040

crates/codegen/language/definition/src/compiler/analysis/definitions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ fn calculate_defined_in(analysis: &mut Analysis, item: &Item) -> VersionSet {
161161
return defined_in;
162162
}
163163

164+
#[allow(clippy::enum_variant_names)]
164165
#[derive(thiserror::Error, Debug)]
165166
enum Errors<'err> {
166167
#[error("An item with the name '{0}' already exists.")]

crates/codegen/language/definition/src/compiler/analysis/reachability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn check_unreachabable_items(analysis: &mut Analysis) {
4848
if !metadata.defined_in.is_empty() && !visited.contains(&*metadata.name) {
4949
analysis
5050
.errors
51-
.add(&metadata.name, &Errors::Unreachable(&*metadata.name));
51+
.add(&metadata.name, &Errors::Unreachable(&metadata.name));
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)