Skip to content

Commit d962a9c

Browse files
committed
Add clippy as an optional dep and fix warnings
1 parent de573ff commit d962a9c

File tree

7 files changed

+87
-71
lines changed

7 files changed

+87
-71
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ uuid = { version = ">= 0.1, < 0.3", optional = true }
4040
security-framework = { version = "0.1.2", optional = true }
4141
bit-vec = { version = "0.4", optional = true }
4242
eui48 = { version = "0.1", optional = true }
43+
clippy = { version = "0.0.61", optional = true }
4344

4445
[dev-dependencies]
4546
url = "0.5"

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#![warn(missing_docs)]
4343
#![allow(unknown_lints, needless_lifetimes)] // for clippy
4444
#![cfg_attr(all(unix, feature = "nightly"), feature(unix_socket))]
45+
#![cfg_attr(feature = "clippy", feature(plugin))]
46+
#![cfg_attr(feature = "clippy", plugin(clippy))]
4547

4648
extern crate bufstream;
4749
extern crate byteorder;
@@ -800,6 +802,7 @@ impl InnerConnection {
800802
Ok(Type::Other(ty))
801803
}
802804

805+
#[allow(if_not_else)]
803806
fn read_type(&mut self, oid: Oid) -> Result<Other> {
804807
try!(self.raw_execute(TYPEINFO_QUERY, "", 0, &[Type::Oid], &[&oid]));
805808
let mut rows = VecDeque::new();

src/md5.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn write_u32_le(dst: &mut [u8], mut input: u32) {
100100
}
101101
}
102102

103-
/// The StandardPadding trait adds a method useful for various hash algorithms to a FixedBuffer
103+
/// The `StandardPadding` trait adds a method useful for various hash algorithms to a `FixedBuffer`
104104
/// struct.
105105
trait StandardPadding {
106106
/// Add standard padding to the buffer. The buffer must not be full when this method is called
@@ -125,11 +125,11 @@ impl<T: FixedBuffer> StandardPadding for T {
125125
}
126126
}
127127

