Skip to content

Commit 1e5be00

Browse files
committed
ttrpc: fix lint errors in build
Fix needless borrow, unncessary cast, binary comparison, and iterator lint errors in build Signed-off-by: Austin Vazquez <macedonv@amazon.com>
1 parent af10ad4 commit 1e5be00

File tree

8 files changed

+27
-29
lines changed

8 files changed

+27
-29
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
protobuf_codegen::Codegen::new()
1515
.pure()
1616
.out_dir(out_dir)
17-
.inputs(&["src/ttrpc.proto"])
17+
.inputs(["src/ttrpc.proto"])
1818
.include("src")
1919
.customize(customize)
2020
.run()

src/asynchronous/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Client {
9797
};
9898

9999
let msg = result?;
100-
let res = Response::decode(&msg.payload)
100+
let res = Response::decode(msg.payload)
101101
.map_err(err_to_others_err!(e, "Unpack response error "))?;
102102

103103
let status = res.status();

src/asynchronous/stream.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ where
103103
{
104104
pub async fn recv(&mut self) -> Result<P> {
105105
let msg_buf = self.rx.recv().await?;
106-
P::decode(&msg_buf).map_err(err_to_others_err!(e, "Decode message failed."))
106+
P::decode(msg_buf).map_err(err_to_others_err!(e, "Decode message failed."))
107107
}
108108
}
109109

@@ -184,7 +184,7 @@ where
184184
return Ok(None);
185185
}
186186
let msg_buf = res?;
187-
Q::decode(&msg_buf)
187+
Q::decode(msg_buf)
188188
.map_err(err_to_others_err!(e, "Decode message failed."))
189189
.map(Some)
190190
}
@@ -221,7 +221,7 @@ where
221221
pub async fn close_and_recv(&mut self) -> Result<P> {
222222
self.inner.close_send().await?;
223223
let msg_buf = self.inner.recv().await?;
224-
P::decode(&msg_buf).map_err(err_to_others_err!(e, "Decode message failed."))
224+
P::decode(msg_buf).map_err(err_to_others_err!(e, "Decode message failed."))
225225
}
226226
}
227227

@@ -273,7 +273,7 @@ where
273273
return Ok(None);
274274
}
275275
let msg_buf = res?;
276-
P::decode(&msg_buf)
276+
P::decode(msg_buf)
277277
.map_err(err_to_others_err!(e, "Decode message failed."))
278278
.map(Some)
279279
}
@@ -302,7 +302,7 @@ where
302302
return Ok(None);
303303
}
304304
let msg_buf = res?;
305-
Q::decode(&msg_buf)
305+
Q::decode(msg_buf)
306306
.map_err(err_to_others_err!(e, "Decode message failed."))
307307
.map(Some)
308308
}

src/proto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ mod tests {
398398
assert_eq!(&buf, &PROTOBUF_REQUEST);
399399
let dreq = Request::decode(&buf).unwrap();
400400
assert_eq!(creq, dreq);
401-
let dreq2 = Request::decode(&PROTOBUF_REQUEST).unwrap();
401+
let dreq2 = Request::decode(PROTOBUF_REQUEST).unwrap();
402402
assert_eq!(creq, dreq2);
403403
}
404404

