Skip to content

Commit 2d81d51

Browse files
Th3LinkMarc Luehr
andauthored
Update to rust 1.86, fix ci, introduce clippy and fmt (#393)
* feat: Upgrade to rust 1.86 * ci: Add clippy and fix all initial clippy warnings --------- Co-authored-by: Marc Luehr <marc@luehr.org>
1 parent 49d2a4e commit 2d81d51

12 files changed

Lines changed: 54 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: Continuous integration
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v6
1010
- name: Extract Rust version from Cargo.toml
1111
run: |
1212
MSRV=$(sed -n 's/^rust-version = "\([^"]*\)"/\1/p' Cargo.toml)
@@ -16,6 +16,7 @@ jobs:
1616
uses: dtolnay/rust-toolchain@stable # actions-rust-lang/setup-rust-toolchain@v1
1717
with:
1818
toolchain: ${{ env.MSRV }}
19+
components: clippy,rustfmt
1920
- name: Cache dependencies
2021
uses: Swatinem/rust-cache@v2
2122
- name: Build System Info
@@ -26,6 +27,11 @@ jobs:
2627
cargo test --no-default-features
2728
cargo build --features derive --features card
2829
cargo test --features derive --features card
30+
- name: Format check
31+
run: cargo fmt --check
32+
- name: Run Clippy
33+
run: cargo clippy --all-targets --features derive --features card -- -D warnings
34+
2935
test_validator-nightly:
3036
name: Continuous integration
3137
runs-on: ubuntu-latest
@@ -34,7 +40,7 @@ jobs:
3440
include:
3541
- rust: nightly
3642
steps:
37-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@v6
3844
- name: Install Rust
3945
uses: dtolnay/rust-toolchain@stable
4046
with:
@@ -48,4 +54,4 @@ jobs:
4854
cargo build --no-default-features
4955
cargo test --no-default-features
5056
cargo build --all-features
51-
cargo test --all-features
57+
cargo test --all-features

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ resolver = "2"
33
members = ["validator", "validator_derive", "validator_derive_tests"]
44

55
[workspace.package]
6-
rust-version = "1.81"
6+
rust-version = "1.86"

validator/src/validation/cards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ pub trait ValidateCreditCard {
99
CardValidate::from(&card_string).is_ok()
1010
}
1111

12-
fn as_credit_card_string(&self) -> Cow<str>;
12+
fn as_credit_card_string(&self) -> Cow<'_, str>;
1313
}
1414

1515
impl<T: AsRef<str>> ValidateCreditCard for T {
16-
fn as_credit_card_string(&self) -> Cow<str> {
16+
fn as_credit_card_string(&self) -> Cow<'_, str> {
1717
Cow::from(self.as_ref())
1818
}
1919
}

validator/src/validation/email.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ pub trait ValidateEmail {
7777
true
7878
}
7979

80-
fn as_email_string(&self) -> Option<Cow<str>>;
80+
fn as_email_string(&self) -> Option<Cow<'_, str>>;
8181
}
8282

8383
impl<T> ValidateEmail for &T
8484
where
8585
T: ValidateEmail,
8686
{
87-
fn as_email_string(&self) -> Option<Cow<str>> {
87+
fn as_email_string(&self) -> Option<Cow<'_, str>> {
8888
T::as_email_string(self)
8989
}
9090
}
9191

9292
impl ValidateEmail for String {
93-
fn as_email_string(&self) -> Option<Cow<str>> {
93+
fn as_email_string(&self) -> Option<Cow<'_, str>> {
9494
Some(Cow::from(self))
9595
}
9696
}
@@ -99,7 +99,7 @@ impl<T> ValidateEmail for Option<T>
9999
where
100100
T: ValidateEmail,
101101
{
102-
fn as_email_string(&self) -> Option<Cow<str>> {
102+
fn as_email_string(&self) -> Option<Cow<'_, str>> {
103103
let Some(u) = self else {
104104
return None;
105105
};

validator/src/validation/regex.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::sync::{Arc, LazyLock, Mutex, OnceLock};
66
use regex::Regex;
77

88
pub trait AsRegex {
9-
fn as_regex(&self) -> Cow<Regex>;
9+
fn as_regex(&self) -> Cow<'_, Regex>;
1010
}
1111

1212
impl AsRegex for Regex {
13-
fn as_regex(&self) -> Cow<Regex> {
13+
fn as_regex(&self) -> Cow<'_, Regex> {
1414
Cow::Borrowed(self)
1515
}
1616
}
@@ -19,43 +19,43 @@ impl<T> AsRegex for &T
1919
where
2020
T: AsRegex,
2121
{
22-
fn as_regex(&self) -> Cow<Regex> {
22+
fn as_regex(&self) -> Cow<'_, Regex> {
2323
T::as_regex(self)
2424
}
2525
}
2626

2727
impl AsRegex for &OnceLock<Regex> {
28-
fn as_regex(&self) -> Cow<Regex> {
28+
fn as_regex(&self) -> Cow<'_, Regex> {
2929
Cow::Borrowed(self.get().unwrap())
3030
}
3131
}
3232

3333
impl AsRegex for &Mutex<OnceCell<Regex>> {
34-
fn as_regex(&self) -> Cow<Regex> {
34+
fn as_regex(&self) -> Cow<'_, Regex> {
3535
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
3636
}
3737
}
3838

3939
impl AsRegex for &Mutex<OnceLock<Regex>> {
40-
fn as_regex(&self) -> Cow<Regex> {
40+
fn as_regex(&self) -> Cow<'_, Regex> {
4141
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
4242
}
4343
}
4444

4545
impl AsRegex for &Arc<Mutex<OnceCell<Regex>>> {
46-
fn as_regex(&self) -> Cow<Regex> {
46+
fn as_regex(&self) -> Cow<'_, Regex> {
4747
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
4848
}
4949
}
5050

5151
impl AsRegex for &Arc<Mutex<OnceLock<Regex>>> {
52-
fn as_regex(&self) -> Cow<Regex> {
52+
fn as_regex(&self) -> Cow<'_, Regex> {
5353
Cow::Owned(self.lock().unwrap().get().unwrap().clone())
5454
}
5555
}
5656

5757
impl AsRegex for LazyLock<Regex> {
58-
fn as_regex(&self) -> Cow<Regex> {
58+
fn as_regex(&self) -> Cow<'_, Regex> {
5959
Cow::Borrowed(self)
6060
}
6161
}

validator/src/validation/urls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait ValidateUrl {
1616
}
1717
}
1818

19-
fn as_url_string(&self) -> Option<Cow<str>>;
19+
fn as_url_string(&self) -> Option<Cow<'_, str>>;
2020
}
2121

