Skip to content

Commit 9108d28

Browse files
authored
Fix clippy warnings from clippy::unwrap_used (#3367)
1 parent 92776b0 commit 9108d28

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
env:
66
rust_min: 1.74.0
7-
rust_nightly: nightly-2024-03-09
7+
rust_nightly: nightly-2025-05-18
88

99
jobs:
1010
test:
@@ -162,6 +162,11 @@ jobs:
162162
- name: Cache
163163
uses: Swatinem/rust-cache@v2
164164

165+
- name: Pin problematic dependencies to working versions
166+
run: |
167+
cargo update idna_adapter --precise 1.1.0
168+
cargo update triomphe --precise 0.1.11
169+
165170
- name: Check
166171
run: cargo check --features full
167172

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ edition = "2021"
2727
rust-version = "1.74"
2828

2929
[dependencies]
30-
#!! Downgrade to versions still supporting v1.74.0
31-
#!! Make sure to remove on `next`
32-
litemap = "=0.7.4"
33-
zerofrom = "=0.1.5"
34-
3530
# Required dependencies
3631
bitflags = "2.4.2"
3732
serde_json = "1.0.108"

src/framework/standard/help_commands.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,8 @@ fn flatten_group_to_plain_string(
959959
let repeated_indent_str = help_options.indention_prefix.repeat(nest_level);
960960

961961
if nest_level > 0 {
962-
write!(group_text, "\n{repeated_indent_str}**{}**", group.name).unwrap();
962+
write!(group_text, "\n{repeated_indent_str}**{}**", group.name)
963+
.expect("writing to a string should never fail");
963964
}
964965

965966
if group.prefixes.is_empty() {
@@ -970,7 +971,7 @@ fn flatten_group_to_plain_string(
970971
" ({}: `{}`): ",
971972
help_options.group_prefix,
972973
group.prefixes.join("`, `"),
973-
).unwrap();
974+
).expect("writing to a string should never fail");
974975
}
975976

976977
let joined_commands = group.command_names.join(", ");
@@ -1232,7 +1233,7 @@ fn grouped_commands_to_plain_string(
12321233
result.push('\n');
12331234

12341235
for group in groups {
1235-
write!(result, "\n**{}**", &group.name).unwrap();
1236+
write!(result, "\n**{}**", &group.name).expect("writing to a string should never fail");
12361237

12371238
flatten_group_to_plain_string(&mut result, group, 0, help_options);
12381239
}
@@ -1245,15 +1246,16 @@ fn grouped_commands_to_plain_string(
12451246
fn single_command_to_plain_string(help_options: &HelpOptions, command: &Command<'_>) -> String {
12461247
let mut result = String::new();
12471248

1248-
writeln!(result, "__**{}**__", command.name).unwrap();
1249+
writeln!(result, "__**{}**__", command.name).expect("writing to a string should never fail");
12491250

12501251
if !command.aliases.is_empty() {
12511252
write!(result, "**{}**: `{}`", help_options.aliases_label, command.aliases.join("`, `"))
1252-
.unwrap();
1253+
.expect("writing to a string should never fail");
12531254
}
12541255

12551256
if let Some(description) = command.description {
1256-
writeln!(result, "**{}**: {description}", help_options.description_label).unwrap();
1257+
writeln!(result, "**{}**: {description}", help_options.description_label)
1258+
.expect("writing to a string should never fail");
12571259
}
12581260

12591261
if let Some(usage) = command.usage {
@@ -1263,10 +1265,10 @@ fn single_command_to_plain_string(help_options: &HelpOptions, command: &Command<
12631265
"**{}**: `{first_prefix} {} {usage}`",
12641266
help_options.usage_label, command.name
12651267
)
1266-
.unwrap();
1268+
.expect("writing to a string should never fail");
12671269
} else {
12681270
writeln!(result, "**{}**: `{} {usage}`", help_options.usage_label, command.name)
1269-
.unwrap();
1271+
.expect("writing to a string should never fail");
12701272
}
12711273
}
12721274

@@ -1278,7 +1280,7 @@ fn single_command_to_plain_string(help_options: &HelpOptions, command: &Command<
12781280
"**{}**: `{first_prefix} {} {example}`",
12791281
help_options.usage_sample_label, command.name
12801282
)
1281-
.unwrap();
1283+
.expect("writing to a string should never fail");
12821284
};
12831285
command.usage_sample.iter().for_each(format_example);
12841286
} else {
@@ -1288,16 +1290,18 @@ fn single_command_to_plain_string(help_options: &HelpOptions, command: &Command<
12881290
"**{}**: `{} {example}`",
12891291
help_options.usage_sample_label, command.name
12901292
)
1291-
.unwrap();
1293+
.expect("writing to a string should never fail");
12921294
};
12931295
command.usage_sample.iter().for_each(format_example);
12941296
}
12951297
}
12961298