@@ -470,7 +470,7 @@ mod tests {
470470
buf.extend_from_slice(&[0x0, 0x0]);
471471
let msg = Message::<Request>::read_from(&*buf).await.unwrap();
472472
assert_eq!(msg.header.length, 67);
473-
assert_eq!(msg.header.length, msg.payload.size() as u32);
473+
assert_eq!(msg.header.length, msg.payload.size());
474474
assert_eq!(msg.header.stream_id, 0x123456);
475475
assert_eq!(msg.header.type_, MESSAGE_TYPE_REQUEST);
476476
assert_eq!(msg.header.flags, 0xef);

src/sync/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Client {
229229

230230
let buf = result?;
231231
let res =
232-
Response::decode(&buf).map_err(err_to_others_err!(e, "Unpack response error "))?;
232+
Response::decode(buf).map_err(err_to_others_err!(e, "Unpack response error "))?;
233233

234234
let status = res.status();
235235
if status.code() != Code::OK {

ttrpc-codegen/src/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a> Resolver<'a> {
495495
for (oneof_index, oneof) in input.oneofs.iter().enumerate() {
496496
let oneof_index = oneof_index as i32;
497497
for f in &oneof.fields {
498-
fields.push(self.field(f, Some(oneof_index as i32), &nested_path_in_file)?);
498+
fields.push(self.field(f, Some(oneof_index), &nested_path_in_file)?);
499499
}
500500
}
501501

@@ -908,7 +908,7 @@ impl<'a> Resolver<'a> {
908908
if field_type != &model::FieldType::Bool {
909909
Err(())
910910
} else {
911-
Ok(protobuf::UnknownValue::Varint(if b { 1 } else { 0 }))
911+
Ok(protobuf::UnknownValue::Varint(u64::from(b)))
912912
}
913913
}
914914
// TODO: check overflow
@@ -938,7 +938,7 @@ impl<'a> Resolver<'a> {
938938
| model::FieldType::Int32
939939
| model::FieldType::Uint64
940940
| model::FieldType::Uint32 => Ok(protobuf::UnknownValue::Varint(v as u64)),
941-
model::FieldType::Sint64 => Ok(protobuf::UnknownValue::sint64(v as i64)),
941+
model::FieldType::Sint64 => Ok(protobuf::UnknownValue::sint64(v)),
942942
model::FieldType::Sint32 => Ok(protobuf::UnknownValue::sint32(v as i32)),
943943
_ => Err(()),
944944
},

ttrpc-codegen/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a> Run<'a> {
258258
let mut this_file_deps = HashMap::new();
259259
self.get_all_deps_already_parsed(&parsed, &mut this_file_deps);
260260

261-
let this_file_deps: Vec<_> = this_file_deps.into_iter().map(|(_, v)| v.parsed).collect();
261+
let this_file_deps: Vec<_> = this_file_deps.into_values().map(|v| v.parsed).collect();
262262

263263
let descriptor =
264264
convert::file_descriptor(protobuf_path.to_owned(), &parsed, &this_file_deps).map_err(
@@ -346,8 +346,8 @@ pub fn parse_and_typecheck(
346346

347347
let file_descriptors: Vec<_> = run
348348
.parsed_files
349-
.into_iter()
350-
.map(|(_, v)| v.descriptor)
349+
.into_values()
350+
.map(|v| v.descriptor)
351351
.collect();
352352

353353
Ok(ParsedAndTypechecked {

ttrpc-codegen/src/parser.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,11 @@ impl<'a> Lexer<'a> {
347347
}
348348

349349
fn next_char_if_eq(&mut self, expect: char) -> bool {
350-
self.next_char_if(|c| c == expect) != None
350+
self.next_char_if(|c| c == expect).is_some()
351351
}
352352

353353
fn next_char_if_in(&mut self, alphabet: &str) -> Option<char> {
354-
for c in alphabet.chars() {
355-
if self.next_char_if_eq(c) {
356-
return Some(c);
357-
}
358-
}
359-
None
354+
alphabet.chars().find(|&c| self.next_char_if_eq(c))
360355
}
361356

362357
fn next_char_expect_eq(&mut self, expect: char) -> ParserResult<()> {
@@ -430,7 +425,7 @@ impl<'a> Lexer<'a> {
430425
Ok(
431426
if self.skip_if_lookahead_is_str("0x") || self.skip_if_lookahead_is_str("0X") {
432427
let s = self.take_while(Lexer::is_ascii_hexdigit);
433-
Some(u64::from_str_radix(s, 16)? as u64)
428+
Some(u64::from_str_radix(s, 16)?)
434429
} else {
435430
None
436431
},
@@ -449,7 +444,7 @@ impl<'a> Lexer<'a> {
449444

450445
let pos = clone.pos;
451446

452-
Ok(if clone.next_char_if(Lexer::is_ascii_digit) != None {
447+
Ok(if clone.next_char_if(Lexer::is_ascii_digit).is_some() {
453448
clone.take_while(Lexer::is_ascii_digit);
454449
let value = clone.input[pos..clone.pos].parse()?;
455450
*self = clone;
@@ -517,7 +512,7 @@ impl<'a> Lexer<'a> {
517512

518513
// exponent = ( "e" | "E" ) [ "+" | "-" ] decimals
519514
fn next_exponent_opt(&mut self) -> ParserResult<Option<()>> {
520-
if self.next_char_if_in("eE") != None {
515+
if self.next_char_if_in("eE").is_some() {
521516
self.next_char_if_in("+-");
522517
self.next_decimal_digits()?;
523518
Ok(Some(()))
@@ -537,7 +532,7 @@ impl<'a> Lexer<'a> {
537532
if self.next_char_if_eq('.') {
538533
self.next_decimal_digits()?;
539534
self.next_exponent_opt()?;
540-
} else if self.next_exponent_opt()? == None {
535+
} else if (self.next_exponent_opt()?).is_none() {
541536
return Err(ParserError::IncorrectFloatLit);
542537
}
543538
}
@@ -931,7 +926,7 @@ impl<'a> Parser<'a> {
931926
}
932927

933928
fn next_ident_if_eq(&mut self, word: &str) -> ParserResult<bool> {
934-
Ok(self.next_ident_if_in(&[word])? != None)
929+
Ok((self.next_ident_if_in(&[word])?).is_some())
935930
}
936931

937932
pub fn next_ident_expect_eq(&mut self, word: &str) -> ParserResult<()> {
@@ -950,7 +945,10 @@ impl<'a> Parser<'a> {
950945
}
951946

952947
fn next_symbol_if_eq(&mut self, symbol: char) -> ParserResult<bool> {
953-
Ok(self.next_token_if(|token| matches!(*token, Token::Symbol(c) if c == symbol))? != None)
948+
Ok(
949+
(self.next_token_if(|token| matches!(*token, Token::Symbol(c) if c == symbol))?)
950+
.is_some(),
951+
)
954952
}
955953

956954
fn next_symbol_expect_eq(&mut self, symbol: char) -> ParserResult<()> {

0 commit comments

Comments
 (0)