Skip to content

Commit cf1cfd4

Browse files
authored
minor: bump clippy to 1.88 (#1442)
1 parent c95787f commit cf1cfd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+437
-688
lines changed

.evergreen/check-clippy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -o errexit
55
source ./.evergreen/env.sh
66

77
# Pin clippy to the latest version. This should be updated when new versions of Rust are released.
8-
CLIPPY_VERSION=1.85.0
8+
CLIPPY_VERSION=1.88.0
99

1010
rustup install $CLIPPY_VERSION
1111

src/action/insert_one.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<T: Serialize + Send + Sync> crate::sync::Collection<T> {
6060
}
6161
}
6262

63-
/// Inserts a document into a collection. Construct with ['Collection::insert_one`].
63+
/// Inserts a document into a collection. Construct with [`Collection::insert_one`].
6464
#[must_use]
6565
pub struct InsertOne<'a> {
6666
coll: CollRef<'a>,

src/action/search_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a> Action for CreateSearchIndex<'a, Single> {
204204
.await?;
205205
match names.len() {
206206
1 => Ok(names.pop().unwrap()),
207-
n => Err(Error::internal(format!("expected 1 index name, got {}", n))),
207+
n => Err(Error::internal(format!("expected 1 index name, got {n}"))),
208208
}
209209
}
210210
}

