Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

Commit e0852e4

Browse files
committed
Auto merge of #103 - mcarton:clippy, r=Ogeon
Fix some Clippy warnings There are 5 warnings left: - one `needless_lifetimes` which is a false positive (reported there: https://github.com/Manishearth/rust-clippy/issues/740#issuecomment-205826823); - 3 `type_complexity` warnings that I did not fix because they seem legit; - one `wrong_self_convention` which seems semi-legit too, although it’s a little surprising to have an `is_empty` function require a `&mut self`. Here they are, FYI: ```rust src/router/tree_router.rs:80:5: 110:6 warning: explicit lifetimes given in parameter types where they could be elided, #[warn(needless_lifetimes)] on by default src/router/tree_router.rs: 80 fn merge_router<'a, I: Iterator<Item = &'a [u8]> + Clone>(&mut self, state: InsertState<'a, I>, router: TreeRouter<T>) { src/router/tree_router.rs: 81 self.item.insert_router(state.clone(), router.item); src/router/tree_router.rs: 82 src/router/tree_router.rs: 83 for (key, router) in router.static_routes { src/router/tree_router.rs: 84 let next = match self.static_routes.entry(key.clone()) { src/router/tree_router.rs: 85 Occupied(entry) => entry.into_mut(), ... src/router/tree_router.rs:80:5: 110:6 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_lifetimes src/router/mod.rs:357:21: 357:71 warning: very complex type used. Consider factoring parts into `type` definitions, #[warn(type_complexity)] on by default src/router/mod.rs:357 type Segments = RouteIter<Split<'a, u8, &'static fn(&u8) -> bool>>; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/router/mod.rs:357:21: 357:71 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#type_complexity src/router/mod.rs:365:21: 365:71 warning: very complex type used. Consider factoring parts into `type` definitions, #[warn(type_complexity)] on by default src/router/mod.rs:365 type Segments = RouteIter<Split<'a, u8, &'static fn(&u8) -> bool>>; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/router/mod.rs:365:21: 365:71 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#type_complexity src/router/mod.rs:393:21: 393:170 warning: very complex type used. Consider factoring parts into `type` definitions, #[warn(type_complexity)] on by default src/router/mod.rs:393 type Segments = FlatMap<<&'a I as IntoIterator>::IntoIter, <<T as Deref>::Target as Route<'a>>::Segments, fn(&'a T) -> <<T as Deref>::Target as Route<'a>>::Segments>; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/router/mod.rs:393:21: 393:170 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#type_complexity src/router/mod.rs:449:21: 449:34 warning: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name, #[warn(wrong_self_convention)] on by default src/router/mod.rs:449 pub fn is_empty(&mut self) -> bool { ^~~~~~~~~~~~~ src/router/mod.rs:449:21: 449:34 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#wrong_self_convention ```
2 parents c7c89c9 + e59e0d1 commit e0852e4

File tree

7 files changed

+20
-24
lines changed

7 files changed

+20
-24
lines changed

src/context/maybe_utf8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<S, V> MaybeUtf8<S, V> {
6262
///let string = MaybeUtf8Owned::from("abc");
6363
///assert_eq!("abc", string.as_utf8_lossy());
6464
///```
65-
pub fn as_utf8_lossy<'a>(&'a self) -> Cow<'a, str> where S: AsRef<str>, V: AsRef<[u8]> {
65+
pub fn as_utf8_lossy(&self) -> Cow<str> where S: AsRef<str>, V: AsRef<[u8]> {
6666
match *self {
6767
MaybeUtf8::Utf8(ref s) => s.as_ref().into(),
6868
MaybeUtf8::NotUtf8(ref v) => String::from_utf8_lossy(v.as_ref())

src/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Uri {
197197

198198
///Borrow the URI as a UTF-8 path, if valid, or convert it to a valid
199199
///UTF-8 string.
200-
pub fn as_utf8_path_lossy<'a>(&'a self) -> Option<Cow<'a, str>> {
200+
pub fn as_utf8_path_lossy(&self) -> Option<Cow<str>> {
201201
match *self {
202202
Uri::Path(ref path) => Some(path.as_utf8_lossy()),
203203
Uri::Asterisk => None

src/response.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ impl<'a, 'b> FileError<'a, 'b> {
144144
impl<'a, 'b> Into<io::Error> for FileError<'a, 'b> {
145145
fn into(self) -> io::Error {
146146
match self {
147-
FileError::Open(e, _) => e,
148-
FileError::Send(e) => e
147+
FileError::Open(e, _) | FileError::Send(e) => e
149148
}
150149
}
151150
}
@@ -171,15 +170,13 @@ impl<'a, 'b> std::fmt::Display for FileError<'a, 'b> {
171170
impl<'a, 'b> error::Error for FileError<'a, 'b> {
172171
fn description(&self) -> &str {
173172
match *self {
174-
FileError::Open(ref e, _) => e.description(),
175-
FileError::Send(ref e) => e.description()
173+
FileError::Open(ref e, _) | FileError::Send(ref e) => e.description()
176174
}
177175
}
178176

179177
fn cause(&self) -> Option<&std::error::Error> {
180178
match *self {
181-
FileError::Open(ref e, _) => Some(e),
182-
FileError::Send(ref e) => Some(e)
179+
FileError::Open(ref e, _) | FileError::Send(ref e) => Some(e)
183180
}
184181
}
185182
}
@@ -522,7 +519,7 @@ impl<'a, 'b> Response<'a, 'b> {
522519
let mime = path
523520
.extension()
524521
.and_then(|ext| to_mime(&ext.to_string_lossy()))
525-
.unwrap_or(Mime(TopLevel::Application, SubLevel::Ext("octet-stream".into()), vec![]));
522+
.unwrap_or_else(|| Mime(TopLevel::Application, SubLevel::Ext("octet-stream".into()), vec![]));
526523

527524
let mut file = match File::open(path) {
528525
Ok(file) => file,
@@ -900,8 +897,7 @@ fn filter_headers<'a>(
900897

901898
for filter in filters {
902899
header_result = match header_result {
903-
(_, Action::SilentAbort) => break,
904-
(_, Action::Abort(_)) => break,
900+
(_, Action::SilentAbort) | (_, Action::Abort(_)) => break,
905901
(status, r) => {
906902
write_queue.push(r);
907903

@@ -917,7 +913,7 @@ fn filter_headers<'a>(
917913
(status, Action::Abort(e)) => (status, Action::Abort(e)),
918914
(status, result) => {
919915
let mut error = None;
920-
916+
921917
write_queue = write_queue.into_iter().filter_map(|action| match action {
922918
Action::Next(content) => {
923919
let filter_context = FilterContext {

src/router/tree_router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<T: Router + Default> Router for TreeRouter<T> {
147147
}
148148
}
149149

150-
for (segment, _next) in &current.static_routes {
150+
for segment in current.static_routes.keys() {
151151
result.hyperlinks.push(Link {
152152
method: None,
153153
path: vec![LinkSegment {
@@ -224,7 +224,7 @@ impl<T: Router + Default> Router for TreeRouter<T> {
224224
fn hyperlinks<'a>(&'a self, base: Link<'a>) -> Vec<Link<'a>> {
225225
let mut links = self.item.hyperlinks(base.clone());
226226

227-
for (segment, _next) in &self.static_routes {
227+
for segment in self.static_routes.keys() {
228228
let mut link = base.clone();
229229
link.path.push(LinkSegment {
230230
label: segment.as_slice(),

src/server/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ impl Host {
4848
///Change the port of the host address.
4949
pub fn port(&mut self, port: u16) {
5050
self.0 = match self.0 {
51-
SocketAddr::V4(addr) => SocketAddr::V4(SocketAddrV4::new(addr.ip().clone(), port)),
51+
SocketAddr::V4(addr) => SocketAddr::V4(SocketAddrV4::new(*addr.ip(), port)),
5252
SocketAddr::V6(addr) => {
53-
SocketAddr::V6(SocketAddrV6::new(addr.ip().clone(), port, addr.flowinfo(), addr.scope_id()))
53+
SocketAddr::V6(SocketAddrV6::new(*addr.ip(), port, addr.flowinfo(), addr.scope_id()))
5454
}
5555
};
5656
}

src/server/instance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn parse_path(path: &str) -> ParsedUri {
266266

267267
let mut path = percent_decode(path[..index].as_bytes());
268268
if path.is_empty() {
269-
path.push('/' as u8);
269+
path.push(b'/');
270270
}
271271

272272
ParsedUri {
@@ -281,7 +281,7 @@ fn parse_path(path: &str) -> ParsedUri {
281281

282282
let mut path = percent_decode(path.as_bytes());
283283
if path.is_empty() {
284-
path.push('/' as u8);
284+
path.push(b'/');
285285
}
286286

287287
ParsedUri {
@@ -304,11 +304,11 @@ fn parse_fragment(path: &str) -> (&str, Option<&str>) {
304304
fn parse_url(url: Url) -> ParsedUri {
305305
let mut path = Vec::new();
306306
for component in url.path().unwrap_or(&[]) {
307-
path.push('/' as u8);
307+
path.push(b'/');
308308
percent_decode_to(component.as_bytes(), &mut path);
309309
}
310310
if path.is_empty() {
311-
path.push('/' as u8);
311+
path.push(b'/');
312312
}
313313

314314
let query = url.query_pairs()

src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use context::Parameters;
55
pub fn parse_parameters(source: &[u8]) -> Parameters {
66
let mut parameters = Parameters::new();
77
let source: Vec<u8> = source.iter()
8-
.map(|&e| if e == '+' as u8 { ' ' as u8 } else { e })
8+
.map(|&e| if e == b'+' { b' ' } else { e })
99
.collect();
1010

11-
for parameter in source.split(|&e| e == '&' as u8) {
12-
let mut parts = parameter.split(|&e| e == '=' as u8);
11+
for parameter in source.split(|&e| e == b'&') {
12+
let mut parts = parameter.split(|&e| e == b'=');
1313

1414
match (parts.next(), parts.next()) {
1515
(Some(name), Some(value)) => {
@@ -77,4 +77,4 @@ mod test {
7777
assert_eq!(parameters.get_raw(""), Some(&aa));
7878
assert_eq!(parameters.get_raw("ab"), Some(&ab));
7979
}
80-
}
80+
}

0 commit comments

Comments
 (0)