Skip to content

Commit fac28dd

Browse files
committed
Fix clippy warnings
1 parent 7048929 commit fac28dd

4 files changed

Lines changed: 45 additions & 45 deletions

File tree

src/doc_comments.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ fn try_strip_star_indent(doc_comment: &str) -> Option<String> {
148148
if i == 0 {
149149
// First line: strip leading stars and optional following space.
150150
let after_stars = &first_line[star_count..];
151-
let stripped = if after_stars.starts_with(' ') {
152-
&after_stars[1..]
151+
let stripped = if let Some(s) = after_stars.strip_prefix(' ') {
152+
s
153153
} else {
154154
after_stars
155155
};
@@ -160,8 +160,8 @@ fn try_strip_star_indent(doc_comment: &str) -> Option<String> {
160160
result_lines.push("");
161161
} else {
162162
let after_stars = &trimmed[star_count..];
163-
let stripped = if after_stars.starts_with(' ') {
164-
&after_stars[1..]
163+
let stripped = if let Some(s) = after_stars.strip_prefix(' ') {
164+
s
165165
} else {
166166
after_stars
167167
};

src/generated/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub mod idllistener;
4242
unused_imports,
4343
unused_mut,
4444
unused_braces,
45+
unused_parens,
4546
unused_variables,
4647
clippy::all
4748
)]

src/model/json.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use indexmap::IndexSet;
2222
use serde_json::{Map, Value};
2323

2424
use super::protocol::{Message, Protocol};
25-
use super::schema::{AvroSchema, Field, FieldOrder, LogicalType, PrimitiveType};
25+
use super::schema::{AvroSchema, Field, FieldOrder, LogicalType};
2626

2727
/// A lookup table from full type name to the actual schema definition. This
2828
/// allows `Reference` nodes to be resolved and inlined at their first use.
@@ -213,10 +213,10 @@ pub fn schema_to_json(
213213
Value::String(if *is_error { "error" } else { "record" }.to_string()),
214214
);
215215
obj.insert("name".to_string(), Value::String(name.clone()));
216-
if namespace.as_deref() != enclosing_namespace {
217-
if let Some(ns) = namespace {
218-
obj.insert("namespace".to_string(), Value::String(ns.clone()));
219-
}
216+
if namespace.as_deref() != enclosing_namespace
217+
&& let Some(ns) = namespace
218+
{
219+
obj.insert("namespace".to_string(), Value::String(ns.clone()));
220220
}
221221
if let Some(doc) = doc {
222222
obj.insert("doc".to_string(), Value::String(doc.clone()));
@@ -276,10 +276,10 @@ pub fn schema_to_json(
276276
Value::String("enum".to_string()),
277277
);
278278
obj.insert("name".to_string(), Value::String(name.clone()));
279-
if namespace.as_deref() != enclosing_namespace {
280-
if let Some(ns) = namespace {
281-
obj.insert("namespace".to_string(), Value::String(ns.clone()));
282-
}
279+
if namespace.as_deref() != enclosing_namespace
280+
&& let Some(ns) = namespace
281+
{
282+
obj.insert("namespace".to_string(), Value::String(ns.clone()));
283283
}
284284
if let Some(doc) = doc {
285285
obj.insert("doc".to_string(), Value::String(doc.clone()));
@@ -332,10 +332,10 @@ pub fn schema_to_json(
332332
Value::String("fixed".to_string()),
333333
);
334334
obj.insert("name".to_string(), Value::String(name.clone()));
335-
if namespace.as_deref() != enclosing_namespace {
336-
if let Some(ns) = namespace {
337-
obj.insert("namespace".to_string(), Value::String(ns.clone()));
338-
}
335+
if namespace.as_deref() != enclosing_namespace
336+
&& let Some(ns) = namespace
337+
{
338+
obj.insert("namespace".to_string(), Value::String(ns.clone()));
339339
}
340340
if let Some(doc) = doc {
341341
obj.insert("doc".to_string(), Value::String(doc.clone()));

src/reader.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,15 @@ fn walk_idl_file<'input>(
341341

342342
// Schema mode: optional `namespace`, optional `schema` declaration, plus
343343
// named type declarations.
344-
if let Some(ns_ctx) = ctx.namespaceDeclaration() {
345-
if let Some(id_ctx) = ns_ctx.identifier() {
346-
let id = identifier_text(&id_ctx);
347-
// In schema mode, `namespace foo.bar;` sets the enclosing namespace
348-
// directly. Unlike protocol/record identifiers (where dots in the
349-
// name imply a namespace prefix), here the entire identifier IS the
350-
// namespace value.
351-
*namespace = if id.is_empty() { None } else { Some(id) };
352-
}
344+
if let Some(ns_ctx) = ctx.namespaceDeclaration()
345+
&& let Some(id_ctx) = ns_ctx.identifier()
346+
{
347+
let id = identifier_text(&id_ctx);
348+
// In schema mode, `namespace foo.bar;` sets the enclosing namespace
349+
// directly. Unlike protocol/record identifiers (where dots in the
350+
// name imply a namespace prefix), here the entire identifier IS the
351+
// namespace value.
352+
*namespace = if id.is_empty() { None } else { Some(id) };
353353
}
354354

355355
// Collect imports (schema mode can also have them).
@@ -362,11 +362,11 @@ fn walk_idl_file<'input>(
362362
}
363363

364364
// The main schema declaration uses `schema <fullType>;`.
365-
if let Some(main_ctx) = ctx.mainSchemaDeclaration() {
366-
if let Some(ft_ctx) = main_ctx.fullType() {
367-
let schema = walk_full_type(&ft_ctx, token_stream, src, namespace)?;
368-
return Ok(IdlFile::SchemaFile(schema));
369-
}
365+
if let Some(main_ctx) = ctx.mainSchemaDeclaration()
366+
&& let Some(ft_ctx) = main_ctx.fullType()
367+
{
368+
let schema = walk_full_type(&ft_ctx, token_stream, src, namespace)?;
369+
return Ok(IdlFile::SchemaFile(schema));
370370
}
371371

372372
// If there are named schemas but no explicit `schema <type>;` declaration,
@@ -501,7 +501,7 @@ fn walk_record<'input>(
501501
let raw_identifier = identifier_text(&name_ctx);
502502

503503
// Determine if this is a record or an error type.
504-
let is_error = ctx.recordType.as_ref().map_or(false, |tok| {
504+
let is_error = ctx.recordType.as_ref().is_some_and(|tok| {
505505
tok.get_token_type() == Idl_Error
506506
});
507507

@@ -1179,27 +1179,26 @@ fn unescape_java(s: &str) -> String {
11791179
result.push_str(&hex);
11801180
}
11811181
}
1182-
Some(c2) if c2 >= '0' && c2 <= '7' => {
1182+
Some(c2) if ('0'..='7').contains(&c2) => {
11831183
// Octal escape: 1-3 octal digits. The grammar allows:
11841184
// OctDigit OctDigit? (1-2 digits, any octal)
11851185
// [0-3] OctDigit OctDigit (3 digits, first must be 0-3)
11861186
// This means a 3-digit sequence is only valid if the first
11871187
// digit is 0-3 (keeping the value <= \377 = 255).
11881188
let mut octal = String::new();
11891189
octal.push(c2);
1190-
if let Some(&next) = chars.peek() {
1191-
if next >= '0' && next <= '7' {
1192-
octal.push(next);
1190+
if let Some(&next) = chars.peek()
1191+
&& ('0'..='7').contains(&next)
1192+
{
1193+
octal.push(next);
1194+
chars.next();
1195+
// Only consume a third digit if the first was 0-3.
1196+
if c2 <= '3'
1197+
&& let Some(&next2) = chars.peek()
1198+
&& ('0'..='7').contains(&next2)
1199+
{
1200+
octal.push(next2);
11931201
chars.next();
1194-
// Only consume a third digit if the first was 0-3.
1195-
if c2 <= '3' {
1196-
if let Some(&next2) = chars.peek() {
1197-
if next2 >= '0' && next2 <= '7' {
1198-
octal.push(next2);
1199-
chars.next();
1200-
}
1201-
}
1202-
}
12031202
}
12041203
}
12051204
if let Ok(val) = u32::from_str_radix(&octal, 8) {

0 commit comments

Comments
 (0)