Skip to content

Commit cdb75ee

Browse files
authored
Merge pull request #79 from rust-lang/linting-mostly
Apply some clippy lints
2 parents e4c0bfd + 055e8fc commit cdb75ee

File tree

7 files changed

+43
-39
lines changed

7 files changed

+43
-39
lines changed

src/command_history.rs

Lines changed: 1 addition & 1 deletion
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_default());
3232

3333
let msg = msg.build();
3434

src/commands.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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 {
@@ -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

@@ -166,7 +166,7 @@ impl Commands {
166166
self.menu.take()
167167
}
168168

169-
pub(crate) fn execute<'m>(&'m self, cx: Context, msg: &Message) {
169+
pub(crate) fn execute(&self, cx: Context, msg: &Message) {
170170
let message = &msg.content;
171171
if !msg.is_own(&cx) && message.starts_with(PREFIX) {
172172
self.state_machine.process(message).map(|matched| {
@@ -201,8 +201,7 @@ impl Commands {
201201

202202
fn add_space(&mut self, mut state: usize, i: usize) -> usize {
203203
if i > 0 {
204-
let mut char_set = CharacterSet::from_char(' ');
205-
char_set.insert('\n');
204+
let char_set = CharacterSet::from_chars(&[' ', '\n']);
206205

207206
state = self.state_machine.add(state, char_set);
208207
self.state_machine.add_next_state(state, state);
@@ -226,7 +225,7 @@ impl Commands {
226225
let name = &s[1..s.len() - 1];
227226

228227
let mut char_set = CharacterSet::any();
229-
char_set.remove(' ');
228+
char_set.remove(&[' ']);
230229
state = self.state_machine.add(state, char_set);
231230
self.state_machine.add_next_state(state, state);
232231
self.state_machine.start_parse(state, name);
@@ -257,9 +256,7 @@ impl Commands {
257256
let lambda = state;
258257

259258
let mut char_set = CharacterSet::any();
260-
char_set.remove('`');
261-
char_set.remove(' ');
262-
char_set.remove('\n');
259+
char_set.remove(&['`', ' ', '\n']);
263260
state = self.state_machine.add(state, char_set);
264261
self.state_machine.add_next_state(state, state);
265262

@@ -310,8 +307,7 @@ impl Commands {
310307
state = self.state_machine.add(state, CharacterSet::from_char('='));
311308

312309
let mut char_set = CharacterSet::any();
313-
char_set.remove(' ');
314-
char_set.remove('\n');
310+
char_set.remove(&[' ', '\n']);
315311
state = self.state_machine.add(state, char_set);
316312
self.state_machine.add_next_state(state, state);
317313
self.state_machine.start_parse(state, name);
@@ -323,7 +319,7 @@ impl Commands {
323319

324320
fn key_value_pair(s: &'static str) -> Option<&'static str> {
325321
s.match_indices("={}")
326-
.nth(0)
322+
.next()
327323
.map(|pair| {
328324
let name = &s[0..pair.0];
329325
if name.len() > 0 {

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: 1 addition & 2 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::*};
@@ -73,7 +72,7 @@ fn init_data(config: &Config) -> Result<(), Error> {
7372
let wg_and_teams_role = config
7473
.wg_and_teams_id
7574
.as_ref()
76-
.ok_or_else(|| text::WG_AND_TEAMS_MISSING_ENV_VAR)?;
75+
.ok_or(text::WG_AND_TEAMS_MISSING_ENV_VAR)?;
7776
upsert_role("wg_and_teams", &wg_and_teams_role)?;
7877
}
7978

src/playground.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ struct PlayResult {
134134
fn run_code(args: &Args, code: &str) -> Result<String, Error> {
135135
let mut errors = String::new();
136136

137-
let warnings = args.params.get("warn").unwrap_or_else(|| &"false");
138-
let channel = args.params.get("channel").unwrap_or_else(|| &"nightly");
139-
let mode = args.params.get("mode").unwrap_or_else(|| &"debug");
140-
let edition = args.params.get("edition").unwrap_or_else(|| &"2018");
137+
let warnings = args.params.get("warn").unwrap_or(&"false");
138+
let channel = args.params.get("channel").unwrap_or(&"nightly");
139+
let mode = args.params.get("mode").unwrap_or(&"debug");
140+
let edition = args.params.get("edition").unwrap_or(&"2018");
141141

142142
let mut request = PlaygroundCode::new(code);
143143

src/state_machine.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,33 @@ 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 => {
4040
let bit = 1 << val - 64;
41-
self.high_mask = self.high_mask | bit;
41+
self.high_mask |= bit;
4242
}
4343
_ => {}
4444
}
4545
}
4646

47-
/// Remove a character from the character set.
48-
pub(crate) fn remove(&mut self, ch: char) {
49-
let val = ch as u32 - 1;
47+
/// Remove characters from the character set.
48+
pub(crate) fn remove(&mut self, chs: &[char]) {
49+
chs.iter().for_each(|ch| {
50+
let val = *ch as u32 - 1;
5051

51-
match val {
52-
0..=63 => {
53-
let bit = 1 << val;
54-
self.low_mask = self.low_mask & !bit;
55-
}
56-
64..=127 => {
57-
let bit = 1 << val - 64;
58-
self.high_mask = self.high_mask & !bit;
52+
match val {
53+
0..=63 => {
54+
let bit = 1 << val;
55+
self.low_mask &= !bit;
56+
}
57+
64..=127 => {
58+
let bit = 1 << val - 64;
59+
self.high_mask &= !bit;
60+
}
61+
_ => {}
5962
}
60-
_ => {}
61-
}
63+
});
6264
}
6365

6466
/// Check if the character `ch` is a member of the character set.
@@ -85,6 +87,13 @@ impl CharacterSet {
8587
chars.insert(ch);
8688
chars
8789
}
90+
91+
/// Insert the characters `chs` into the character set.
92+
pub(crate) fn from_chars(chs: &[char]) -> Self {
93+
let mut chars = Self::new();
94+
chs.iter().for_each(|ch| chars.insert(*ch));
95+
chars
96+
}
8897
}
8998

9099
pub(crate) struct State<T> {

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)