Skip to content

Commit de1dfa9

Browse files
committed
fix: more clippy warnings in mssql modules
- Fix unit_arg by using () instead of Default::default() - Fix redundant_closure by using function reference directly - Fix while_let_on_iterator by using for loop - Fix explicit_auto_deref in mssql/options/parse.rs - Add allow for result_large_err in requested_packet_size - Fix needless_range_loop by iterating over slice directly - Add allow for ptr_arg where Vec-specific methods are used
1 parent 6df4fdb commit de1dfa9

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

sqlx-core/src/mssql/connection/tls_prelogin_stream_wrapper.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> AsyncRead for TlsPreloginWrapper<
100100

101101
let read = header_buf.filled().len();
102102
if read == 0 {
103-
return Poll::Ready(Ok(Default::default()));
103+
return Poll::Ready(Ok(()));
104104
}
105105

106106
inner.header_pos += read;
107107
}
108108

109109
let header: PacketHeader = Decode::decode(Bytes::copy_from_slice(&inner.header_buf))
110-
.map_err(|err| io::Error::other(err))?;
110+
.map_err(io::Error::other)?;
111111

112112
inner.read_remaining = usize::from(header.length) - HEADER_BYTES;
113113

@@ -153,14 +153,14 @@ impl<S: AsyncRead + AsyncWrite + Unpin + Send> AsyncRead for TlsPreloginWrapper<
153153
let read = ready!(Pin::new(&mut inner.stream).poll_read(cx, header_buf))?;
154154

155155
if read == 0 {
156-
return Poll::Ready(Ok(Default::default()));
156+
return Poll::Ready(Ok(()));
157157
}
158158

159159
inner.header_pos += read;
160160
}
161161

162162
let header: PacketHeader = Decode::decode(Bytes::copy_from_slice(&inner.header_buf))
163-
.map_err(|err| io::Error::other(err))?;
163+
.map_err(io::Error::other)?;
164164

165165
inner.read_remaining = usize::from(header.length) - HEADER_BYTES;
166166

sqlx-core/src/mssql/io/buf_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub trait MssqlBufMutExt {
66
impl MssqlBufMutExt for Vec<u8> {
77
fn put_utf16_str(&mut self, s: &str) {
88
let mut enc = s.encode_utf16();
9-
while let Some(ch) = enc.next() {
9+
for ch in enc {
1010
self.extend_from_slice(&ch.to_le_bytes());
1111
}
1212
}

sqlx-core/src/mssql/options/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl MssqlConnectOptions {
134134

135135
/// Size in bytes of TDS packets to exchange with the server.
136136
/// Returns an error if the size is smaller than 512 bytes
137+
#[allow(clippy::result_large_err)]
137138
pub fn requested_packet_size(mut self, size: u32) -> Result<Self, Self> {
138139
if size < 512 {
139140
Err(self)

sqlx-core/src/mssql/options/parse.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ impl FromStr for MssqlConnectOptions {
6060
let username = url.username();
6161
if !username.is_empty() {
6262
options = options.username(
63-
&*percent_decode_str(username)
63+
&percent_decode_str(username)
6464
.decode_utf8()
6565
.map_err(Error::config)?,
6666
);
6767
}
6868

6969
if let Some(password) = url.password() {
7070
options = options.password(
71-
&*percent_decode_str(password)
71+
&percent_decode_str(password)
7272
.decode_utf8()
7373
.map_err(Error::config)?,
7474
);
@@ -82,7 +82,7 @@ impl FromStr for MssqlConnectOptions {
8282
for (key, value) in url.query_pairs() {
8383
match key.as_ref() {
8484
"instance" => {
85-
options = options.instance(&*value);
85+
options = options.instance(&value);
8686
}
8787
"encrypt" => {
8888
match value.to_lowercase().as_str() {
@@ -104,7 +104,7 @@ impl FromStr for MssqlConnectOptions {
104104
options = options.trust_server_certificate(trust);
105105
}
106106
"hostname_in_certificate" => {
107-
options = options.hostname_in_certificate(&*value);
107+
options = options.hostname_in_certificate(&value);
108108
}
109109
"packet_size" => {
110110
let size = value.parse().map_err(Error::config)?;
@@ -116,11 +116,11 @@ impl FromStr for MssqlConnectOptions {
116116
options = options.client_program_version(value.parse().map_err(Error::config)?)
117117
}
118118
"client_pid" => options = options.client_pid(value.parse().map_err(Error::config)?),
119-
"hostname" => options = options.hostname(&*value),
120-
"app_name" => options = options.app_name(&*value),
121-
"server_name" => options = options.server_name(&*value),
122-
"client_interface_name" => options = options.client_interface_name(&*value),
123-
"language" => options = options.language(&*value),
119+
"hostname" => options = options.hostname(&value),
120+
"app_name" => options = options.app_name(&value),
121+
"server_name" => options = options.server_name(&value),
122+
"client_interface_name" => options = options.client_interface_name(&value),
123+
"language" => options = options.language(&value),
124124
_ => {
125125
return Err(Error::config(MssqlInvalidOption(key.into())));
126126
}

sqlx-core/src/mssql/protocol/login.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ impl Encode<'_> for Login7<'_> {
9797
// password buffer starting with the position pointed to by ibPassword or
9898
// ibChangePassword, the client SHOULD first swap the four high bits with
9999
// the four low bits and then do a bit-XOR with 0xA5 (10100101).
100-
for i in password_start..buf.len() {
101-
let b = buf[i];
102-
buf[i] = ((b << 4) & 0xf0 | (b >> 4) & 0x0f) ^ 0xa5;
100+
for b in &mut buf[password_start..] {
101+
*b = ((*b << 4) & 0xf0 | (*b >> 4) & 0x0f) ^ 0xa5;
103102
}
104103

105104
// [AppName] The client application name
@@ -143,6 +142,7 @@ impl Encode<'_> for Login7<'_> {
143142
}
144143
}
145144

145+
#[allow(clippy::ptr_arg)]
146146
fn write_offset(buf: &mut Vec<u8>, offsets: &mut usize, beg: usize) {
147147
// The offset must be relative to the beginning of the packet payload, after
148148
// the packet header

sqlx-core/src/mssql/protocol/pre_login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ enum PreLoginOptionToken {
195195
}
196196

197197
impl PreLoginOptionToken {
198+
#[allow(clippy::ptr_arg)]
198199
fn put(self, buf: &mut Vec<u8>, pos: &mut usize, offset: &mut u16, len: u16) {
199200
buf[*pos] = self as u8;
200201
*pos += 1;

0 commit comments

Comments
 (0)