128-
/// A FixedBuffer, likes its name implies, is a fixed size buffer. When the buffer becomes full, it
129-
/// must be processed. The input() method takes care of processing and then clearing the buffer
128+
/// A `FixedBuffer`, likes its name implies, is a fixed size buffer. When the buffer becomes full,
129+
/// it must be processed. The input() method takes care of processing and then clearing the buffer
130130
/// automatically. However, other methods do not and require the caller to process the buffer. Any
131-
/// method that modifies the buffer directory or provides the caller with bytes that can be modifies
132-
/// results in those bytes being marked as used by the buffer.
131+
/// method that modifies the buffer directory or provides the caller with bytes that can be
132+
/// modifies results in those bytes being marked as used by the buffer.
133133
trait FixedBuffer {
134134
/// Input a vector of bytes. If the buffer becomes full, process it with the provided
135135
/// function and then clear the buffer.
@@ -257,6 +257,7 @@ impl Clone for FixedBuffer64 {
257257

258258
impl FixedBuffer64 {
259259
/// Create a new buffer
260+
#[allow(new_without_default)]
260261
fn new() -> FixedBuffer64 {
261262
FixedBuffer64 {
262263
buffer: [0u8; 64],
@@ -276,6 +277,7 @@ struct Md5State {
276277
}
277278

278279
impl Md5State {
280+
#[allow(new_without_default)]
279281
fn new() -> Md5State {
280282
Md5State {
281283
s0: 0x67452301,
@@ -292,6 +294,7 @@ impl Md5State {
292294
self.s3 = 0x10325476;
293295
}
294296

297+
#[allow(many_single_char_names)]
295298
fn process_block(&mut self, input: &[u8]) {
296299
fn f(u: u32, v: u32, w: u32) -> u32 {
297300
(u & v) | (!u & w)
@@ -429,6 +432,7 @@ pub struct Md5 {
429432

430433
impl Md5 {
431434
/// Construct a new instance of the MD5 Digest.
435+
#[allow(new_without_default)]
432436
pub fn new() -> Md5 {
433437
Md5 {
434438
length_bytes: 0,

src/stmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ impl<'conn> StatementInternals<'conn> for Statement<'conn> {
6464

6565
impl<'conn> Statement<'conn> {
6666
fn finish_inner(&mut self) -> Result<()> {
67-
if !self.finished {
67+
if self.finished {
68+
Ok(())
69+
} else {
6870
self.finished = true;
6971
let mut conn = self.conn.conn.borrow_mut();
7072
check_desync!(conn);
7173
conn.close_statement(&self.info.name, b'S')
72-
} else {
73-
Ok(())
7474
}
7575
}
7676

src/transaction.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ pub struct Config {
6767
deferrable: Option<bool>,
6868
}
6969

70+
impl Default for Config {
71+
fn default() -> Config {
72+
Config {
73+
isolation_level: None,
74+
read_only: None,
75+
deferrable: None,
76+
}
77+
}
78+
}
79+
7080
impl ConfigInternals for Config {
7181
fn build_command(&self, s: &mut String) {
7282
let mut first = true;
@@ -105,11 +115,7 @@ impl ConfigInternals for Config {
105115
impl Config {
106116
/// Creates a new `Config` with no configuration overrides.
107117
pub fn new() -> Config {
108-
Config {
109-
isolation_level: None,
110-
read_only: None,
111-
deferrable: None,
112-
}
118+
Config::default()
113119
}
114120

115121
/// Sets the isolation level of the configuration.

src/types/mod.rs

+57-55
Original file line numberDiff line numberDiff line change
@@ -256,40 +256,41 @@ impl WrongTypeNew for WrongType {
256256
/// The following implementations are provided by this crate, along with the
257257
/// corresponding Postgres types:
258258
///
259-
/// | Rust type | Postgres type(s) |
260-
/// |---------------------------------------------|--------------------------------|
261-
/// | bool | BOOL |
262-
/// | i8 | "char" |
263-
/// | i16 | SMALLINT, SMALLSERIAL |
264-
/// | i32 | INT, SERIAL |
265-
/// | u32 | OID |
266-
/// | i64 | BIGINT, BIGSERIAL |
267-
/// | f32 | REAL |
268-
/// | f64 | DOUBLE PRECISION |
269-
/// | String | VARCHAR, CHAR(n), TEXT, CITEXT |
270-
/// | Vec&lt;u8&gt; | BYTEA |
271-
/// | HashMap&lt;String, Option&lt;String&gt;&gt; | HSTORE |
259+
/// | Rust type | Postgres type(s) |
260+
/// |-----------------------------------------------|--------------------------------|
261+
/// | `bool` | BOOL |
262+
/// | `i8` | "char" |
263+
/// | `i16` | SMALLINT, SMALLSERIAL |
264+
/// | `i32` | INT, SERIAL |
265+
/// | `u32` | OID |
266+
/// | `i64` | BIGINT, BIGSERIAL |
267+
/// | `f32` | REAL |
268+
/// | `f64` | DOUBLE PRECISION |
269+
/// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
270+
/// | `Vec&lt;u8&gt;` | BYTEA |
271+
/// | `HashMap&lt;String, Option&lt;String&gt;&gt;` | HSTORE |
272272
///
273273
/// In addition, some implementations are provided for types in third party
274274
/// crates. These are disabled by default; to opt into one of these
275275
/// implementations, activate the Cargo feature corresponding to the crate's
276276
/// name. For example, the `serde_json` feature enables the implementation for
277277
/// the `serde_json::Value` type.
278278
///
279-
/// | Rust type | Postgres type(s) |
280-
/// |-------------------------------------|-------------------------------------|
281-
/// | serialize::json::Json | JSON, JSONB |
282-
/// | serde_json::Value | JSON, JSONB |
283-
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
284-
/// | chrono::NaiveDateTime | TIMESTAMP |
285-
/// | chrono::DateTime&lt;UTC&gt; | TIMESTAMP WITH TIME ZONE |
286-
/// | chrono::DateTime&lt;Local&gt; | TIMESTAMP WITH TIME ZONE |
287-
/// | chrono::DateTime&lt;FixedOffset&gt; | TIMESTAMP WITH TIME ZONE |
288-
/// | chrono::NaiveDate | DATE |
289-
/// | chrono::NaiveTime | TIME |
290-
/// | eui48::MacAddress | MACADDR |
291-
/// | uuid::Uuid | UUID |
292-
/// | bit_vec::BitVec | BIT, VARBIT |
279+
/// | Rust type | Postgres type(s) |
280+
/// |---------------------------------------|-------------------------------------|
281+
/// | `serialize::json::Json` | JSON, JSONB |
282+
/// | `serde_json::Value` | JSON, JSONB |
283+
/// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
284+
/// | `chrono::NaiveDateTime` | TIMESTAMP |
285+
/// | `chrono::DateTime&lt;UTC&gt;` | TIMESTAMP WITH TIME ZONE |
286+
/// | `chrono::DateTime&lt;Local&gt;` | TIMESTAMP WITH TIME ZONE |
287+
/// | `chrono::DateTime&lt;FixedOffset&gt;` | TIMESTAMP WITH TIME ZONE |
288+
/// | `chrono::NaiveDate` | DATE |
289+
/// | `chrono::NaiveTime` | TIME |
290+
/// | `eui48::MacAddress` | MACADDR |
291+
/// | `uuid::Uuid` | UUID |
292+
/// | `bit_vec::BitVec` | BIT, VARBIT |
293+
/// | `eui48::MacAddress` | MACADDR |
293294
///
294295
/// # Nullability
295296
///
@@ -500,41 +501,42 @@ pub enum IsNull {
500501
/// The following implementations are provided by this crate, along with the
501502
/// corresponding Postgres types:
502503
///
503-
/// | Rust type | Postgres type(s) |
504-
/// |---------------------------------------------|--------------------------------|
505-
/// | bool | BOOL |
506-
/// | i8 | "char" |
507-
/// | i16 | SMALLINT, SMALLSERIAL |
508-
/// | i32 | INT, SERIAL |
509-
/// | u32 | OID |
510-
/// | i64 | BIGINT, BIGSERIAL |
511-
/// | f32 | REAL |
512-
/// | f64 | DOUBLE PRECISION |
513-
/// | String | VARCHAR, CHAR(n), TEXT, CITEXT |
514-
/// | &str | VARCHAR, CHAR(n), TEXT, CITEXT |
515-
/// | Vec&lt;u8&gt; | BYTEA |
516-
/// | &[u8] | BYTEA |
517-
/// | HashMap&lt;String, Option&lt;String&gt;&gt; | HSTORE |
504+
/// | Rust type | Postgres type(s) |
505+
/// |-----------------------------------------------|--------------------------------|
506+
/// | `bool` | BOOL |
507+
/// | `i8` | "char" |
508+
/// | `i16` | SMALLINT, SMALLSERIAL |
509+
/// | `i32` | INT, SERIAL |
510+
/// | `u32` | OID |
511+
/// | `i64` | BIGINT, BIGSERIAL |
512+
/// | `f32` | REAL |
513+
/// | `f64` | DOUBLE PRECISION |
514+
/// | `String` | VARCHAR, CHAR(n), TEXT, CITEXT |
515+
/// | `&str` | VARCHAR, CHAR(n), TEXT, CITEXT |
516+
/// | `Vec&lt;u8&gt;` | BYTEA |
517+
/// | `&[u8]` | BYTEA |
518+
/// | `HashMap&lt;String, Option&lt;String&gt;&gt;` | HSTORE |
518519
///
519520
/// In addition, some implementations are provided for types in third party
520521
/// crates. These are disabled by default; to opt into one of these
521522
/// implementations, activate the Cargo feature corresponding to the crate's
522523
/// name. For example, the `serde_json` feature enables the implementation for
523524
/// the `serde_json::Value` type.
524525
///
525-
/// | Rust type | Postgres type(s) |
526-
/// |-------------------------------------|-------------------------------------|
527-
/// | serialize::json::Json | JSON, JSONB |
528-
/// | serde_json::Value | JSON, JSONB |
529-
/// | time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
530-
/// | chrono::NaiveDateTime | TIMESTAMP |
531-
/// | chrono::DateTime&lt;UTC&gt; | TIMESTAMP WITH TIME ZONE |
532-
/// | chrono::DateTime&lt;Local&gt; | TIMESTAMP WITH TIME ZONE |
533-
/// | chrono::DateTime&lt;FixedOffset&gt; | TIMESTAMP WITH TIME ZONE |
534-
/// | chrono::NaiveDate | DATE |
535-
/// | chrono::NaiveTime | TIME |
536-
/// | uuid::Uuid | UUID |
537-
/// | bit_vec::BitVec | BIT, VARBIT |
526+
/// | Rust type | Postgres type(s) |
527+
/// |---------------------------------------|-------------------------------------|
528+
/// | `serialize::json::Json` | JSON, JSONB |
529+
/// | `serde_json::Value` | JSON, JSONB |
530+
/// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
531+
/// | `chrono::NaiveDateTime` | TIMESTAMP |
532+
/// | `chrono::DateTime&lt;UTC&gt;` | TIMESTAMP WITH TIME ZONE |
533+
/// | `chrono::DateTime&lt;Local&gt;` | TIMESTAMP WITH TIME ZONE |
534+
/// | `chrono::DateTime&lt;FixedOffset&gt;` | TIMESTAMP WITH TIME ZONE |
535+
/// | `chrono::NaiveDate` | DATE |
536+
/// | `chrono::NaiveTime` | TIME |
537+
/// | `uuid::Uuid` | UUID |
538+
/// | `bit_vec::BitVec` | BIT, VARBIT |
539+
/// | `eui48::MacAddress` | MACADDR |
538540
///
539541
/// # Nullability
540542
///

src/url.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Url {
5959
let (userinfo, host, port, rest) = try!(get_authority(rest));
6060

6161
// path
62-
let has_authority = host.len() > 0;
62+
let has_authority = !host.is_empty();
6363
let (path, rest) = try!(get_path(rest, has_authority));
6464

6565
// query and fragment
@@ -127,8 +127,8 @@ fn decode_inner(c: &str, full_url: bool) -> DecodeResult<String> {
127127
let bytes = match (iter.next(), iter.next()) {
128128
(Some(one), Some(two)) => [one, two],
129129
_ => {
130-
return Err(format!("Malformed input: found '%' without two \
131-
trailing bytes"))
130+
return Err("Malformed input: found '%' without two \
131+
trailing bytes".to_owned())
132132
}
133133
};
134134

0 commit comments

Comments
 (0)