Skip to content

Commit

Permalink
chore: address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Jul 20, 2023
1 parent 1040bc3 commit 3eb5a05
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 92 deletions.
2 changes: 1 addition & 1 deletion actix-http/src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use self::{decoder::Decoder, encoder::Encoder};
/// Special-purpose writer for streaming (de-)compression.
///
/// Pre-allocates 8KiB of capacity.
pub(self) struct Writer {
struct Writer {
buf: BytesMut,
}

Expand Down
2 changes: 1 addition & 1 deletion actix-http/src/ws/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {
#[test]
fn test_apply_mask() {
let mask = [0x6d, 0xb6, 0xb2, 0x80];
let unmasked = vec![
let unmasked = [
0xf3, 0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0xff, 0xfe, 0x00, 0x17, 0x74, 0xf9,
0x12, 0x03,
];
Expand Down
8 changes: 3 additions & 5 deletions actix-http/tests/test_server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::uninlined_format_args)]

use std::{
convert::Infallible,
io::{Read, Write},
Expand Down Expand Up @@ -139,7 +137,7 @@ async fn expect_continue_h1() {

#[actix_rt::test]
async fn chunked_payload() {
let chunk_sizes = vec![32768, 32, 32768];
let chunk_sizes = [32768, 32, 32768];
let total_size: usize = chunk_sizes.iter().sum();

let mut srv = test_server(|| {
Expand Down Expand Up @@ -402,7 +400,7 @@ async fn content_length() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|req: Request| {
let indx: usize = req.uri().path()[1..].parse().unwrap();
let idx: usize = req.uri().path()[1..].parse().unwrap();
let statuses = [
StatusCode::NO_CONTENT,
StatusCode::CONTINUE,
Expand All @@ -411,7 +409,7 @@ async fn content_length() {
StatusCode::OK,
StatusCode::NOT_FOUND,
];
ok::<_, Infallible>(Response::new(statuses[indx]))
ok::<_, Infallible>(Response::new(statuses[idx]))
})
.tcp()
})
Expand Down
7 changes: 6 additions & 1 deletion actix-router/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,12 @@ mod tests {
assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter()));

let mut s = String::new();
assert!(resource.resource_path_from_iter(&mut s, &mut vec!["item", "item2"].iter()));

assert!(resource.resource_path_from_iter(
&mut s,
#[allow(clippy::useless_vec)]
&mut vec!["item", "item2"].iter()
));
assert_eq!(s, "/user/item/item2/");
}

Expand Down
8 changes: 4 additions & 4 deletions actix-web/src/http/header/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ common_header! {
// Tests from the RFC
crate::http::header::common_header_test!(
test1,
vec![b"audio/*; q=0.2, audio/basic"],
[b"audio/*; q=0.2, audio/basic"],
Some(Accept(vec![
QualityItem::new("audio/*".parse().unwrap(), q(0.2)),
QualityItem::max("audio/basic".parse().unwrap()),
])));

crate::http::header::common_header_test!(
test2,
vec![b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
[b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
Some(Accept(vec![
QualityItem::new(mime::TEXT_PLAIN, q(0.5)),
QualityItem::max(mime::TEXT_HTML),
Expand All @@ -99,13 +99,13 @@ common_header! {
// Custom tests
crate::http::header::common_header_test!(
test3,
vec![b"text/plain; charset=utf-8"],
[b"text/plain; charset=utf-8"],
Some(Accept(vec![
QualityItem::max(mime::TEXT_PLAIN_UTF_8),
])));
crate::http::header::common_header_test!(
test4,
vec![b"text/plain; charset=utf-8; q=0.5"],
[b"text/plain; charset=utf-8; q=0.5"],
Some(Accept(vec![
QualityItem::new(mime::TEXT_PLAIN_UTF_8, q(0.5)),
])));
Expand Down
2 changes: 1 addition & 1 deletion actix-web/src/http/header/accept_charset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ common_header! {

test_parse_and_format {
// Test case from RFC
common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
common_header_test!(test1, [b"iso-8859-5, unicode-1-1;q=0.8"]);
}
}
14 changes: 7 additions & 7 deletions actix-web/src/http/header/accept_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,31 @@ common_header! {
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Preference<Encoding>>)*

test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], Some(AcceptEncoding(vec![])));
common_header_test!(empty_header, vec![b""; 1], Some(AcceptEncoding(vec![])));
common_header_test!(no_headers, [b""; 0], Some(AcceptEncoding(vec![])));
common_header_test!(empty_header, [b""; 1], Some(AcceptEncoding(vec![])));

common_header_test!(
order_of_appearance,
vec![b"br, gzip"],
[b"br, gzip"],
Some(AcceptEncoding(vec![
QualityItem::max(Preference::Specific(Encoding::brotli())),
QualityItem::max(Preference::Specific(Encoding::gzip())),
]))
);

common_header_test!(any, vec![b"*"], Some(AcceptEncoding(vec![
common_header_test!(any, [b"*"], Some(AcceptEncoding(vec![
QualityItem::max(Preference::Any),
])));

// Note: Removed quality 1 from gzip
common_header_test!(implicit_quality, vec![b"gzip, identity; q=0.5, *;q=0"]);
common_header_test!(implicit_quality, [b"gzip, identity; q=0.5, *;q=0"]);

// Note: Removed quality 1 from gzip
common_header_test!(implicit_quality_out_of_order, vec![b"compress;q=0.5, gzip"]);
common_header_test!(implicit_quality_out_of_order, [b"compress;q=0.5, gzip"]);

common_header_test!(
only_gzip_no_identity,
vec![b"gzip, *; q=0"],
[b"gzip, *; q=0"],
Some(AcceptEncoding(vec![
QualityItem::max(Preference::Specific(Encoding::gzip())),
QualityItem::zero(Preference::Any),
Expand Down
12 changes: 6 additions & 6 deletions actix-web/src/http/header/accept_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ common_header! {
(AcceptLanguage, header::ACCEPT_LANGUAGE) => (QualityItem<Preference<LanguageTag>>)*

test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], Some(AcceptLanguage(vec![])));
common_header_test!(no_headers, [b""; 0], Some(AcceptLanguage(vec![])));

common_header_test!(empty_header, vec![b""; 1], Some(AcceptLanguage(vec![])));
common_header_test!(empty_header, [b""; 1], Some(AcceptLanguage(vec![])));

common_header_test!(
example_from_rfc,
vec![b"da, en-gb;q=0.8, en;q=0.7"]
[b"da, en-gb;q=0.8, en;q=0.7"]
);


common_header_test!(
not_ordered_by_weight,
vec![b"en-US, en; q=0.5, fr"],
[b"en-US, en; q=0.5, fr"],
Some(AcceptLanguage(vec![
QualityItem::max("en-US".parse().unwrap()),
QualityItem::new("en".parse().unwrap(), q(0.5)),
Expand All @@ -80,7 +80,7 @@ common_header! {

common_header_test!(
has_wildcard,
vec![b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
[b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
Some(AcceptLanguage(vec![
QualityItem::max("fr-CH".parse().unwrap()),
QualityItem::new("fr".parse().unwrap(), q(0.9)),
Expand Down Expand Up @@ -137,7 +137,7 @@ impl AcceptLanguage {
b.quality.cmp(&a.quality)
});

types.into_iter().map(|qitem| qitem.item).collect()
types.into_iter().map(|q_item| q_item.item).collect()
}
}

Expand Down
6 changes: 3 additions & 3 deletions actix-web/src/http/header/allow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ crate::http::header::common_header! {
// From the RFC
crate::http::header::common_header_test!(
test1,
vec![b"GET, HEAD, PUT"],
[b"GET, HEAD, PUT"],
Some(HeaderField(vec![Method::GET, Method::HEAD, Method::PUT])));
// Own tests
crate::http::header::common_header_test!(
test2,
vec![b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH"],
[b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH"],
Some(HeaderField(vec![
Method::OPTIONS,
Method::GET,
Expand All @@ -69,7 +69,7 @@ crate::http::header::common_header! {
Method::PATCH])));
crate::http::header::common_header_test!(
test3,
vec![b""],
[b""],
Some(HeaderField(Vec::<Method>::new())));
}
}
12 changes: 6 additions & 6 deletions actix-web/src/http/header/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ common_header! {
(CacheControl, header::CACHE_CONTROL) => (CacheDirective)+

test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], None);
common_header_test!(empty_header, vec![b""; 1], None);
common_header_test!(bad_syntax, vec![b"foo="], None);
common_header_test!(no_headers, [b""; 0], None);
common_header_test!(empty_header, [b""; 1], None);
common_header_test!(bad_syntax, [b"foo="], None);

common_header_test!(
multiple_headers,
vec![&b"no-cache"[..], &b"private"[..]],
[&b"no-cache"[..], &b"private"[..]],
Some(CacheControl(vec![
CacheDirective::NoCache,
CacheDirective::Private,
Expand All @@ -62,7 +62,7 @@ common_header! {

common_header_test!(
argument,
vec![b"max-age=100, private"],
[b"max-age=100, private"],
Some(CacheControl(vec![
CacheDirective::MaxAge(100),
CacheDirective::Private,
Expand All @@ -71,7 +71,7 @@ common_header! {

common_header_test!(
extension,
vec![b"foo, bar=baz"],
[b"foo, bar=baz"],
Some(CacheControl(vec![
CacheDirective::Extension("foo".to_owned(), None),
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned())),
Expand Down
4 changes: 2 additions & 2 deletions actix-web/src/http/header/content_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ common_header! {
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+

test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"da"]);
crate::http::header::common_header_test!(test2, vec![b"mi, en"]);
crate::http::header::common_header_test!(test1, [b"da"]);
crate::http::header::common_header_test!(test2, [b"mi, en"]);
}
}
36 changes: 14 additions & 22 deletions actix-web/src/http/header/content_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,59 @@ crate::http::header::common_header! {

test_parse_and_format {
crate::http::header::common_header_test!(test_bytes,
vec![b"bytes 0-499/500"],
[b"bytes 0-499/500"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: Some((0, 499)),
instance_length: Some(500)
})));

crate::http::header::common_header_test!(test_bytes_unknown_len,
vec![b"bytes 0-499/*"],
[b"bytes 0-499/*"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: Some((0, 499)),
instance_length: None
})));

crate::http::header::common_header_test!(test_bytes_unknown_range,
vec![b"bytes */500"],
[b"bytes */500"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: None,
instance_length: Some(500)
})));

crate::http::header::common_header_test!(test_unregistered,
vec![b"seconds 1-2"],
[b"seconds 1-2"],
Some(ContentRange(ContentRangeSpec::Unregistered {
unit: "seconds".to_owned(),
resp: "1-2".to_owned()
})));

crate::http::header::common_header_test!(test_no_len,
vec![b"bytes 0-499"],
[b"bytes 0-499"],
None::<ContentRange>);

crate::http::header::common_header_test!(test_only_unit,
vec![b"bytes"],
[b"bytes"],
None::<ContentRange>);

crate::http::header::common_header_test!(test_end_less_than_start,
vec![b"bytes 499-0/500"],
[b"bytes 499-0/500"],
None::<ContentRange>);

crate::http::header::common_header_test!(test_blank,
vec![b""],
[b""],
None::<ContentRange>);

crate::http::header::common_header_test!(test_bytes_many_spaces,
vec![b"bytes 1-2/500 3"],
[b"bytes 1-2/500 3"],
None::<ContentRange>);

crate::http::header::common_header_test!(test_bytes_many_slashes,
vec![b"bytes 1-2/500/600"],
[b"bytes 1-2/500/600"],
None::<ContentRange>);

crate::http::header::common_header_test!(test_bytes_many_dashes,
vec![b"bytes 1-2-3/500"],
[b"bytes 1-2-3/500"],
None::<ContentRange>);

}
Expand Down Expand Up @@ -113,21 +113,13 @@ pub enum ContentRangeSpec {
},
}

fn split_in_two(s: &str, separator: char) -> Option<(&str, &str)> {
let mut iter = s.splitn(2, separator);
match (iter.next(), iter.next()) {
(Some(a), Some(b)) => Some((a, b)),
_ => None,
}
}

impl FromStr for ContentRangeSpec {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, ParseError> {
let res = match split_in_two(s, ' ') {
let res = match s.split_once(' ') {
Some(("bytes", resp)) => {
let (range, instance_length) = split_in_two(resp, '/').ok_or(ParseError::Header)?;
let (range, instance_length) = resp.split_once('/').ok_or(ParseError::Header)?;

let instance_length = if instance_length == "*" {
None
Expand All @@ -139,7 +131,7 @@ impl FromStr for ContentRangeSpec {
None
} else {
let (first_byte, last_byte) =
split_in_two(range, '-').ok_or(ParseError::Header)?;
range.split_once('-').ok_or(ParseError::Header)?;
let first_byte = first_byte.parse().map_err(|_| ParseError::Header)?;
let last_byte = last_byte.parse().map_err(|_| ParseError::Header)?;
if last_byte < first_byte {
Expand Down
4 changes: 2 additions & 2 deletions actix-web/src/http/header/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ crate::http::header::common_header! {
test_parse_and_format {
crate::http::header::common_header_test!(
test_text_html,
vec![b"text/html"],
[b"text/html"],
Some(HeaderField(mime::TEXT_HTML)));
crate::http::header::common_header_test!(
test_image_star,
vec![b"image/*"],
[b"image/*"],
Some(HeaderField(mime::IMAGE_STAR)));

}
Expand Down
2 changes: 1 addition & 1 deletion actix-web/src/http/header/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ crate::http::header::common_header! {
(Date, DATE) => [HttpDate]

test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]);
crate::http::header::common_header_test!(test1, [b"Tue, 15 Nov 1994 08:12:31 GMT"]);
}
}

Expand Down
Loading

0 comments on commit 3eb5a05

Please sign in to comment.