2222
macro_rules! validate_type_that_derefs {
@@ -25,7 +25,7 @@ macro_rules! validate_type_that_derefs {
2525
where
2626
T: ValidateUrl,
2727
{
28-
fn as_url_string(&self) -> Option<Cow<str>> {
28+
fn as_url_string(&self) -> Option<Cow<'_, str>> {
2929
T::as_url_string(self)
3030
}
3131
}
@@ -42,7 +42,7 @@ validate_type_that_derefs!(RefMut<'_, T>);
4242
macro_rules! validate_type_of_str {
4343
($type_:ty) => {
4444
impl ValidateUrl for $type_ {
45-
fn as_url_string(&self) -> Option<Cow<str>> {
45+
fn as_url_string(&self) -> Option<Cow<'_, str>> {
4646
Some(Cow::Borrowed(self))
4747
}
4848
}
@@ -57,7 +57,7 @@ impl<T> ValidateUrl for Option<T>
5757
where
5858
T: ValidateUrl,
5959
{
60-
fn as_url_string(&self) -> Option<Cow<str>> {
60+
fn as_url_string(&self) -> Option<Cow<'_, str>> {
6161
let Some(u) = self else {
6262
return None;
6363
};

validator_derive/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ impl ValidationData {
280280
}
281281

282282
if let Data::Struct(fields) = &self.data {
283-
let original_fields: Vec<&Field> =
284-
fields.fields.iter().map(|f| &f.original).collect();
283+
let original_fields: Vec<&Field> = fields.fields.iter().map(|f| &f.original).collect();
285284
for f in &fields.fields {
286285
f.parsed.validate(&self.ident, &original_fields, &f.original);
287286
}

validator_derive/src/types.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ impl ValidateField {
153153
pub fn number_options(&self) -> u8 {
154154
fn find_option(mut count: u8, ty: &syn::Type) -> u8 {
155155
if let syn::Type::Path(p) = ty {
156-
let idents_of_path =
157-
p.path.segments.iter().fold(String::new(), |mut acc, v| {
158-
acc.push_str(&v.ident.to_string());
159-
acc.push('|');
160-
acc
161-
});
156+
let idents_of_path = p.path.segments.iter().fold(String::new(), |mut acc, v| {
157+
acc.push_str(&v.ident.to_string());
158+
acc.push('|');
159+
acc
160+
});
162161

163162
if OPTIONS_TYPE.contains(&idents_of_path.as_str()) {
164163
count += 1;

validator_derive_tests/tests/compile-fail/wrong_crate_alias.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,42 @@ error[E0432]: unresolved import `validator_other`
22
--> tests/compile-fail/wrong_crate_alias.rs:9:24
33
|
44
9 | #[validate(crate = "validator_other")]
5-
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
5+
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
6+
|
7+
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
68

7-
error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
9+
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
810
--> tests/compile-fail/wrong_crate_alias.rs:9:24
911
|
1012
9 | #[validate(crate = "validator_other")]
11-
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
13+
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
1214
|
15+
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
1316
help: consider importing one of these structs
1417
|
1518
4 + use crate::validator_renamed::ValidationErrors;
1619
|
1720
4 + use validator::ValidationErrors;
1821
|
1922

20-
error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
23+
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
2124
--> tests/compile-fail/wrong_crate_alias.rs:9:24
2225
|
2326
9 | #[validate(crate = "validator_other")]
24-
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
27+
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
2528
|
29+
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`
2630
help: consider importing one of these structs
2731
|
2832
4 + use crate::validator_renamed::ValidationError;
2933
|
3034
4 + use validator::ValidationError;
3135
|
3236

33-
error[E0433]: failed to resolve: use of undeclared crate or module `validator_other`
37+
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `validator_other`
3438
--> tests/compile-fail/wrong_crate_alias.rs:9:24
3539
|
3640
9 | #[validate(crate = "validator_other")]
37-
| ^^^^^^^^^^^^^^^^^ use of undeclared crate or module `validator_other`
41+
| ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `validator_other`
42+
|
43+
= help: if you wanted to use a crate named `validator_other`, use `cargo add validator_other` to add it to your `Cargo.toml`

validator_derive_tests/tests/credit_card.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn can_validate_custom_impl_for_credit_card() {
8585
}
8686

8787
impl validator::ValidateCreditCard for CustomCreditCard {
88-
fn as_credit_card_string(&self) -> Cow<str> {
88+
fn as_credit_card_string(&self) -> Cow<'_, str> {
8989
Cow::from(format!("{}{}{}", &self.bin, &self.ian, &self.check,))
9090
}
9191
}

0 commit comments

Comments
 (0)