1297-
writeln!(result, "**{}**: {}", help_options.grouped_label, command.group_name).unwrap();
1299+
writeln!(result, "**{}**: {}", help_options.grouped_label, command.group_name)
1300+
.expect("writing to a string should never fail");
12981301

12991302
if !help_options.available_text.is_empty() && !command.availability.is_empty() {
1300-
writeln!(result, "**{}**: {}", help_options.available_text, command.availability).unwrap();
1303+
writeln!(result, "**{}**: {}", help_options.available_text, command.availability)
1304+
.expect("writing to a string should never fail");
13011305
}
13021306

13031307
if !command.sub_commands.is_empty() {
@@ -1307,7 +1311,7 @@ fn single_command_to_plain_string(help_options: &HelpOptions, command: &Command<
13071311
help_options.sub_commands_label,
13081312
command.sub_commands.join("`, `"),
13091313
)
1310-
.unwrap();
1314+
.expect("writing to a string should never fail");
13111315
}
13121316

13131317
result
@@ -1385,8 +1389,7 @@ pub async fn plain(
13851389
msg.channel_id.say(&ctx, result).await
13861390
}
13871391

1388-
#[cfg(test)]
1389-
#[cfg(all(feature = "cache", feature = "http"))]
1392+
#[cfg(all(test, feature = "cache", feature = "http"))]
13901393
mod tests {
13911394
use super::{SuggestedCommandName, Suggestions};
13921395

src/http/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'a> Request<'a> {
8080
if let Some(params) = self.params {
8181
path += "?";
8282
for (param, value) in params {
83-
write!(path, "&{param}={value}").unwrap();
83+
write!(path, "&{param}={value}").expect("writing to a string should never fail");
8484
}
8585
}
8686

src/model/channel/message.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ impl Message {
420420
at_distinct.push_str(&u.name);
421421
if let Some(discriminator) = u.discriminator {
422422
at_distinct.push('#');
423-
write!(at_distinct, "{:04}", discriminator.get()).unwrap();
423+
write!(at_distinct, "{:04}", discriminator.get())
424+
.expect("writing to a string should never fail");
424425
}
425426

426427
let mut m = u.mention().to_string();

src/model/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ fn tag(name: &str, discriminator: Option<NonZeroU16>) -> String {
830830
tag.push_str(name);
831831
if let Some(discriminator) = discriminator {
832832
tag.push('#');
833-
write!(tag, "{discriminator:04}").unwrap();
833+
write!(tag, "{discriminator:04}").expect("writing to a string should never fail");
834834
}
835835
tag
836836
}

src/utils/message_builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl MessageBuilder {
187187

188188
#[inline]
189189
fn push_<C: std::fmt::Display + ?Sized>(&mut self, content: &C) -> &mut Self {
190-
write!(self.0, "{content}").unwrap();
190+
write!(self.0, "{content}").expect("writing to a string should never fail");
191191

192192
self
193193
}
@@ -931,7 +931,8 @@ pub trait EmbedMessageBuilding {
931931

932932
impl EmbedMessageBuilding for MessageBuilder {
933933
fn push_named_link(&mut self, name: impl Into<Content>, url: impl Into<Content>) -> &mut Self {
934-
write!(self.0, "[{}]({})", name.into(), url.into()).unwrap();
934+
write!(self.0, "[{}]({})", name.into(), url.into())
935+
.expect("writing to a string should never fail");
935936

936937
self
937938
}

0 commit comments

Comments
 (0)