Skip to content

Commit c63d87d

Browse files
committed
Rust 1.95.0; Clippy fixes; Enforce clippy
1 parent 72105fd commit c63d87d

9 files changed

Lines changed: 45 additions & 56 deletions

File tree

.github/workflows/clippy.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Clippy
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
clippy:
8+
name: cargo clippy
9+
runs-on: ubuntu-24.04
10+
steps:
11+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
12+
- run: |
13+
rustup toolchain install
14+
- run: |
15+
cargo clippy --workspace --all-targets --all-features -- -D warnings

.github/workflows/fmt.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ jobs:
77
check_fmt:
88
runs-on: ubuntu-24.04
99
steps:
10-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
11-
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
12-
with:
13-
toolchain: stable
14-
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
15-
with:
16-
command: fmt
17-
args: -- --check
10+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
11+
- run: |
12+
rustup toolchain install
13+
- run: |
14+
cargo fmt -- --check

.github/workflows/test.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ jobs:
88
name: cargo test
99
runs-on: ubuntu-24.04
1010
steps:
11-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
12-
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
13-
with:
14-
toolchain: stable
11+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
12+
- run: |
13+
rustup toolchain install
1514
1615
- uses: michaelkaye/setup-matrix-synapse@main
1716
with:
@@ -24,9 +23,7 @@ jobs:
2423
"enable_registration": true
2524
}
2625
27-
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
28-
with:
29-
command: test
26+
- run: cargo test
3027
env:
3128
RUST_BACKTRACE: 1
3229
RUST_LOG: info,micro=trace,matrix=trace,ruma=trace,test=trace

microbot/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum MessengerError {
4343
#[error("Bot has already been started")]
4444
AlreadyStarted,
4545
#[error(transparent)]
46-
Builder(#[from] ClientBuildError),
46+
Builder(Box<ClientBuildError>),
4747
#[error(transparent)]
4848
Client(#[from] matrix_sdk::Error),
4949
#[error(transparent)]
@@ -54,6 +54,12 @@ pub enum MessengerError {
5454
PrefixConfig(regex::Error),
5555
}
5656

57+
impl From<ClientBuildError> for MessengerError {
58+
fn from(err: ClientBuildError) -> Self {
59+
MessengerError::Builder(Box::new(err))
60+
}
61+
}
62+
5763
#[derive(Debug, Deserialize)]
5864
pub struct MatrixConfig {
5965
pub url: String,
@@ -189,7 +195,7 @@ impl MatrixMessenger {
189195
LoopCtrl::Continue
190196
}
191197
}).await
192-
}.map_err(|err| MessengerError::Client(err))
198+
}.map_err(MessengerError::Client)
193199
));
194200

195201
Ok(())

microbot/src/message.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,6 @@ pub(crate) struct CommandMessageParser {
6262
command_pattern: Regex,
6363
}
6464

65-
#[derive(Debug)]
66-
pub(crate) struct CommandMessageParserError {
67-
pub inner: regex::Error,
68-
}
69-
70-
impl From<regex::Error> for CommandMessageParserError {
71-
fn from(err: regex::Error) -> Self {
72-
Self { inner: err }
73-
}
74-
}
75-
76-
impl std::fmt::Display for CommandMessageParserError {
77-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78-
write!(
79-
f,
80-
"Failed to construct command message parser: {}",
81-
self.inner
82-
)
83-
}
84-
}
85-
86-
impl std::error::Error for CommandMessageParserError {
87-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
88-
Some(&self.inner)
89-
}
90-
}
91-
9265
impl Default for CommandMessageParser {
9366
fn default() -> Self {
9467
Self {

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.95.0"
3+
components = ["clippy", "rustfmt"]

tests/tests/bot_conversation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::sync::{
1212
};
1313
use tracing_subscriber::filter::EnvFilter;
1414

15-
static HOMESERVER: &'static str = "http://localhost:8008";
15+
static HOMESERVER: &str = "http://localhost:8008";
1616

1717
// This test configures two bots and an initial sender that will send an initial command.
1818
// In response to this command the two bots will command messages to the room triggering
@@ -49,23 +49,23 @@ async fn test_bot_conversation() {
4949
rand::rng()
5050
.sample_iter(&Alphanumeric)
5151
.take(24)
52-
.map(|b| char::from(b))
52+
.map(char::from)
5353
.collect::<String>()
5454
);
5555
let bot1 = format!(
5656
"test-bot1-{}",
5757
rand::rng()
5858
.sample_iter(&Alphanumeric)
5959
.take(24)
60-
.map(|b| char::from(b))
60+
.map(char::from)
6161
.collect::<String>()
6262
);
6363
let bot2 = format!(
6464
"test-bot2-{}",
6565
rand::rng()
6666
.sample_iter(&Alphanumeric)
6767
.take(24)
68-
.map(|b| char::from(b))
68+
.map(char::from)
6969
.collect::<String>()
7070
);
7171

@@ -164,8 +164,6 @@ async fn test_bot_conversation() {
164164

165165
handle1.abort();
166166
handle2.abort();
167-
168-
()
169167
})
170168
.await
171169
.expect("Failed to run bot test in time");

tests/tests/ignore_old_messages.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt};
88
use tokio::sync::{mpsc, mpsc::Sender};
99
use tracing_subscriber::filter::EnvFilter;
1010

11-
static HOMESERVER: &'static str = "http://localhost:8008";
11+
static HOMESERVER: &str = "http://localhost:8008";
1212

1313
#[tokio::test]
1414
async fn test_ignores_old_messages() {
@@ -23,15 +23,15 @@ async fn test_ignores_old_messages() {
2323
rand::rng()
2424
.sample_iter(&Alphanumeric)
2525
.take(24)
26-
.map(|b| char::from(b))
26+
.map(char::from)
2727
.collect::<String>()
2828
);
2929
let receiver = format!(
3030
"test-receiver-{}",
3131
rand::rng()
3232
.sample_iter(&Alphanumeric)
3333
.take(24)
34-
.map(|b| char::from(b))
34+
.map(char::from)
3535
.collect::<String>()
3636
);
3737

tests/tests/receives_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt};
88
use tokio::sync::{mpsc, mpsc::Sender};
99
use tracing_subscriber::filter::EnvFilter;
1010

11-
static HOMESERVER: &'static str = "http://localhost:8008";
11+
static HOMESERVER: &str = "http://localhost:8008";
1212

1313
#[tokio::test]
1414
async fn test_receives_command() {
@@ -23,15 +23,15 @@ async fn test_receives_command() {
2323
rand::rng()
2424
.sample_iter(&Alphanumeric)
2525
.take(24)
26-
.map(|b| char::from(b))
26+
.map(char::from)
2727
.collect::<String>()
2828
);
2929
let receiver = format!(
3030
"test-receiver-{}",
3131
rand::rng()
3232
.sample_iter(&Alphanumeric)
3333
.take(24)
34-
.map(|b| char::from(b))
34+
.map(char::from)
3535
.collect::<String>()
3636
);
3737

0 commit comments

Comments
 (0)