Skip to content

Commit 07d20b1

Browse files
authored
Fix all clippy warnings (#652)
1 parent c1ce37e commit 07d20b1

39 files changed

+283
-300
lines changed

examples/akamai.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
5050
{
5151
let (_, session) = tls.get_ref();
5252
let negotiated_protocol = session.alpn_protocol();
53-
assert_eq!(
54-
Some(ALPN_H2.as_bytes()),
55-
negotiated_protocol.as_ref().map(|x| &**x)
56-
);
53+
assert_eq!(Some(ALPN_H2.as_bytes()), negotiated_protocol);
5754
}
5855

5956
println!("Starting client handshake");

src/codec/framed_read.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn decode_frame(
109109

110110
if partial_inout.is_some() && head.kind() != Kind::Continuation {
111111
proto_err!(conn: "expected CONTINUATION, got {:?}", head.kind());
112-
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR).into());
112+
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
113113
}
114114

115115
let kind = head.kind();
@@ -231,7 +231,7 @@ fn decode_frame(
231231
if head.stream_id() == 0 {
232232
// Invalid stream identifier
233233
proto_err!(conn: "invalid stream ID 0");
234-
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR).into());
234+
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
235235
}
236236

237237
match frame::Priority::load(head, &bytes[frame::HEADER_LEN..]) {
@@ -257,14 +257,14 @@ fn decode_frame(
257257
Some(partial) => partial,
258258
None => {
259259
proto_err!(conn: "received unexpected CONTINUATION frame");
260-
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR).into());
260+
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
261261
}
262262
};
263263

264264
// The stream identifiers must match
265265
if partial.frame.stream_id() != head.stream_id() {
266266
proto_err!(conn: "CONTINUATION frame stream ID does not match previous frame stream ID");
267-
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR).into());
267+
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
268268
}
269269

270270
// Extend the buf
@@ -287,7 +287,7 @@ fn decode_frame(
287287
// the attacker to go away.
288288
if partial.buf.len() + bytes.len() > max_header_list_size {
289289
proto_err!(conn: "CONTINUATION frame header block size over ignorable limit");
290-
return Err(Error::library_go_away(Reason::COMPRESSION_ERROR).into());
290+
return Err(Error::library_go_away(Reason::COMPRESSION_ERROR));
291291
}
292292
}
293293
partial.buf.extend_from_slice(&bytes[frame::HEADER_LEN..]);

src/frame/data.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Data<T = Bytes> {
1616
pad_len: Option<u8>,
1717
}
1818

19-
#[derive(Copy, Clone, Eq, PartialEq)]
19+
#[derive(Copy, Clone, Default, Eq, PartialEq)]
2020
struct DataFlags(u8);
2121

2222
const END_STREAM: u8 = 0x1;
@@ -211,12 +211,6 @@ impl DataFlags {
211211
}
212212
}
213213

