Skip to content

Commit 04ce4bb

Browse files
committed
Run clippy
1 parent 8c3338e commit 04ce4bb

File tree

29 files changed

+622
-790
lines changed

29 files changed

+622
-790
lines changed

.circleci/config.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ jobs:
2828
- image: sfackler/rust-postgres-test:5
2929
steps:
3030
- checkout
31-
- run: rustup component add rustfmt
31+
- run: rustup component add rustfmt clippy
3232
- run: cargo fmt --all -- --check
33+
- run: cargo clippy --all
3334
- *RESTORE_REGISTRY
3435
- run: cargo generate-lockfile
3536
- *SAVE_REGISTRY

codegen/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::all)]
2+
13
extern crate linked_hash_map;
24
extern crate marksman_escape;
35
extern crate phf_codegen;

codegen/src/sqlstate.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs::File;
44
use std::io::{BufWriter, Write};
55
use std::path::Path;
66

7-
const ERRCODES_TXT: &'static str = include_str!("errcodes.txt");
7+
const ERRCODES_TXT: &str = include_str!("errcodes.txt");
88

99
pub fn build(path: &Path) {
1010
let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap());
@@ -20,7 +20,7 @@ fn parse_codes() -> LinkedHashMap<String, Vec<String>> {
2020
let mut codes = LinkedHashMap::new();
2121

2222
for line in ERRCODES_TXT.lines() {
23-
if line.starts_with("#") || line.starts_with("Section") || line.trim().is_empty() {
23+
if line.starts_with('#') || line.starts_with("Section") || line.trim().is_empty() {
2424
continue;
2525
}
2626

@@ -39,7 +39,6 @@ fn make_type(file: &mut BufWriter<File>) {
3939
write!(
4040
file,
4141
"// Autogenerated file - DO NOT EDIT
42-
use phf;
4342
use std::borrow::Cow;
4443
4544
/// A SQLSTATE error code
@@ -96,5 +95,5 @@ static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = "
9695
builder.entry(&**code, &format!("SqlState::{}", &names[0]));
9796
}
9897
builder.build(file).unwrap();
99-
write!(file, ";\n").unwrap();
98+
writeln!(file, ";").unwrap();
10099
}

codegen/src/type_gen.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::path::Path;
77

88
use crate::snake_to_camel;
99

10-
const PG_TYPE_H: &'static str = include_str!("pg_type.h");
11-
const PG_RANGE_H: &'static str = include_str!("pg_range.h");
10+
const PG_TYPE_H: &str = include_str!("pg_type.h");
11+
const PG_RANGE_H: &str = include_str!("pg_range.h");
1212

1313
struct Type {
1414
name: &'static str,
@@ -122,7 +122,7 @@ fn make_header(w: &mut BufWriter<File>) {
122122
"// Autogenerated file - DO NOT EDIT
123123
use std::sync::Arc;
124124
125-
use types::{{Type, Oid, Kind}};
125+
use crate::types::{{Type, Oid, Kind}};
126126
127127
#[derive(PartialEq, Eq, Debug)]
128128
pub struct Other {{
@@ -231,8 +231,7 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
231231
write!(
232232
w,
233233
" Inner::{} => {{
234-
const V: &'static Kind = &Kind::{};
235-
V
234+
&Kind::{}
236235
}}
237236
",
238237
type_.variant, kind

postgres-protocol/src/authentication/sasl.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use std::str;
1414
const NONCE_LENGTH: usize = 24;
1515

1616
/// The identifier of the SCRAM-SHA-256 SASL authentication mechanism.
17-
pub const SCRAM_SHA_256: &'static str = "SCRAM-SHA-256";
17+
pub const SCRAM_SHA_256: &str = "SCRAM-SHA-256";
1818
/// The identifier of the SCRAM-SHA-256-PLUS SASL authentication mechanism.
19-
pub const SCRAM_SHA_256_PLUS: &'static str = "SCRAM-SHA-256-PLUS";
19+
pub const SCRAM_SHA_256_PLUS: &str = "SCRAM-SHA-256-PLUS";
2020

2121
// since postgres passwords are not required to exclude saslprep-prohibited
2222
// characters or even be valid UTF8, we run saslprep if possible and otherwise
@@ -153,7 +153,7 @@ impl ScramSha256 {
153153
state: State::Update {
154154
nonce,
155155
password: normalize(password),
156-
channel_binding: channel_binding,
156+
channel_binding,
157157
},
158158
}
159159
}
@@ -228,8 +228,8 @@ impl ScramSha256 {
228228
write!(&mut self.message, ",p={}", base64::encode(&*client_proof)).unwrap();
229229

230230
self.state = State::Finish {
231-
salted_password: salted_password,
232-
auth_message: auth_message,
231+
salted_password,
232+
auth_message,
233233
};
234234
Ok(())
235235
}
@@ -288,7 +288,7 @@ struct Parser<'a> {
288288
impl<'a> Parser<'a> {
289289
fn new(s: &'a str) -> Parser<'a> {
290290
Parser {
291-
s: s,
291+
s,
292292
it: s.char_indices().peekable(),
293293
}
294294
}
@@ -390,9 +390,9 @@ impl<'a> Parser<'a> {
390390
self.eof()?;
391391

392392
Ok(ServerFirstMessage {
393-
nonce: nonce,
394-
salt: salt,
395-
iteration_count: iteration_count,
393+
nonce,
394+
salt,
395+
iteration_count,
396396
})
397397
}
398398

postgres-protocol/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! This library assumes that the `client_encoding` backend parameter has been
1111
//! set to `UTF8`. It will most likely not behave properly if that is not the case.
1212
#![doc(html_root_url = "https://docs.rs/postgres-protocol/0.3")]
13-
#![warn(missing_docs, rust_2018_idioms)]
13+
#![warn(missing_docs, rust_2018_idioms, clippy::all)]
1414

1515
use byteorder::{BigEndian, ByteOrder};
1616
use std::io;

postgres-protocol/src/message/backend.rs

+37-52
Original file line numberDiff line numberDiff line change
@@ -88,65 +88,62 @@ impl Message {
8888
let channel = buf.read_cstr()?;
8989
let message = buf.read_cstr()?;
9090
Message::NotificationResponse(NotificationResponseBody {
91-
process_id: process_id,
92-
channel: channel,
93-
message: message,
91+
process_id,
92+
channel,
93+
message,
9494
})
9595
}
9696
b'c' => Message::CopyDone,
9797
b'C' => {
9898
let tag = buf.read_cstr()?;
99-
Message::CommandComplete(CommandCompleteBody { tag: tag })
99+
Message::CommandComplete(CommandCompleteBody { tag })
100100
}
101101
b'd' => {
102102
let storage = buf.read_all();
103-
Message::CopyData(CopyDataBody { storage: storage })
103+
Message::CopyData(CopyDataBody { storage })
104104
}
105105
b'D' => {
106106
let len = buf.read_u16::<BigEndian>()?;
107107
let storage = buf.read_all();
108-
Message::DataRow(DataRowBody {
109-
storage: storage,
110-
len: len,
111-
})
108+
Message::DataRow(DataRowBody { storage, len })
112109
}
113110
b'E' => {
114111
let storage = buf.read_all();
115-
Message::ErrorResponse(ErrorResponseBody { storage: storage })
112+
Message::ErrorResponse(ErrorResponseBody { storage })
116113
}
117114
b'G' => {
118115
let format = buf.read_u8()?;
119116
let len = buf.read_u16::<BigEndian>()?;
120117
let storage = buf.read_all();
121118
Message::CopyInResponse(CopyInResponseBody {
122-
format: format,
123-
len: len,
124-
storage: storage,
119+
format,
120+
len,
121+
storage,
125122
})
126123
}
127124
b'H' => {
128125
let format = buf.read_u8()?;
129126
let len = buf.read_u16::<BigEndian>()?;
130127
let storage = buf.read_all();
131128
Message::CopyOutResponse(CopyOutResponseBody {
132-
format: format,
133-
len: len,
134-
storage: storage,
129+
format,
130+
len,
131+
storage,
135132
})
136133
}
137134
b'I' => Message::EmptyQueryResponse,
138135
b'K' => {
139136
let process_id = buf.read_i32::<BigEndian>()?;
140137
let secret_key = buf.read_i32::<BigEndian>()?;
141138
Message::BackendKeyData(BackendKeyDataBody {
142-
process_id: process_id,
143-
secret_key: secret_key,
139+
process_id,
140+
secret_key,
144141
})
145142
}
146143
b'n' => Message::NoData,
147144
b'N' => {
148145
let storage = buf.read_all();
149-
Message::NoticeResponse(NoticeResponseBody { storage: storage })
146+
Message::NoticeResponse(NoticeResponseBody { storage })
150147
}
151148
b'R' => match buf.read_i32::<BigEndian>()? {
152149
0 => Message::AuthenticationOk,
@@ -155,7 +152,7 @@ impl Message {
155152
5 => {
156153
let mut salt = [0; 4];
157154
buf.read_exact(&mut salt)?;
158-
Message::AuthenticationMd5Password(AuthenticationMd5PasswordBody { salt: salt })
155+
Message::AuthenticationMd5Password(AuthenticationMd5PasswordBody { salt })
159156
}
160157
6 => Message::AuthenticationScmCredential,
161158
7 => Message::AuthenticationGss,
@@ -187,30 +184,21 @@ impl Message {
187184
b'S' => {
188185
let name = buf.read_cstr()?;
189186
let value = buf.read_cstr()?;
190-
Message::ParameterStatus(ParameterStatusBody {
191-
name: name,
192-
value: value,
193-
})
187+
Message::ParameterStatus(ParameterStatusBody { name, value })
194188
}
195189
b't' => {
196190
let len = buf.read_u16::<BigEndian>()?;
197191
let storage = buf.read_all();
198-
Message::ParameterDescription(ParameterDescriptionBody {
199-
storage: storage,
200-
len: len,
201-
})
192+
Message::ParameterDescription(ParameterDescriptionBody { storage, len })
202193
}
203194
b'T' => {
204195
let len = buf.read_u16::<BigEndian>()?;
205196
let storage = buf.read_all();
206-
Message::RowDescription(RowDescriptionBody {
207-
storage: storage,
208-
len: len,
209-
})
197+
Message::RowDescription(RowDescriptionBody { storage, len })
210198
}
211199
b'Z' => {
212200
let status = buf.read_u8()?;
213-
Message::ReadyForQuery(ReadyForQueryBody { status: status })
201+
Message::ReadyForQuery(ReadyForQueryBody { status })
214202
}
215203
tag => {
216204
return Err(io::Error::new(
@@ -305,7 +293,7 @@ pub struct AuthenticationSaslBody(Bytes);
305293

306294
impl AuthenticationSaslBody {
307295
#[inline]
308-
pub fn mechanisms<'a>(&'a self) -> SaslMechanisms<'a> {
296+
pub fn mechanisms(&self) -> SaslMechanisms<'_> {
309297
SaslMechanisms(&self.0)
310298
}
311299
}
@@ -410,7 +398,7 @@ impl CopyInResponseBody {
410398
}
411399

412400
#[inline]
413-
pub fn column_formats<'a>(&'a self) -> ColumnFormats<'a> {
401+
pub fn column_formats(&self) -> ColumnFormats<'_> {
414402
ColumnFormats {
415403
remaining: self.len,
416404
buf: &self.storage,
@@ -464,7 +452,7 @@ impl CopyOutResponseBody {
464452
}
465453

466454
#[inline]
467-
pub fn column_formats<'a>(&'a self) -> ColumnFormats<'a> {
455+
pub fn column_formats(&self) -> ColumnFormats<'_> {
468456
ColumnFormats {
469457
remaining: self.len,
470458
buf: &self.storage,
@@ -479,7 +467,7 @@ pub struct DataRowBody {
479467

480468
impl DataRowBody {
481469
#[inline]
482-
pub fn ranges<'a>(&'a self) -> DataRowRanges<'a> {
470+
pub fn ranges(&self) -> DataRowRanges<'_> {
483471
DataRowRanges {
484472
buf: &self.storage,
485473
len: self.storage.len(),
@@ -547,7 +535,7 @@ pub struct ErrorResponseBody {
547535

548536
impl ErrorResponseBody {
549537
#[inline]
550-
pub fn fields<'a>(&'a self) -> ErrorFields<'a> {
538+
pub fn fields(&self) -> ErrorFields<'_> {
551539
ErrorFields { buf: &self.storage }
552540
}
553541
}
@@ -578,10 +566,7 @@ impl<'a> FallibleIterator for ErrorFields<'a> {
578566
let value = get_str(&self.buf[..value_end])?;
579567
self.buf = &self.buf[value_end + 1..];
580568

581-
Ok(Some(ErrorField {
582-
type_: type_,
583-
value: value,
584-
}))
569+
Ok(Some(ErrorField { type_, value }))
585570
}
586571
}
587572

@@ -608,7 +593,7 @@ pub struct NoticeResponseBody {
608593

609594
impl NoticeResponseBody {
610595
#[inline]
611-
pub fn fields<'a>(&'a self) -> ErrorFields<'a> {
596+
pub fn fields(&self) -> ErrorFields<'_> {
612597
ErrorFields { buf: &self.storage }
613598
}
614599
}
@@ -643,7 +628,7 @@ pub struct ParameterDescriptionBody {
643628

644629
impl ParameterDescriptionBody {
645630
#[inline]
646-
pub fn parameters<'a>(&'a self) -> Parameters<'a> {
631+
pub fn parameters(&self) -> Parameters<'_> {
647632
Parameters {
648633
buf: &self.storage,
649634
remaining: self.len,
@@ -719,7 +704,7 @@ pub struct RowDescriptionBody {
719704

720705
impl RowDescriptionBody {
721706
#[inline]
722-
pub fn fields<'a>(&'a self) -> Fields<'a> {
707+
pub fn fields(&self) -> Fields<'_> {
723708
Fields {
724709
buf: &self.storage,
725710
remaining: self.len,
@@ -761,13 +746,13 @@ impl<'a> FallibleIterator for Fields<'a> {
761746
let format = self.buf.read_i16::<BigEndian>()?;
762747

763748
Ok(Some(Field {
764-
name: name,
765-
table_oid: table_oid,
766-
column_id: column_id,
767-
type_oid: type_oid,
768-
type_size: type_size,
769-
type_modifier: type_modifier,
770-
format: format,
749+
name,
750+
table_oid,
751+
column_id,
752+
type_oid,
753+
type_size,
754+
type_modifier,
755+
format,
771756
}))
772757
}
773758
}

0 commit comments

Comments
 (0)