Skip to content

Commit 5b54a69

Browse files
committed
Clean up stuff pointed out by clippy
1 parent 5179018 commit 5b54a69

File tree

8 files changed

+60
-56
lines changed

8 files changed

+60
-56
lines changed

src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ impl error::Error for ConnectError {
208208

209209
fn cause(&self) -> Option<&error::Error> {
210210
match *self {
211-
ConnectError::ConnectParams(ref err) => Some(&**err),
211+
ConnectError::ConnectParams(ref err) | ConnectError::Ssl(ref err) => Some(&**err),
212212
ConnectError::Db(ref err) => Some(&**err),
213-
ConnectError::Ssl(ref err) => Some(&**err),
214213
ConnectError::Io(ref err) => Some(err),
215214
}
216215
}

src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! ```
4141
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.3")]
4242
#![warn(missing_docs)]
43+
#![allow(unknown_lints, needless_lifetimes)] // for clippy
4344

4445
extern crate bufstream;
4546
extern crate byteorder;
@@ -162,21 +163,13 @@ impl<'a> IntoConnectParams for &'a str {
162163
fn into_connect_params(self) -> result::Result<ConnectParams, Box<StdError + StdSync + Send>> {
163164
match Url::parse(self) {
164165
Ok(url) => url.into_connect_params(),
165-
Err(err) => return Err(err.into()),
166+
Err(err) => Err(err.into()),
166167
}
167168
}
168169
}
169170

170171
impl IntoConnectParams for Url {
171172
fn into_connect_params(self) -> result::Result<ConnectParams, Box<StdError + StdSync + Send>> {
172-
let Url {
173-
host,
174-
port,
175-
user,
176-
path: url::Path { mut path, query: options, .. },
177-
..
178-
} = self;
179-
180173
#[cfg(feature = "unix_socket")]
181174
fn make_unix(maybe_path: String)
182175
-> result::Result<ConnectTarget, Box<StdError + StdSync + Send>> {
@@ -187,8 +180,16 @@ impl IntoConnectParams for Url {
187180
Err("unix socket support requires the `unix_socket` feature".into())
188181
}
189182

183+
let Url {
184+
host,
185+
port,
186+
user,
187+
path: url::Path { mut path, query: options, .. },
188+
..
189+
} = self;
190+
190191
let maybe_path = try!(url::decode_component(&host));
191-
let target = if maybe_path.starts_with("/") {
192+
let target = if maybe_path.starts_with('/') {
192193
try!(make_unix(maybe_path))
193194
} else {
194195
ConnectTarget::Tcp(host)
@@ -633,8 +634,8 @@ impl InnerConnection {
633634

634635
match try!(self.read_message()) {
635636
AuthenticationOk => Ok(()),
636-
ErrorResponse { fields } => return DbError::new_connect(fields),
637-
_ => return Err(ConnectError::Io(bad_response())),
637+
ErrorResponse { fields } => DbError::new_connect(fields),
638+
_ => Err(ConnectError::Io(bad_response())),
638639
}
639640
}
640641

@@ -716,9 +717,8 @@ impl InnerConnection {
716717
}
717718
CopyOutResponse { .. } => {
718719
loop {
719-
match try!(self.read_message()) {
720-
ReadyForQuery { .. } => break,
721-
_ => {}
720+
if let ReadyForQuery { .. } = try!(self.read_message()) {
721+
break;
722722
}
723723
}
724724
return Err(Error::Io(std_io::Error::new(std_io::ErrorKind::InvalidInput,

src/md5.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ trait FixedBuffer {
144144

145145
/// Get a slice of the buffer of the specified size. There must be at least that many bytes
146146
/// remaining in the buffer.
147-
fn next<'s>(&'s mut self, len: usize) -> &'s mut [u8];
147+
fn next(&mut self, len: usize) -> &mut [u8];
148148

149149
/// Get the current buffer. The buffer must already be full. This clears the buffer as well.
150-
fn full_buffer<'s>(&'s mut self) -> &'s [u8];
150+
fn full_buffer(&mut self) -> &[u8];
151151

152152
/// Get the current buffer.
153-
fn current_buffer<'s>(&'s mut self) -> &'s [u8];
153+
fn current_buffer(&mut self) -> &[u8];
154154

155155
/// Get the current position of the buffer.
156156
fn position(&self) -> usize;
@@ -217,18 +217,18 @@ macro_rules! impl_fixed_buffer( ($name:ident, $size:expr) => (
217217
self.buffer_idx = idx;
218218
}
219219

220-
fn next<'s>(&'s mut self, len: usize) -> &'s mut [u8] {
220+
fn next(&mut self, len: usize) -> &mut [u8] {
221221
self.buffer_idx += len;
222222
&mut self.buffer[self.buffer_idx - len..self.buffer_idx]
223223
}
224224

225-
fn full_buffer<'s>(&'s mut self) -> &'s [u8] {
225+
fn full_buffer(&mut self) -> &[u8] {
226226
assert!(self.buffer_idx == $size);
227227
self.buffer_idx = 0;
228228
&self.buffer[..$size]
229229
}
230230

231-
fn current_buffer<'s>(&'s mut self) -> &'s [u8] {
231+
fn current_buffer(&mut self) -> &[u8] {
232232
let tmp = self.buffer_idx;
233233
self.buffer_idx = 0;
234234
&self.buffer[..tmp]

src/notification.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ impl<'conn> Notifications<'conn> {
3737
self.conn.conn.borrow().notifications.len()
3838
}
3939

40+
/// Determines if there are any pending notifications.
41+
pub fn is_empty(&self) -> bool {
42+
self.len() == 0
43+
}
44+
4045
/// Returns an iterator over pending notifications.
4146
///
4247
/// # Note

src/rows.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ impl<'stmt> Rows<'stmt> {
7272
self.data.len()
7373
}
7474

75+
/// Determines if there are any rows present.
76+
pub fn is_empty(&self) -> bool {
77+
self.len() == 0
78+
}
79+
7580
/// Returns a specific `Row`.
7681
///
7782
/// # Panics
@@ -158,6 +163,11 @@ impl<'a> Row<'a> {
158163
self.data.len()
159164
}
160165

166+
/// Determines if there are any values in the row.
167+
pub fn is_empty(&self) -> bool {
168+
self.len() == 0
169+
}
170+
161171
/// Returns a slice describing the columns of the `Row`.
162172
pub fn columns(&self) -> &[Column] {
163173
self.stmt.columns()
@@ -192,7 +202,7 @@ impl<'a> Row<'a> {
192202
match self.get_inner(&idx) {
193203
Some(Ok(ok)) => ok,
194204
Some(Err(err)) => panic!("error retrieving column {:?}: {:?}", idx, err),
195-
None => panic!("no such column {:?}"),
205+
None => panic!("no such column {:?}", idx),
196206
}
197207
}
198208

src/stmt.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,11 @@ impl<'conn> Statement<'conn> {
272272
}
273273
_ => {
274274
loop {
275-
match try!(conn.read_message()) {
276-
ReadyForQuery { .. } => {
277-
return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput,
278-
"called `copy_in` on a \
279-
non-`COPY FROM STDIN` \
280-
statement")));
281-
}
282-
_ => {}
275+
if let ReadyForQuery { .. } = try!(conn.read_message()) {
276+
return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput,
277+
"called `copy_in` on a \
278+
non-`COPY FROM STDIN` \
279+
statement")));
283280
}
284281
}
285282
}
@@ -384,13 +381,10 @@ impl<'conn> Statement<'conn> {
384381
}
385382
_ => {
386383
loop {
387-
match try!(conn.read_message()) {
388-
ReadyForQuery { .. } => {
389-
return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput,
390-
"called `copy_out` on a \
391-
non-`COPY TO STDOUT` statement")));
392-
}
393-
_ => {}
384+
if let ReadyForQuery { .. } = try!(conn.read_message()) {
385+
return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput,
386+
"called `copy_out` on a \
387+
non-`COPY TO STDOUT` statement")));
394388
}
395389
}
396390
}
@@ -412,9 +406,8 @@ impl<'conn> Statement<'conn> {
412406
Ok(n) => data = &data[n..],
413407
Err(e) => {
414408
loop {
415-
match try!(info.conn.read_message()) {
416-
ReadyForQuery { .. } => return Err(Error::Io(e)),
417-
_ => {}
409+
if let ReadyForQuery { .. } = try!(info.conn.read_message()) {
410+
return Err(Error::Io(e));
418411
}
419412
}
420413
}
@@ -428,17 +421,15 @@ impl<'conn> Statement<'conn> {
428421
}
429422
ErrorResponse { fields } => {
430423
loop {
431-
match try!(info.conn.read_message()) {
432-
ReadyForQuery { .. } => return DbError::new(fields),
433-
_ => {}
424+
if let ReadyForQuery { .. } = try!(info.conn.read_message()) {
425+
return DbError::new(fields);
434426
}
435427
}
436428
}
437429
_ => {
438430
loop {
439-
match try!(info.conn.read_message()) {
440-
ReadyForQuery { .. } => return Err(Error::Io(bad_response())),
441-
_ => {}
431+
if let ReadyForQuery { .. } = try!(info.conn.read_message()) {
432+
return Err(Error::Io(bad_response()));
442433
}
443434
}
444435
}

src/types/slice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
3333
mut w: &mut W,
3434
ctx: &SessionInfo)
3535
-> Result<IsNull> {
36-
let member_type = match ty.kind() {
37-
&Kind::Array(ref member) => member,
36+
let member_type = match *ty.kind() {
37+
Kind::Array(ref member) => member,
3838
_ => panic!("expected array type"),
3939
};
4040

@@ -61,8 +61,8 @@ impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
6161
}
6262

6363
fn accepts(ty: &Type) -> bool {
64-
match ty.kind() {
65-
&Kind::Array(ref member) => T::accepts(member),
64+
match *ty.kind() {
65+
Kind::Array(ref member) => T::accepts(member),
6666
_ => false,
6767
}
6868
}

src/url.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn decode_component(container: &str) -> DecodeResult<String> {
117117

118118
fn decode_inner(c: &str, full_url: bool) -> DecodeResult<String> {
119119
let mut out = String::new();
120-
let mut iter = c.as_bytes().iter().map(|&b| b);
120+
let mut iter = c.as_bytes().iter().cloned();
121121

122122
loop {
123123
match iter.next() {
@@ -367,7 +367,6 @@ fn get_authority(rawurl: &str) -> DecodeResult<(Option<UserInfo>, &str, Option<u
367367

368368
// finish up
369369
match st {
370-
State::Start => host = &rawurl[begin..end],
371370
State::PassHostPort |
372371
State::Ip6Port => {
373372
if input != Input::Digit {
@@ -377,7 +376,7 @@ fn get_authority(rawurl: &str) -> DecodeResult<(Option<UserInfo>, &str, Option<u
377376
port = Some(&rawurl[pos + 1..end]);
378377
}
379378
State::Ip6Host |
380-
State::InHost => host = &rawurl[begin..end],
379+
State::InHost | State::Start => host = &rawurl[begin..end],
381380
State::InPort => {
382381
if input != Input::Digit {
383382
return Err("Non-digit characters in port.".to_owned());
@@ -437,7 +436,7 @@ fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> {
437436
}
438437
}
439438

440-
if is_authority && end != 0 && !rawurl.starts_with("/") {
439+
if is_authority && end != 0 && !rawurl.starts_with('/') {
441440
Err("Non-empty path must begin with '/' in presence of authority.".to_owned())
442441
} else {
443442
Ok((try!(decode_component(&rawurl[0..end])), &rawurl[end..len]))

0 commit comments

Comments
 (0)