Skip to content

Commit 75ed7ae

Browse files
committed
Fix clippy lints
1 parent e4c0bfd commit 75ed7ae

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

src/command_history.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn replay_message(
2828
let mut msg = CustomMessage::new();
2929
msg.id(ev.id)
3030
.channel_id(ev.channel_id)
31-
.content(ev.content.unwrap_or_else(|| String::new()));
31+
.content(ev.content.unwrap_or_else(String::new));
3232

3333
let msg = msg.build();
3434

@@ -49,7 +49,7 @@ pub(crate) fn clear_command_history(cx: &Context) -> Result<(), SendSyncError> {
4949
let history = data.get_mut::<CommandHistory>().unwrap();
5050

5151
// always keep the last command in history
52-
if history.len() > 0 {
52+
if !history.is_empty() {
5353
info!("Clearing command history");
5454
history.drain(..history.len() - 1);
5555
}

src/commands.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use reqwest::blocking::Client as HttpClient;
88
use serenity::{model::channel::Message, prelude::Context};
99
use std::{collections::HashMap, sync::Arc};
1010

11-
pub(crate) const PREFIX: &'static str = "?";
11+
pub(crate) const PREFIX: &str = "?";
1212
pub(crate) type GuardFn = fn(&Args) -> Result<bool, Error>;
1313

1414
struct Command {
1515
guard: GuardFn,
16-
ptr: Box<dyn for<'m> Fn(Args<'m>) -> Result<(), Error> + Send + Sync>,
16+
ptr: Box<dyn Fn(Args<'_>) -> Result<(), Error> + Send + Sync>,
1717
}
1818

1919
impl Command {
@@ -70,7 +70,7 @@ impl Commands {
7070

7171
command
7272
.split(' ')
73-
.filter(|segment| segment.len() > 0)
73+
.filter(|segment| !segment.is_empty())
7474
.enumerate()
7575
.for_each(|(i, segment)| {
7676
if let Some(name) = key_value_pair(segment) {
@@ -96,9 +96,9 @@ impl Commands {
9696
state = self.add_code_segment_multi_line(state, segment);
9797
} else if segment.starts_with("```") && segment.ends_with("```") {
9898
state = self.add_code_segment_single_line(state, 3, segment);
99-
} else if segment.starts_with("`") && segment.ends_with("`") {
99+
} else if segment.starts_with('`') && segment.ends_with('`') {
100100
state = self.add_code_segment_single_line(state, 1, segment);
101-
} else if segment.starts_with("{") && segment.ends_with("}") {
101+
} else if segment.starts_with('{') && segment.ends_with('}') {
102102
state = self.add_dynamic_segment(state, segment);
103103
} else if segment.ends_with("...") {
104104
state = self.add_remaining_segment(state, segment);
@@ -122,7 +122,7 @@ impl Commands {
122122
});
123123
} else {
124124
self.state_machine.set_final_state(state);
125-
self.state_machine.set_handler(state, handler.clone());
125+
self.state_machine.set_handler(state, handler);
126126
}
127127
}
128128

@@ -169,7 +169,7 @@ impl Commands {
169169
pub(crate) fn execute<'m>(&'m self, cx: Context, msg: &Message) {
170170
let message = &msg.content;
171171
if !msg.is_own(&cx) && message.starts_with(PREFIX) {
172-
self.state_machine.process(message).map(|matched| {
172+
if let Some(matched) = self.state_machine.process(message) {
173173
info!("Processing command: {}", message);
174174
let args = Args {
175175
http: &self.client,
@@ -195,7 +195,7 @@ impl Commands {
195195
}
196196
Err(e) => error!("{}", e),
197197
}
198-
});
198+
};
199199
}
200200
}
201201

@@ -323,10 +323,10 @@ impl Commands {
323323

324324
fn key_value_pair(s: &'static str) -> Option<&'static str> {
325325
s.match_indices("={}")
326-
.nth(0)
326+
.next()
327327
.map(|pair| {
328328
let name = &s[0..pair.0];
329-
if name.len() > 0 {
329+
if !name.is_empty() {
330330
Some(name)
331331
} else {
332332
None

src/crates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn get_crate(args: &Args) -> Result<Option<Crate>, Error> {
3939
.send()?
4040
.json::<Crates>()?;
4141

42-
Ok(crate_list.crates.into_iter().nth(0))
42+
Ok(crate_list.crates.into_iter().next())
4343
}
4444

4545
pub fn search(args: Args) -> Result<(), Error> {

src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ mod welcome;
2424
use crate::db::DB;
2525
use commands::{Args, Commands, GuardFn};
2626
use diesel::prelude::*;
27-
use envy;
2827
use indexmap::IndexMap;
2928
use serde::Deserialize;
3029
use serenity::{model::prelude::*, prelude::*};
@@ -203,16 +202,15 @@ fn app() -> Result<(), Error> {
203202
}
204203

205204
fn main_menu(args: &Args, commands: &IndexMap<&str, (&str, GuardFn)>) -> String {
206-
let mut menu = format!("Commands:\n");
207-
208-
menu = commands
209-
.iter()
210-
.fold(menu, |mut menu, (base_cmd, (description, guard))| {
205+
let mut menu = commands.iter().fold(
206+
"Commands:\n".to_owned(),
207+
|mut menu, (base_cmd, (description, guard))| {
211208
if let Ok(true) = (guard)(&args) {
212209
menu += &format!("\t{cmd:<12}{desc}\n", cmd = base_cmd, desc = description);
213210
}
214211
menu
215-
});
212+
},
213+
);
216214

217215
menu += &format!("\t{help:<12}This menu\n", help = "?help");
218216
menu += "\nType ?help command for more info on a command.";

src/playground.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn run_code(args: &Args, code: &str) -> Result<String, Error> {
185185
errors,
186186
get_playground_link(args, code, &request)?
187187
)
188-
} else if result.len() == 0 {
188+
} else if result.is_empty() {
189189
format!("{}compilation succeeded.", errors)
190190
} else {
191191
format!("{}```\n{}```", errors, result)

src/state_machine.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ impl CharacterSet {
3434
match val {
3535
0..=63 => {
3636
let bit = 1 << val;
37-
self.low_mask = self.low_mask | bit;
37+
self.low_mask |= bit;
3838
}
3939
64..=127 => {
40-
let bit = 1 << val - 64;
41-
self.high_mask = self.high_mask | bit;
40+
let bit = 1 << (val - 64);
41+
self.high_mask |= bit;
4242
}
4343
_ => {}
4444
}
@@ -51,11 +51,11 @@ impl CharacterSet {
5151
match val {
5252
0..=63 => {
5353
let bit = 1 << val;
54-
self.low_mask = self.low_mask & !bit;
54+
self.low_mask &= !bit;
5555
}
5656
64..=127 => {
57-
let bit = 1 << val - 64;
58-
self.high_mask = self.high_mask & !bit;
57+
let bit = 1 << (val - 64);
58+
self.high_mask &= !bit;
5959
}
6060
_ => {}
6161
}
@@ -72,7 +72,7 @@ impl CharacterSet {
7272
}
7373
64..=127 => {
7474
// flip a bit within 0 - 63
75-
let bit = 1 << val - 64;
75+
let bit = 1 << (val - 64);
7676
self.high_mask & bit != 0
7777
}
7878
_ => self.any,

src/text.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub(crate) const WELCOME_BILLBOARD: &'static str = "By participating in this community, you agree to follow the Rust Code of Conduct, as linked below. Please click the :white_check_mark: below to acknowledge and gain access to the channels.
1+
pub(crate) const WELCOME_BILLBOARD: &str = "By participating in this community, you agree to follow the Rust Code of Conduct, as linked below. Please click the :white_check_mark: below to acknowledge and gain access to the channels.
22
33
https://www.rust-lang.org/policies/code-of-conduct
44
@@ -8,4 +8,4 @@ pub(crate) fn ban_message(reason: &str, hours: u64) -> String {
88
format!("You have been banned from The Rust Programming Language discord server for {}. The ban will expire in {} hours. If you feel this action was taken unfairly, you can reach the Rust moderation team at [email protected]", reason, hours)
99
}
1010

11-
pub(crate) const WG_AND_TEAMS_MISSING_ENV_VAR: &'static str = "missing value for field wg_and_teams_id.\n\nIf you enabled tags or crates then you need the WG_AND_TEAMS_ID env var.";
11+
pub(crate) const WG_AND_TEAMS_MISSING_ENV_VAR: &str = "missing value for field wg_and_teams_id.\n\nIf you enabled tags or crates then you need the WG_AND_TEAMS_ID env var.";

0 commit comments

Comments
 (0)