214-
impl Default for DataFlags {
215-
fn default() -> Self {
216-
DataFlags(0)
217-
}
218-
}
219-
220214
impl From<DataFlags> for u8 {
221215
fn from(src: DataFlags) -> u8 {
222216
src.0

src/frame/headers.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,20 @@ impl fmt::Debug for Headers {
309309

310310
// ===== util =====
311311

312-
pub fn parse_u64(src: &[u8]) -> Result<u64, ()> {
312+
#[derive(Debug, PartialEq, Eq)]
313+
pub struct ParseU64Error;
314+
315+
pub fn parse_u64(src: &[u8]) -> Result<u64, ParseU64Error> {
313316
if src.len() > 19 {
314317
// At danger for overflow...
315-
return Err(());
318+
return Err(ParseU64Error);
316319
}
317320

318321
let mut ret = 0;
319322

320323
for &d in src {
321324
if d < b'0' || d > b'9' {
322-
return Err(());
325+
return Err(ParseU64Error);
323326
}
324327

325328
ret *= 10;
@@ -333,7 +336,7 @@ pub fn parse_u64(src: &[u8]) -> Result<u64, ()> {
333336

334337
#[derive(Debug)]
335338
pub enum PushPromiseHeaderError {
336-
InvalidContentLength(Result<u64, ()>),
339+
InvalidContentLength(Result<u64, ParseU64Error>),
337340
NotSafeAndCacheable,
338341
}
339342

@@ -381,7 +384,7 @@ impl PushPromise {
381384
fn safe_and_cacheable(method: &Method) -> bool {
382385
// Cacheable: https://httpwg.org/specs/rfc7231.html#cacheable.methods
383386
// Safe: https://httpwg.org/specs/rfc7231.html#safe.methods
384-
return method == Method::GET || method == Method::HEAD;
387+
method == Method::GET || method == Method::HEAD
385388
}
386389

387390
pub fn fields(&self) -> &HeaderMap {

src/frame/settings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ impl Settings {
182182
}
183183
}
184184
Some(MaxFrameSize(val)) => {
185-
if val < DEFAULT_MAX_FRAME_SIZE || val > MAX_MAX_FRAME_SIZE {
186-
return Err(Error::InvalidSettingValue);
187-
} else {
185+
if DEFAULT_MAX_FRAME_SIZE <= val && val <= MAX_MAX_FRAME_SIZE {
188186
settings.max_frame_size = Some(val);
187+
} else {
188+
return Err(Error::InvalidSettingValue);
189189
}
190190
}
191191
Some(MaxHeaderListSize(val)) => {

src/hpack/decoder.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -852,26 +852,24 @@ mod test {
852852
fn test_decode_empty() {
853853
let mut de = Decoder::new(0);
854854
let mut buf = BytesMut::new();
855-
let empty = de.decode(&mut Cursor::new(&mut buf), |_| {}).unwrap();
856-
assert_eq!(empty, ());
855+
let _: () = de.decode(&mut Cursor::new(&mut buf), |_| {}).unwrap();
857856
}
858857

859858
#[test]
860859
fn test_decode_indexed_larger_than_table() {
861860
let mut de = Decoder::new(0);
862861

863862
let mut buf = BytesMut::new();
864-
buf.extend(&[0b01000000, 0x80 | 2]);
863+
buf.extend([0b01000000, 0x80 | 2]);
865864
buf.extend(huff_encode(b"foo"));
866-
buf.extend(&[0x80 | 3]);
865+
buf.extend([0x80 | 3]);
867866
buf.extend(huff_encode(b"bar"));
868867

869868
let mut res = vec![];
870-
let _ = de
871-
.decode(&mut Cursor::new(&mut buf), |h| {
872-
res.push(h);
873-
})
874-
.unwrap();
869+
de.decode(&mut Cursor::new(&mut buf), |h| {
870+
res.push(h);
871+
})
872+
.unwrap();
875873

876874
assert_eq!(res.len(), 1);
877875
assert_eq!(de.table.size(), 0);
@@ -900,10 +898,10 @@ mod test {
900898
let value = huff_encode(b"bar");
901899
let mut buf = BytesMut::new();
902900
// header name is non_huff encoded
903-
buf.extend(&[0b01000000, 0x00 | 3]);
901+
buf.extend([0b01000000, 3]);
904902
buf.extend(b"foo");
905903
// header value is partial
906-
buf.extend(&[0x80 | 3]);
904+
buf.extend([0x80 | 3]);
907905
buf.extend(&value[0..1]);
908906

909907
let mut res = vec![];
@@ -917,11 +915,10 @@ mod test {
917915

918916
// extend buf with the remaining header value
919917
buf.extend(&value[1..]);
920-
let _ = de
921-
.decode(&mut Cursor::new(&mut buf), |h| {
922-
res.push(h);
923-
})
924-
.unwrap();
918+
de.decode(&mut Cursor::new(&mut buf), |h| {
919+
res.push(h);
920+
})
921+
.unwrap();
925922

926923
assert_eq!(res.len(), 1);
927924
assert_eq!(de.table.size(), 0);

src/hpack/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ impl Encoder {
118118
encode_int(idx, 7, 0x80, dst);
119119
}
120120
Index::Name(idx, _) => {
121-
let header = self.table.resolve(&index);
121+
let header = self.table.resolve(index);
122122

123123
encode_not_indexed(idx, header.value_slice(), header.is_sensitive(), dst);
124124
}
125125
Index::Inserted(_) => {
126-
let header = self.table.resolve(&index);
126+
let header = self.table.resolve(index);
127127

128128
assert!(!header.is_sensitive());
129129

@@ -133,15 +133,15 @@ impl Encoder {
133133
encode_str(header.value_slice(), dst);
134134
}
135135
Index::InsertedValue(idx, _) => {
136-
let header = self.table.resolve(&index);
136+
let header = self.table.resolve(index);
137137

138138
assert!(!header.is_sensitive());
139139

140140
encode_int(idx, 6, 0b0100_0000, dst);
141141
encode_str(header.value_slice(), dst);
142142
}
143143
Index::NotIndexed(_) => {
144-
let header = self.table.resolve(&index);
144+
let header = self.table.resolve(index);
145145

146146
encode_not_indexed2(
147147
header.name().as_slice(),

src/hpack/header.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,18 @@ impl Header {
190190
use http::header;
191191

192192
match *self {
193-
Header::Field { ref name, .. } => match *name {
193+
Header::Field { ref name, .. } => matches!(
194+
*name,
194195
header::AGE
195-
| header::AUTHORIZATION
196-
| header::CONTENT_LENGTH
197-
| header::ETAG
198-
| header::IF_MODIFIED_SINCE
199-
| header::IF_NONE_MATCH
200-
| header::LOCATION
201-
| header::COOKIE
202-
| header::SET_COOKIE => true,
203-
_ => false,
204-
},
196+
| header::AUTHORIZATION
197+
| header::CONTENT_LENGTH
198+
| header::ETAG
199+
| header::IF_MODIFIED_SINCE
200+
| header::IF_NONE_MATCH
201+
| header::LOCATION
202+
| header::COOKIE
203+
| header::SET_COOKIE
204+
),
205205
Header::Path(..) => true,
206206
_ => false,
207207
}
@@ -231,10 +231,10 @@ impl<'a> Name<'a> {
231231
match self {
232232
Name::Field(name) => Ok(Header::Field {
233233
name: name.clone(),
234-
value: HeaderValue::from_bytes(&*value)?,
234+
value: HeaderValue::from_bytes(&value)?,
235235
}),
236236
Name::Authority => Ok(Header::Authority(BytesStr::try_from(value)?)),
237-
Name::Method => Ok(Header::Method(Method::from_bytes(&*value)?)),
237+
Name::Method => Ok(Header::Method(Method::from_bytes(&value)?)),
238238
Name::Scheme => Ok(Header::Scheme(BytesStr::try_from(value)?)),
239239
Name::Path => Ok(Header::Path(BytesStr::try_from(value)?)),
240240
Name::Protocol => Ok(Header::Protocol(Protocol::try_from(value)?)),

src/hpack/huffman/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod test {
112112
#[test]
113113
fn decode_single_byte() {
114114
assert_eq!("o", decode(&[0b00111111]).unwrap());
115-
assert_eq!("0", decode(&[0x0 + 7]).unwrap());
115+
assert_eq!("0", decode(&[7]).unwrap());
116116
assert_eq!("A", decode(&[(0x21 << 2) + 3]).unwrap());
117117
}
118118

@@ -138,7 +138,7 @@ mod test {
138138

139139
dst.clear();
140140
encode(b"0", &mut dst);
141-
assert_eq!(&dst[..], &[0x0 + 7]);
141+
assert_eq!(&dst[..], &[7]);
142142

143143
dst.clear();
144144
encode(b"A", &mut dst);
@@ -147,7 +147,7 @@ mod test {
147147

148148
#[test]
149149
fn encode_decode_str() {
150-
const DATA: &'static [&'static str] = &[
150+
const DATA: &[&str] = &[
151151
"hello world",
152152
":method",
153153
":scheme",
@@ -184,8 +184,7 @@ mod test {
184184

185185
#[test]
186186
fn encode_decode_u8() {
187-
const DATA: &'static [&'static [u8]] =
188-
&[b"\0", b"\0\0\0", b"\0\x01\x02\x03\x04\x05", b"\xFF\xF8"];
187+
const DATA: &[&[u8]] = &[b"\0", b"\0\0\0", b"\0\x01\x02\x03\x04\x05", b"\xFF\xF8"];
189188

190189
for s in DATA {
191190
let mut dst = BytesMut::with_capacity(s.len());

src/hpack/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl Table {
404404

405405
// Find the associated position
406406
probe_loop!(probe < self.indices.len(), {
407-
debug_assert!(!self.indices[probe].is_none());
407+
debug_assert!(self.indices[probe].is_some());
408408

409409
let mut pos = self.indices[probe].unwrap();
410410

src/hpack/test/fixture.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn test_story(story: Value) {
5252

5353
Case {
5454
seqno: case.get("seqno").unwrap().as_u64().unwrap(),
55-
wire: wire,
56-
expect: expect,
55+
wire,
56+
expect,
5757
header_table_size: size,
5858
}
5959
})
@@ -142,10 +142,10 @@ fn key_str(e: &Header) -> &str {
142142
fn value_str(e: &Header) -> &str {
143143
match *e {
144144
Header::Field { ref value, .. } => value.to_str().unwrap(),
145-
Header::Authority(ref v) => &**v,
145+
Header::Authority(ref v) => v,
146146
Header::Method(ref m) => m.as_str(),
147-
Header::Scheme(ref v) => &**v,
148-
Header::Path(ref v) => &**v,
147+
Header::Scheme(ref v) => v,
148+
Header::Path(ref v) => v,
149149
Header::Protocol(ref v) => v.as_str(),
150150
Header::Status(ref v) => v.as_str(),
151151
}

src/hpack/test/fuzz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl FuzzHpack {
8080
let high = rng.gen_range(128..MAX_CHUNK * 2);
8181
let low = rng.gen_range(0..high);
8282

83-
frame.resizes.extend(&[low, high]);
83+
frame.resizes.extend([low, high]);
8484
}
8585
1..=3 => {
8686
frame.resizes.push(rng.gen_range(128..MAX_CHUNK * 2));

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#![doc(html_root_url = "https://docs.rs/h2/0.3.15")]
8282
#![deny(missing_debug_implementations, missing_docs)]
8383
#![cfg_attr(test, deny(warnings))]
84+
#![allow(clippy::type_complexity, clippy::manual_range_contains)]
8485

8586
macro_rules! proto_err {
8687
(conn: $($msg:tt)+) => {

src/proto/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215
});
216216

217217
match (ours, theirs) {
218-
(Reason::NO_ERROR, Reason::NO_ERROR) => return Ok(()),
218+
(Reason::NO_ERROR, Reason::NO_ERROR) => Ok(()),
219219
(ours, Reason::NO_ERROR) => Err(Error::GoAway(Bytes::new(), ours, initiator)),
220220
// If both sides reported an error, give their
221221
// error back to th user. We assume our error

src/proto/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub enum Error {
1313
Io(io::ErrorKind, Option<String>),
1414
}
1515

16-
#[derive(Clone, Copy, Debug, PartialEq)]
16+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1717
pub enum Initiator {
1818
User,
1919
Library,
@@ -70,7 +70,7 @@ impl fmt::Display for Error {
7070

7171
impl From<io::ErrorKind> for Error {
7272
fn from(src: io::ErrorKind) -> Self {
73-
Error::Io(src.into(), None)
73+
Error::Io(src, None)
7474
}
7575
}
7676

src/proto/ping_pong.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ impl PingPong {
200200

201201
impl ReceivedPing {
202202
pub(crate) fn is_shutdown(&self) -> bool {
203-
match *self {
204-
ReceivedPing::Shutdown => true,
205-
_ => false,
206-
}
203+
matches!(*self, Self::Shutdown)
207204
}
208205
}
209206

0 commit comments

Comments
 (0)