Skip to content

Commit 23c6257

Browse files
author
Michael Rodler
committed
run clippy --fix
1 parent d25a30b commit 23c6257

13 files changed

+87
-91
lines changed

src/byte_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl ByteStr {
4343
}
4444
}
4545
// Invariant: assumed by the safety requirements of this function.
46-
ByteStr { bytes: bytes }
46+
ByteStr { bytes }
4747
}
4848
}
4949

src/header/map.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<T> HeaderMap<T> {
642642
assert!(cap <= MAX_SIZE, "header map reserve over max capacity");
643643
assert!(cap != 0, "header map reserve overflowed");
644644

645-
if self.entries.len() == 0 {
645+
if self.entries.is_empty() {
646646
self.mask = cap as Size - 1;
647647
self.indices = vec![Pos::none(); cap].into_boxed_slice();
648648
self.entries = Vec::with_capacity(usable_capacity(cap));
@@ -1082,22 +1082,22 @@ impl<T> HeaderMap<T> {
10821082
danger,
10831083
Entry::Vacant(VacantEntry {
10841084
map: self,
1085-
hash: hash,
1085+
hash,
10861086
key: key.into(),
1087-
probe: probe,
1088-
danger: danger,
1087+
probe,
1088+
danger,
10891089
}),
10901090
Entry::Occupied(OccupiedEntry {
10911091
map: self,
10921092
index: pos,
1093-
probe: probe,
1093+
probe,
10941094
}),
10951095
Entry::Vacant(VacantEntry {
10961096
map: self,
1097-
hash: hash,
1097+
hash,
10981098
key: key.into(),
1099-
probe: probe,
1100-
danger: danger,
1099+
probe,
1100+
danger,
11011101
})
11021102
)
11031103
}
@@ -1201,7 +1201,7 @@ impl<T> HeaderMap<T> {
12011201

12021202
ValueDrain {
12031203
first: Some(old),
1204-
next: next,
1204+
next,
12051205
lt: PhantomData,
12061206
}
12071207
}
@@ -1407,7 +1407,7 @@ impl<T> HeaderMap<T> {
14071407

14081408
// backward shift deletion in self.indices
14091409
// after probe, shift all non-ideally placed indices backward
1410-
if self.entries.len() > 0 {
1410+
if !self.entries.is_empty() {
14111411
let mut last_probe = probe;
14121412
let mut probe = probe + 1;
14131413

@@ -1454,9 +1454,9 @@ impl<T> HeaderMap<T> {
14541454
assert!(self.entries.len() < MAX_SIZE, "header map at capacity");
14551455

14561456
self.entries.push(Bucket {
1457-
hash: hash,
1458-
key: key,
1459-
value: value,
1457+
hash,
1458+
key,
1459+
value,
14601460
links: None,
14611461
});
14621462
}
@@ -1851,7 +1851,7 @@ impl<'a, K, V, T> TryFrom<&'a HashMap<K, V>> for HeaderMap<T>
18511851
type Error = Error;
18521852

18531853
fn try_from(c: &'a HashMap<K, V>) -> Result<Self, Self::Error> {
1854-
c.into_iter()
1854+
c.iter()
18551855
.map(|(k, v)| -> crate::Result<(HeaderName, T)> {
18561856
let name = TryFrom::try_from(k).map_err(Into::into)?;
18571857
let value = TryFrom::try_from(v).map_err(Into::into)?;
@@ -2038,7 +2038,7 @@ fn append_value<T>(
20382038
Some(links) => {
20392039
let idx = extra.len();
20402040
extra.push(ExtraValue {
2041-
value: value,
2041+
value,
20422042
prev: Link::Extra(links.tail),
20432043
next: Link::Entry(entry_idx),
20442044
});
@@ -2050,7 +2050,7 @@ fn append_value<T>(
20502050
None => {
20512051
let idx = extra.len();
20522052
extra.push(ExtraValue {
2053-
value: value,
2053+
value,
20542054
prev: Link::Entry(entry_idx),
20552055
next: Link::Entry(entry_idx),
20562056
});
@@ -2422,7 +2422,7 @@ impl<'a, T> VacantEntry<'a, T> {
24222422
// Ensure that there is space in the map
24232423
let index =
24242424
self.map
2425-
.insert_phase_two(self.key, value.into(), self.hash, self.probe, self.danger);
2425+
.insert_phase_two(self.key, value, self.hash, self.probe, self.danger);
24262426

24272427
&mut self.map.entries[index].value
24282428
}
@@ -2449,11 +2449,11 @@ impl<'a, T> VacantEntry<'a, T> {
24492449
// Ensure that there is space in the map
24502450
let index =
24512451
self.map
2452-
.insert_phase_two(self.key, value.into(), self.hash, self.probe, self.danger);
2452+
.insert_phase_two(self.key, value, self.hash, self.probe, self.danger);
24532453

24542454
OccupiedEntry {
24552455
map: self.map,
2456-
index: index,
2456+
index,
24572457
probe: self.probe,
24582458
}
24592459
}
@@ -2863,7 +2863,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
28632863
/// assert_eq!("earth", map["host"]);
28642864
/// ```
28652865
pub fn insert(&mut self, value: T) -> T {
2866-
self.map.insert_occupied(self.index, value.into())
2866+
self.map.insert_occupied(self.index, value)
28672867
}
28682868

28692869
/// Sets the value of the entry.
@@ -2889,7 +2889,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
28892889
/// assert_eq!("earth", map["host"]);
28902890
/// ```
28912891
pub fn insert_mult(&mut self, value: T) -> ValueDrain<'_, T> {
2892-
self.map.insert_occupied_mult(self.index, value.into())
2892+
self.map.insert_occupied_mult(self.index, value)
28932893
}
28942894

28952895
/// Insert the value into the entry.
@@ -2916,7 +2916,7 @@ impl<'a, T> OccupiedEntry<'a, T> {
29162916
pub fn append(&mut self, value: T) {
29172917
let idx = self.index;
29182918
let entry = &mut self.map.entries[idx];
2919-
append_value(idx, entry, &mut self.map.extra_values, value.into());
2919+
append_value(idx, entry, &mut self.map.extra_values, value);
29202920
}
29212921

29222922
/// Remove the entry from the map.
@@ -3095,12 +3095,12 @@ impl<'a, T> Iterator for ValueDrain<'a, T> {
30953095
// Exactly 1
30963096
(&Some(_), &None) => (1, Some(1)),
30973097
// 1 + extras
3098-
(&Some(_), &Some(ref extras)) => {
3098+
(&Some(_), Some(extras)) => {
30993099
let (l, u) = extras.size_hint();
31003100
(l + 1, u.map(|u| u + 1))
31013101
},
31023102
// Extras only
3103-
(&None, &Some(ref extras)) => extras.size_hint(),
3103+
(&None, Some(extras)) => extras.size_hint(),
31043104
// No more
31053105
(&None, &None) => (0, Some(0)),
31063106
}
@@ -3111,7 +3111,7 @@ impl<'a, T> FusedIterator for ValueDrain<'a, T> {}
31113111

31123112
impl<'a, T> Drop for ValueDrain<'a, T> {
31133113
fn drop(&mut self) {
3114-
while let Some(_) = self.next() {}
3114+
for _ in self.by_ref() {}
31153115
}
31163116
}
31173117

@@ -3154,7 +3154,7 @@ impl Pos {
31543154
debug_assert!(index < MAX_SIZE);
31553155
Pos {
31563156
index: index as Size,
3157-
hash: hash,
3157+
hash,
31583158
}
31593159
}
31603160

@@ -3418,7 +3418,7 @@ mod as_header_name {
34183418
}
34193419

34203420
fn as_str(&self) -> &str {
3421-
<HeaderName>::as_str(*self)
3421+
<HeaderName>::as_str(self)
34223422
}
34233423
}
34243424

@@ -3472,7 +3472,7 @@ mod as_header_name {
34723472
}
34733473

34743474
fn as_str(&self) -> &str {
3475-
*self
3475+
self
34763476
}
34773477
}
34783478

src/header/name.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ impl HeaderName {
12561256
};
12571257
}
12581258

1259-
if name_bytes.len() == 0 || name_bytes.len() > super::MAX_HEADER_NAME_LEN || {
1259+
if name_bytes.is_empty() || name_bytes.len() > super::MAX_HEADER_NAME_LEN || {
12601260
let mut i = 0;
12611261
loop {
12621262
if i >= name_bytes.len() {
@@ -1283,7 +1283,7 @@ impl HeaderName {
12831283
pub fn as_str(&self) -> &str {
12841284
match self.inner {
12851285
Repr::Standard(v) => v.as_str(),
1286-
Repr::Custom(ref v) => &*v.0,
1286+
Repr::Custom(ref v) => &v.0,
12871287
}
12881288
}
12891289

@@ -1516,8 +1516,8 @@ impl<'a> HdrName<'a> {
15161516
HdrName {
15171517
// Invariant (on MaybeLower): follows from the precondition
15181518
inner: Repr::Custom(MaybeLower {
1519-
buf: buf,
1520-
lower: lower,
1519+
buf,
1520+
lower,
15211521
}),
15221522
}
15231523
}
@@ -1552,7 +1552,7 @@ impl<'a> From<HdrName<'a>> for HeaderName {
15521552
},
15531553
Repr::Custom(maybe_lower) => {
15541554
if maybe_lower.lower {
1555-
let buf = Bytes::copy_from_slice(&maybe_lower.buf[..]);
1555+
let buf = Bytes::copy_from_slice(maybe_lower.buf);
15561556
// Safety: the invariant on MaybeLower ensures buf is valid UTF-8.
15571557
let byte_str = unsafe { ByteStr::from_utf8_unchecked(buf) };
15581558

src/method.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ mod extension {
355355
}
356356

357357
pub fn as_str(&self) -> &str {
358-
// Safety: the invariant of AllocatedExtension ensures that self.0
358+
// SAFETY: the invariant of AllocatedExtension ensures that self.0
359359
// contains valid UTF-8.
360360
unsafe {str::from_utf8_unchecked(&self.0)}
361361
}
@@ -468,6 +468,6 @@ mod test {
468468
assert_eq!(Method::from_str("wOw!!").unwrap(), "wOw!!");
469469

470470
let long_method = "This_is_a_very_long_method.It_is_valid_but_unlikely.";
471-
assert_eq!(Method::from_str(&long_method).unwrap(), long_method);
471+
assert_eq!(Method::from_str(long_method).unwrap(), long_method);
472472
}
473473
}

src/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<T> Request<T> {
439439
pub fn new(body: T) -> Request<T> {
440440
Request {
441441
head: Parts::new(),
442-
body: body,
442+
body,
443443
}
444444
}
445445

@@ -459,7 +459,7 @@ impl<T> Request<T> {
459459
pub fn from_parts(parts: Parts, body: T) -> Request<T> {
460460
Request {
461461
head: parts,
462-
body: body,
462+
body,
463463
}
464464
}
465465

src/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<T> Response<T> {
251251
pub fn new(body: T) -> Response<T> {
252252
Response {
253253
head: Parts::new(),
254-
body: body,
254+
body,
255255
}
256256
}
257257

@@ -274,7 +274,7 @@ impl<T> Response<T> {
274274
pub fn from_parts(parts: Parts, body: T) -> Response<T> {
275275
Response {
276276
head: parts,
277-
body: body,
277+
body,
278278
}
279279
}
280280

src/status.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl StatusCode {
7171
/// ```
7272
#[inline]
7373
pub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode> {
74-
if src < 100 || src >= 1000 {
74+
if !(100..1000).contains(&src) {
7575
return Err(InvalidStatusCode::new());
7676
}
7777

@@ -265,7 +265,7 @@ impl FromStr for StatusCode {
265265
impl<'a> From<&'a StatusCode> for StatusCode {
266266
#[inline]
267267
fn from(t: &'a StatusCode) -> Self {
268-
t.clone()
268+
*t
269269
}
270270
}
271271

@@ -544,7 +544,7 @@ impl Error for InvalidStatusCode {}
544544

545545
// A string of packed 3-ASCII-digit status code values for the supported range
546546
// of [100, 999] (900 codes, 2700 bytes).
547-
const CODE_DIGITS: &'static str = "\
547+
const CODE_DIGITS: &str = "\
548548
100101102103104105106107108109110111112113114115116117118119\
549549
120121122123124125126127128129130131132133134135136137138139\
550550
140141142143144145146147148149150151152153154155156157158159\

src/uri/authority.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Authority {
238238
pub fn port(&self) -> Option<Port<&str>> {
239239
let bytes = self.as_str();
240240
bytes
241-
.rfind(":")
241+
.rfind(':')
242242
.and_then(|i| Port::from_str(&bytes[i + 1..]).ok())
243243
}
244244

@@ -253,7 +253,7 @@ impl Authority {
253253
/// assert_eq!(authority.port_u16(), Some(80));
254254
/// ```
255255
pub fn port_u16(&self) -> Option<u16> {
256-
self.port().and_then(|p| Some(p.as_u16()))
256+
self.port().map(|p| p.as_u16())
257257
}
258258

259259
/// Return a str representation of the authority
@@ -434,7 +434,7 @@ impl<'a> TryFrom<&'a [u8]> for Authority {
434434

435435
// Preconditon on create_authority: copy_from_slice() copies all of
436436
// bytes from the [u8] parameter into a new Bytes
437-
create_authority(s, |s| Bytes::copy_from_slice(s))
437+
create_authority(s, Bytes::copy_from_slice)
438438
}
439439
}
440440

@@ -485,8 +485,7 @@ impl fmt::Display for Authority {
485485
}
486486

487487
fn host(auth: &str) -> &str {
488-
let host_port = auth
489-
.rsplitn(2, '@')
488+
let host_port = auth.rsplit('@')
490489
.next()
491490
.expect("split always has at least 1 item");
492491

@@ -619,10 +618,10 @@ mod tests {
619618
#[test]
620619
fn compares_with_a_string() {
621620
let authority: Authority = "def.com".parse().unwrap();
622-
assert!(authority < "ghi.com".to_string());
623-
assert!("ghi.com".to_string() > authority);
624-
assert!(authority > "abc.com".to_string());
625-
assert!("abc.com".to_string() < authority);
621+
assert!(authority < *"ghi.com");
622+
assert!(*"ghi.com" > authority);
623+
assert!(authority > *"abc.com");
624+
assert!(*"abc.com" < authority);
626625
}
627626

628627
#[test]

0 commit comments

Comments
 (0)