src/bson_util.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ pub(crate) fn extend_raw_document_buf(
196196
for result in other.iter() {
197197
let (k, v) = result?;
198198
if keys.contains(k) {
199-
return Err(Error::internal(format!(
200-
"duplicate raw document key {:?}",
201-
k
202-
)));
199+
return Err(Error::internal(format!("duplicate raw document key {k:?}")));
203200
}
204201
this.append(k, v.to_raw_bson());
205202
}

src/checked.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<T> Checked<T> {
4343
value
4444
.try_into()
4545
.map(|v| Self(Some(v)))
46-
.map_err(|e| crate::error::Error::invalid_argument(format! {"{}", e}))
46+
.map_err(|e| crate::error::Error::invalid_argument(format! {"{e}"}))
4747
}
4848

4949
pub fn get(self) -> crate::error::Result<T> {
@@ -58,7 +58,7 @@ impl<T> Checked<T> {
5858
{
5959
self.get().and_then(|v| {
6060
v.try_into()
61-
.map_err(|e| crate::error::Error::invalid_argument(format!("{}", e)))
61+
.map_err(|e| crate::error::Error::invalid_argument(format!("{e}")))
6262
})
6363
}
6464
}

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl Client {
556556
state
557557
.servers()
558558
.keys()
559-
.map(|stream_address| format!("{}", stream_address))
559+
.map(|stream_address| format!("{stream_address}"))
560560
.collect()
561561
}
562562

src/client/auth.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,24 +350,21 @@ impl AuthMechanism {
350350
| AuthMechanism::Plain
351351
| AuthMechanism::MongoDbCr => Err(ErrorKind::Authentication {
352352
message: format!(
353-
"Reauthentication for authentication mechanism {:?} is not supported.",
354-
self
353+
"Reauthentication for authentication mechanism {self:?} is not supported."
355354
),
356355
}
357356
.into()),
358357
#[cfg(feature = "gssapi-auth")]
359358
AuthMechanism::Gssapi => Err(ErrorKind::Authentication {
360359
message: format!(
361-
"Reauthentication for authentication mechanism {:?} is not supported.",
362-
self
360+
"Reauthentication for authentication mechanism {self:?} is not supported."
363361
),
364362
}
365363
.into()),
366364
#[cfg(feature = "aws-auth")]
367365
AuthMechanism::MongoDbAws => Err(ErrorKind::Authentication {
368366
message: format!(
369-
"Reauthentication for authentication mechanism {:?} is not supported.",
370-
self
367+
"Reauthentication for authentication mechanism {self:?} is not supported."
371368
),
372369
}
373370
.into()),
@@ -407,7 +404,7 @@ impl FromStr for AuthMechanism {
407404
.into()),
408405

409406
_ => Err(ErrorKind::InvalidArgument {
410-
message: format!("invalid mechanism string: {}", str),
407+
message: format!("invalid mechanism string: {str}"),
411408
}
412409
.into()),
413410
}

src/client/auth/aws.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl AwsCredential {
352352
/// Obtains credentials from the ECS endpoint.
353353
async fn get_from_ecs(relative_uri: String, http_client: &HttpClient) -> Result<Self> {
354354
// Use the local IP address that AWS uses for ECS agents.
355-
let uri = format!("http://{}/{}", AWS_ECS_IP, relative_uri);
355+
let uri = format!("http://{AWS_ECS_IP}/{relative_uri}");
356356

357357
http_client
358358
.get(&uri)
@@ -364,16 +364,14 @@ impl AwsCredential {
364364
/// Obtains temporary credentials for an EC2 instance to use for authentication.
365365
async fn get_from_ec2(http_client: &HttpClient) -> Result<Self> {
366366
let temporary_token = http_client
367-
.put(format!("http://{}/latest/api/token", AWS_EC2_IP))
367+
.put(format!("http://{AWS_EC2_IP}/latest/api/token"))
368368
.headers(&[("X-aws-ec2-metadata-token-ttl-seconds", "30")])
369369
.send_and_get_string()
370370
.await
371371
.map_err(|_| Error::unknown_authentication_error(MECH_NAME))?;
372372

373-
let role_name_uri = format!(
374-
"http://{}/latest/meta-data/iam/security-credentials/",
375-
AWS_EC2_IP
376-
);
373+
let role_name_uri =
374+
format!("http://{AWS_EC2_IP}/latest/meta-data/iam/security-credentials/");
377375

378376
let role_name = http_client
379377
.get(&role_name_uri)
@@ -382,7 +380,7 @@ impl AwsCredential {
382380
.await
383381
.map_err(|_| Error::unknown_authentication_error(MECH_NAME))?;
384382

385-
let credential_uri = format!("{}/{}", role_name_uri, role_name);
383+
let credential_uri = format!("{role_name_uri}/{role_name}");
386384

387385
http_client
388386
.get(&credential_uri)
@@ -407,7 +405,7 @@ impl AwsCredential {
407405
let token = self
408406
.session_token
409407
.as_ref()
410-
.map(|s| format!("x-amz-security-token:{}\n", s))
408+
.map(|s| format!("x-amz-security-token:{s}\n"))
411409
.unwrap_or_default();
412410

413411
// Similarly, we need to put "x-amz-security-token" into the list of signed headers if the
@@ -430,7 +428,6 @@ impl AwsCredential {
430428
x-mongodb-gs2-cb-flag;\
431429
x-mongodb-server-nonce\
432430
",
433-
token_signed_header = token_signed_header,
434431
);
435432

436433
let body = "Action=GetCallerIdentity&Version=2011-06-15";
@@ -446,19 +443,13 @@ impl AwsCredential {
446443
content-length:43\n\
447444
content-type:application/x-www-form-urlencoded\n\
448445
host:{host}\n\
449-
x-amz-date:{date}\n\
446+
x-amz-date:{date_str}\n\
450447
{token}\
451448
x-mongodb-gs2-cb-flag:n\n\
452449
x-mongodb-server-nonce:{nonce}\n\n\
453450
{signed_headers}\n\
454451
{hashed_body}\
455452
",
456-
host = host,
457-
date = date_str,
458-
token = token,
459-
nonce = nonce,
460-
signed_headers = signed_headers,
461-
hashed_body = hashed_body,
462453
);
463454

464455
let hashed_request = hex::encode(Sha256::digest(request.as_bytes()));
@@ -476,14 +467,10 @@ impl AwsCredential {
476467
let string_to_sign = format!(
477468
"\
478469
AWS4-HMAC-SHA256\n\
479-
{full_date}\n\
470+
{date_str}\n\
480471
{small_date}/{region}/sts/aws4_request\n\
481472
{hashed_request}\
482473
",
483-
full_date = date_str,
484-
small_date = small_date,
485-
region = region,
486-
hashed_request = hashed_request,
487474
);
488475

489476
let first_hmac_key = format!("AWS4{}", self.secret_access_key);

src/client/auth/oidc.rs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ impl Callback {
163163
let resource = resource.to_string();
164164
let client_id = client_id.map(|s| s.to_string());
165165
let mut url = format!(
166-
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={}",
167-
resource
166+
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={resource}"
168167
);
169168
if let Some(ref client_id) = client_id {
170-
url.push_str(&format!("&client_id={}", client_id));
169+
url.push_str(&format!("&client_id={client_id}"));
171170
}
172171
Self::new_function(
173172
move |_| {
@@ -182,7 +181,7 @@ impl Callback {
182181
.map_err(|e| {
183182
Error::authentication_error(
184183
MONGODB_OIDC_STR,
185-
&format!("Failed to get access token from Azure IDMS: {}", e),
184+
&format!("Failed to get access token from Azure IDMS: {e}"),
186185
)
187186
});
188187
let response = response?;
@@ -191,7 +190,7 @@ impl Callback {
191190
.map_err(|e| {
192191
Error::authentication_error(
193192
MONGODB_OIDC_STR,
194-
&format!("Failed to get access token from Azure IDMS: {}", e),
193+
&format!("Failed to get access token from Azure IDMS: {e}"),
195194
)
196195
})?
197196
.to_string();
@@ -200,17 +199,14 @@ impl Callback {
200199
.map_err(|e| {
201200
Error::authentication_error(
202201
MONGODB_OIDC_STR,
203-
&format!("Failed to get expires_in from Azure IDMS: {}", e),
202+
&format!("Failed to get expires_in from Azure IDMS: {e}"),
204203
)
205204
})?
206205
.parse::<u64>()
207206
.map_err(|e| {
208207
Error::authentication_error(
209208
MONGODB_OIDC_STR,
210-
&format!(
211-
"Failed to parse expires_in from Azure IDMS as u64: {}",
212-
e
213-
),
209+
&format!("Failed to parse expires_in from Azure IDMS as u64: {e}"),
214210
)
215211
})?;
216212
let expires = Some(Instant::now() + Duration::from_secs(expires_in));
@@ -231,8 +227,7 @@ impl Callback {
231227
fn gcp_callback(resource: &str) -> Function {
232228
use futures_util::FutureExt;
233229
let url = format!(
234-
"http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience={}",
235-
resource
230+
"http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience={resource}"
236231
);
237232
Self::new_function(
238233
move |_| {
@@ -247,7 +242,7 @@ impl Callback {
247242
.map_err(|e| {
248243
Error::authentication_error(
249244
MONGODB_OIDC_STR,
250-
&format!("Failed to get access token from GCP IDMS: {}", e),
245+
&format!("Failed to get access token from GCP IDMS: {e}"),
251246
)
252247
});
253248
let access_token = response?;
@@ -732,8 +727,7 @@ fn get_allowed_hosts(mechanism_properties: Option<&Document>) -> Result<Vec<&str
732727
.map(|host| {
733728
host.as_str().ok_or_else(|| {
734729
auth_error(format!(
735-
"`{}` must contain only strings",
736-
ALLOWED_HOSTS_PROP_STR
730+
"`{ALLOWED_HOSTS_PROP_STR}` must contain only strings"
737731
))
738732
})
739733
})
@@ -928,41 +922,34 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> {
928922
for k in properties.keys() {
929923
if VALID_PROPERTIES.iter().all(|p| *p != k) {
930924
return Err(Error::invalid_argument(format!(
931-
"'{}' is not a valid property for {} authentication",
932-
k, MONGODB_OIDC_STR,
925+
"'{k}' is not a valid property for {MONGODB_OIDC_STR} authentication",
933926
)));
934927
}
935928
}
936929
let environment = properties.get_str(ENVIRONMENT_PROP_STR);
937930
if environment.is_ok() && credential.oidc_callback.is_user_provided() {
938931
return Err(Error::invalid_argument(format!(
939-
"OIDC callback cannot be set for {} authentication, if an `{}` is set",
940-
MONGODB_OIDC_STR, ENVIRONMENT_PROP_STR
932+
"OIDC callback cannot be set for {MONGODB_OIDC_STR} authentication, if an \
933+
`{ENVIRONMENT_PROP_STR}` is set"
941934
)));
942935
}
943936
let has_token_resource = properties.contains_key(TOKEN_RESOURCE_PROP_STR);
944937
match environment {
945938
Ok(AZURE_ENVIRONMENT_VALUE_STR) | Ok(GCP_ENVIRONMENT_VALUE_STR) => {
946939
if !has_token_resource {
947940
return Err(Error::invalid_argument(format!(
948-
"`{}` must be set for {} authentication in the `{}` or `{}` `{}`",
949-
TOKEN_RESOURCE_PROP_STR,
950-
MONGODB_OIDC_STR,
951-
AZURE_ENVIRONMENT_VALUE_STR,
952-
GCP_ENVIRONMENT_VALUE_STR,
953-
ENVIRONMENT_PROP_STR,
941+
"`{TOKEN_RESOURCE_PROP_STR}` must be set for {MONGODB_OIDC_STR} \
942+
authentication in the `{AZURE_ENVIRONMENT_VALUE_STR}` or \
943+
`{GCP_ENVIRONMENT_VALUE_STR}` `{ENVIRONMENT_PROP_STR}`",
954944
)));
955945
}
956946
}
957947
_ => {
958948
if has_token_resource {
959949
return Err(Error::invalid_argument(format!(
960-
"`{}` must not be set for {} authentication unless using the `{}` or `{}` `{}`",
961-
TOKEN_RESOURCE_PROP_STR,
962-
MONGODB_OIDC_STR,
963-
AZURE_ENVIRONMENT_VALUE_STR,
964-
GCP_ENVIRONMENT_VALUE_STR,
965-
ENVIRONMENT_PROP_STR,
950+
"`{TOKEN_RESOURCE_PROP_STR}` must not be set for {MONGODB_OIDC_STR} \
951+
authentication unless using the `{AZURE_ENVIRONMENT_VALUE_STR}` or \
952+
`{GCP_ENVIRONMENT_VALUE_STR}` `{ENVIRONMENT_PROP_STR}`",
966953
)));
967954
}
968955
}
@@ -983,27 +970,25 @@ pub(super) fn validate_credential(credential: &Credential) -> Result<()> {
983970
&& credential.username.is_some()
984971
{
985972
return Err(Error::invalid_argument(format!(
986-
"username must not be set for {} authentication in the {} {}",
987-
MONGODB_OIDC_STR, TEST_ENVIRONMENT_VALUE_STR, ENVIRONMENT_PROP_STR,
973+
"username must not be set for {MONGODB_OIDC_STR} authentication in the \
974+
{TEST_ENVIRONMENT_VALUE_STR} {ENVIRONMENT_PROP_STR}",
988975
)));
989976
}
990977
if credential.password.is_some() {
991978
return Err(Error::invalid_argument(format!(
992-
"password must not be set for {} authentication",
993-
MONGODB_OIDC_STR
979+
"password must not be set for {MONGODB_OIDC_STR} authentication"
994980
)));
995981
}
996982
if let Ok(env) = environment {
997983
if VALID_ENVIRONMENTS.iter().all(|e| *e != env) {
998984
return Err(Error::invalid_argument(format!(
999-
"unsupported environment for {} authentication: {}",
1000-
MONGODB_OIDC_STR, env,
985+
"unsupported environment for {MONGODB_OIDC_STR} authentication: {env}",
1001986
)));
1002987
}
1003988
}
1004989
if let Some(allowed_hosts) = properties.get(ALLOWED_HOSTS_PROP_STR) {
1005990
allowed_hosts.as_array().ok_or_else(|| {
1006-
Error::invalid_argument(format!("`{}` must be an array", ALLOWED_HOSTS_PROP_STR))
991+
Error::invalid_argument(format!("`{ALLOWED_HOSTS_PROP_STR}` must be an array"))
1007992
})?;
1008993
}
1009994
Ok(())

src/client/auth/scram.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl ScramVersion {
319319
ScramVersion::Sha1 => {
320320
// nosemgrep: insecure-hashes
321321
let mut md5 = Md5::new(); // mongodb rating: No Fix Needed
322-
md5.update(format!("{}:mongo:{}", username, password));
322+
md5.update(format!("{username}:mongo:{password}"));
323323
Cow::Owned(hex::encode(md5.finalize()))
324324
}
325325
ScramVersion::Sha256 => match stringprep::saslprep(password) {
@@ -415,8 +415,8 @@ pub(crate) struct ClientFirst {
415415
impl ClientFirst {
416416
fn new(source: &str, username: &str, include_db: bool, server_api: Option<ServerApi>) -> Self {
417417
let nonce = auth::generate_nonce();
418-
let gs2_header = format!("{},,", NO_CHANNEL_BINDING);
419-
let bare = format!("{}={},{}={}", USERNAME_KEY, username, NONCE_KEY, nonce);
418+
let gs2_header = format!("{NO_CHANNEL_BINDING},,");
419+
let bare = format!("{USERNAME_KEY}={username},{NONCE_KEY}={nonce}");
420420
let full = format!("{}{}", &gs2_header, &bare);
421421
let end = full.len();
422422
ClientFirst {
@@ -602,7 +602,7 @@ impl ClientFinal {
602602
let client_proof =
603603
base64::encode(xor(client_key.as_ref(), client_signature.as_ref()).as_slice());
604604

605-
let message = format!("{},{}={}", without_proof, PROOF_KEY, client_proof);
605+
let message = format!("{without_proof},{PROOF_KEY}={client_proof}");
606606

607607
Ok(ClientFinal {
608608
source: source.into(),

0 commit comments

Comments
 (0)