Skip to content

Commit cc81382

Browse files
authoredSep 20, 2023
fix(misc): Improve ci and fix clippy (#290)
* ci: Update actions, replace actions-rs. * `actions/checkout` is updated from `v1` to the current `v4`. * `actions-rs/toolchain` is replaced by `dtolnay/rust-toolchain` as the `actions-rs` actions haven't been maintained in a long time. * clippy: Remove unnecessary call to `into_iter`. The parameter takes `IntoIterator`, so we don't have to call `into_iter` at the call site. * clippy: Remove explicit lifetime that can be elided. * clippy: tests: Fix useless conversion warnings. * clippy: tests: Remove call to `format!`. * Fix minimal-versions build. Due to changes in the nightly compiler, using a recent nightly requires proc-macro2 1.0.60 or later: dtolnay/proc-macro2#356 * ci: Use is-terminal 0.4.7 for MSRV builds. is-terminal 0.4.8 updated its MSRV to 1.63, so we can't use it with our MSRV of 1.56. Force usage of the older version which has an older MSRV.
1 parent a9c2bae commit cc81382

File tree

7 files changed

+24
-66
lines changed

7 files changed

+24
-66
lines changed
 

‎.github/workflows/ci.yml

+11-16
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ jobs:
1010
name: Check fmt & build docs
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v1
13+
- uses: actions/checkout@v4
1414
- name: Install Rust
15-
uses: actions-rs/toolchain@v1
15+
uses: dtolnay/rust-toolchain@master
1616
with:
17-
profile: minimal
1817
toolchain: stable
1918
components: rustfmt
20-
override: true
2119
- name: rustfmt
2220
run: cargo fmt --all -- --check
2321
- name: docs
@@ -32,14 +30,15 @@ jobs:
3230
os: [ubuntu-latest, macOS-latest, windows-latest]
3331

3432
steps:
35-
- uses: actions/checkout@v1
33+
- uses: actions/checkout@v4
3634
- name: Install Rust
37-
uses: actions-rs/toolchain@v1
35+
uses: dtolnay/rust-toolchain@master
3836
with:
39-
profile: minimal
4037
toolchain: ${{ matrix.rust }}
4138
components: clippy
42-
override: true
39+
- name: Force older version of is-terminal for MSRV builds
40+
if: matrix.rust == '1.56.0'
41+
run: cargo update -p is-terminal --precise 0.4.7
4342
- name: Clippy
4443
run: cargo clippy --all -- -D warnings
4544
- name: Run tests
@@ -54,14 +53,12 @@ jobs:
5453
runs-on: ubuntu-latest
5554

5655
steps:
57-
- uses: actions/checkout@v1
56+
- uses: actions/checkout@v4
5857
- name: Install Rust
59-
uses: actions-rs/toolchain@v1
58+
uses: dtolnay/rust-toolchain@master
6059
with:
61-
profile: minimal
6260
toolchain: nightly
6361
components: miri,rust-src
64-
override: true
6562
- name: Run tests with miri
6663
env:
6764
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance
@@ -75,13 +72,11 @@ jobs:
7572
os: [ubuntu-latest, macOS-latest, windows-latest]
7673

7774
steps:
78-
- uses: actions/checkout@v1
75+
- uses: actions/checkout@v4
7976
- name: Install Rust
80-
uses: actions-rs/toolchain@v1
77+
uses: dtolnay/rust-toolchain@master
8178
with:
82-
profile: minimal
8379
toolchain: nightly
84-
override: true
8580
- name: Run minimal version build
8681
run: cargo build -Z minimal-versions --all-features
8782

‎miette-derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ repository = "https://github.com/zkat/miette"
1111
proc-macro = true
1212

1313
[dependencies]
14-
proc-macro2 = "1.0"
14+
proc-macro2 = "1.0.60"
1515
quote = "1.0"
1616
syn = "2.0.11"

‎src/handlers/graphical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ impl GraphicalReportHandler {
382382
Ok(())
383383
}
384384

385-
fn render_context<'a>(
385+
fn render_context(
386386
&self,
387387
f: &mut impl fmt::Write,
388-
source: &'a dyn SourceCode,
388+
source: &dyn SourceCode,
389389
context: &LabeledSpan,
390390
labels: &[LabeledSpan],
391391
) -> fmt::Result {

‎src/miette_diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl MietteDiagnostic {
252252
/// ```
253253
pub fn and_labels(mut self, labels: impl IntoIterator<Item = LabeledSpan>) -> Self {
254254
let mut all_labels = self.labels.unwrap_or_default();
255-
all_labels.extend(labels.into_iter());
255+
all_labels.extend(labels);
256256
self.labels = Some(all_labels);
257257
self
258258
}

‎tests/derive.rs

+8-29
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn fmt_help() {
189189

190190
assert_eq!(
191191
"1 x hello x \"2\"".to_string(),
192-
FooStruct("hello".into()).help().unwrap().to_string()
192+
FooStruct("hello").help().unwrap().to_string()
193193
);
194194

195195
#[derive(Debug, Diagnostic, Error)]
@@ -201,12 +201,7 @@ fn fmt_help() {
201201

202202
assert_eq!(
203203
"1 x hello x \"2\"".to_string(),
204-
BarStruct {
205-
my_field: "hello".into()
206-
}
207-
.help()
208-
.unwrap()
209-
.to_string()
204+
BarStruct { my_field: "hello" }.help().unwrap().to_string()
210205
);
211206

212207
#[derive(Debug, Diagnostic, Error)]
@@ -224,7 +219,7 @@ fn fmt_help() {
224219

225220
assert_eq!(
226221
"1 x bar x \"2\"".to_string(),
227-
FooEnum::X("bar".into()).help().unwrap().to_string()
222+
FooEnum::X("bar").help().unwrap().to_string()
228223
);
229224

230225
assert_eq!(
@@ -250,12 +245,7 @@ fn help_field() {
250245

251246
assert_eq!(
252247
"x".to_string(),
253-
Foo {
254-
do_this: Some("x".into())
255-
}
256-
.help()
257-
.unwrap()
258-
.to_string()
248+
Foo { do_this: Some("x") }.help().unwrap().to_string()
259249
);
260250

261251
#[derive(Debug, Diagnostic, Error)]
@@ -271,37 +261,26 @@ fn help_field() {
271261

272262
assert_eq!(
273263
"x".to_string(),
274-
Bar::A(Some("x".into())).help().unwrap().to_string()
264+
Bar::A(Some("x")).help().unwrap().to_string()
275265
);
276266
assert_eq!(
277267
"x".to_string(),
278-
Bar::B {
279-
do_this: Some("x".into())
280-
}
281-
.help()
282-
.unwrap()
283-
.to_string()
268+
Bar::B { do_this: Some("x") }.help().unwrap().to_string()
284269
);
285270

286271
#[derive(Debug, Diagnostic, Error)]
287272
#[error("welp")]
288273
#[diagnostic()]
289274
struct Baz<'a>(#[help] Option<&'a str>);
290275

291-
assert_eq!(
292-
"x".to_string(),
293-
Baz(Some("x".into())).help().unwrap().to_string()
294-
);
276+
assert_eq!("x".to_string(), Baz(Some("x")).help().unwrap().to_string());
295277

296278
#[derive(Debug, Diagnostic, Error)]
297279
#[error("welp")]
298280
#[diagnostic()]
299281
struct Quux<'a>(#[help] &'a str);
300282

301-
assert_eq!(
302-
"x".to_string(),
303-
Quux("x".into()).help().unwrap().to_string()
304-
);
283+
assert_eq!("x".to_string(), Quux("x").help().unwrap().to_string());
305284
}
306285

307286
#[test]

‎tests/test_diagnostic_source_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn test_diagnostic_source() {
7979
fn test_diagnostic_source_pass_extra_info() {
8080
let diag = TestBoxedError(Box::new(SourceError {
8181
code: String::from("Hello\nWorld!"),
82-
help: format!("Have you tried turning it on and off again?"),
82+
help: String::from("Have you tried turning it on and off again?"),
8383
label: (1, 4),
8484
}));
8585
let mut out = String::new();

‎tests/test_json.rs

-16
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ mod json_report_handler {
5252
"related": []
5353
}"#
5454
.lines()
55-
.into_iter()
5655
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
5756
.collect();
5857
assert_eq!(expected, out);
@@ -98,7 +97,6 @@ mod json_report_handler {
9897
"related": []
9998
}"#
10099
.lines()
101-
.into_iter()
102100
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
103101
.collect();
104102
assert_eq!(expected, out);
@@ -144,7 +142,6 @@ mod json_report_handler {
144142
"related": []
145143
}"#
146144
.lines()
147-
.into_iter()
148145
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
149146
.collect();
150147
assert_eq!(expected, out);
@@ -190,7 +187,6 @@ mod json_report_handler {
190187
"related": []
191188
}"#
192189
.lines()
193-
.into_iter()
194190
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
195191
.collect();
196192
assert_eq!(expected, out);
@@ -235,7 +231,6 @@ mod json_report_handler {
235231
"related": []
236232
}"#
237233
.lines()
238-
.into_iter()
239234
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
240235
.collect();
241236
assert_eq!(expected, out);
@@ -281,7 +276,6 @@ mod json_report_handler {
281276
"related": []
282277
}"#
283278
.lines()
284-
.into_iter()
285279
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
286280
.collect();
287281
assert_eq!(expected, out);
@@ -347,7 +341,6 @@ mod json_report_handler {
347341
"related": []
348342
}"#
349343
.lines()
350-
.into_iter()
351344
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
352345
.collect();
353346
assert_eq!(expected, out);
@@ -393,7 +386,6 @@ mod json_report_handler {
393386
"related": []
394387
}"#
395388
.lines()
396-
.into_iter()
397389
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
398390
.collect();
399391
assert_eq!(expected, out);
@@ -456,7 +448,6 @@ mod json_report_handler {
456448
"related": []
457449
}"#
458450
.lines()
459-
.into_iter()
460451
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
461452
.collect();
462453
assert_eq!(expected, out);
@@ -532,7 +523,6 @@ mod json_report_handler {
532523
"related": []
533524
}"#
534525
.lines()
535-
.into_iter()
536526
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
537527
.collect();
538528
assert_eq!(expected, out);
@@ -588,7 +578,6 @@ mod json_report_handler {
588578
"related": []
589579
}"#
590580
.lines()
591-
.into_iter()
592581
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
593582
.collect();
594583
assert_eq!(expected, out);
@@ -644,7 +633,6 @@ mod json_report_handler {
644633
"related": []
645634
}"#
646635
.lines()
647-
.into_iter()
648636
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
649637
.collect();
650638
assert_eq!(expected, out);
@@ -700,7 +688,6 @@ mod json_report_handler {
700688
"related": []
701689
}"#
702690
.lines()
703-
.into_iter()
704691
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
705692
.collect();
706693
assert_eq!(expected, out);
@@ -728,7 +715,6 @@ mod json_report_handler {
728715
"related": []
729716
}"#
730717
.lines()
731-
.into_iter()
732718
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
733719
.collect();
734720
assert_eq!(expected, out);
@@ -822,7 +808,6 @@ mod json_report_handler {
822808
}]
823809
}"#
824810
.lines()
825-
.into_iter()
826811
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
827812
.collect();
828813
assert_eq!(expected, out);
@@ -920,7 +905,6 @@ mod json_report_handler {
920905
}]
921906
}"#
922907
.lines()
923-
.into_iter()
924908
.map(|s| s.trim_matches(|c| c == ' ' || c == '\n'))
925909
.collect();
926910
assert_eq!(expected, out);

0 commit comments

Comments
 (0)
Please sign in to comment.