Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable clippy lints up to Rust 1.48 #901

Merged
merged 7 commits into from
Feb 14, 2023
Merged

Enable clippy lints up to Rust 1.48 #901

merged 7 commits into from
Feb 14, 2023

Conversation

LingMan
Copy link
Contributor

@LingMan LingMan commented Nov 29, 2022

Enables clippy to show lints applicable for Rust versions 1.39..=1.48 and fixes all resulting warnings.

Fixes clippy warning:
```
warning: this seems like a manual implementation of the non-exhaustive pattern
   --> src/format/parsed.rs:24:1
    |
24  |   pub struct Parsed {
    |   ^----------------
    |   |
    |  _help: add the attribute: `#[non_exhaustive] pub struct Parsed`
    | |
25  | |     /// Year.
26  | |     ///
27  | |     /// This can be negative unlike [`year_div_100`](#structfield.year_div_100)
...   |
107 | |     _dummy: (),
108 | | }
    | |_^
    |
    = note: `#[warn(clippy::manual_non_exhaustive)]` on by default
help: remove this field
   --> src/format/parsed.rs:107:5
    |
107 |     _dummy: (),
    |     ^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
```
Fixes clippy warning:
```
warning: this seems like a manual implementation of the non-exhaustive pattern
   --> src/format/mod.rs:360:1
    |
360 |   pub enum ParseErrorKind {
    |   ^----------------------
    |   |
    |  _help: add the attribute: `#[non_exhaustive] pub enum ParseErrorKind`
    | |
361 | |     /// Given field is out of permitted range.
362 | |     OutOfRange,
363 | |
...   |
391 | |     __Nonexhaustive,
392 | | }
    | |_^
    |
help: remove this variant
   --> src/format/mod.rs:391:5
    |
391 |     __Nonexhaustive,
    |     ^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
```
Fixes clippy warning:
```
warning: match expression looks like `matches!` macro
   --> src/format/scan.rs:316:24
    |
316 |           .position(|&c| match c {
    |  ________________________^
317 | |             b'a'..=b'z' | b'A'..=b'Z' => false,
318 | |             _ => true,
319 | |         })
    | |_________^ help: try this: `!matches!(c, b'a'..=b'z' | b'A'..=b'Z')`
    |
    = note: `#[warn(clippy::match_like_matches_macro)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
```
Potentially saves one char boundary check.
Fixes two clippy warnings:
```
warning: called `.as_ref().map(|s| s.as_str())` on an Option value. This can be done more directly by calling `env_tz.as_deref()` instead
  --> src/offset/local/unix.rs:91:23
   |
91 |         let env_ref = env_tz.as_ref().map(|s| s.as_str());
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `env_tz.as_deref()`
   |
   = note: `#[warn(clippy::option_as_ref_deref)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref

warning: called `.as_ref().map(|s| s.as_str())` on an Option value. This can be done more directly by calling `env_tz.as_deref()` instead
   --> src/offset/local/unix.rs:117:31
    |
117 |                 let env_ref = env_tz.as_ref().map(|s| s.as_str());
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `env_tz.as_deref()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref
```
@djc
Copy link
Member

djc commented Nov 29, 2022

Thanks!

@djc djc requested a review from esheppa December 15, 2022 15:27
@LingMan
Copy link
Contributor Author

LingMan commented Dec 15, 2022

Added one more fix for a clippy warning that shows up since Rust 1.66.

Fixes clippy warning:
```
warning: casting to the same type is unnecessary (`u32` -> `u32`)
  --> src/offset/utc.rs:71:69
   |
71 |             NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos() as u32)
   |                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `now.subsec_nanos()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
   = note: `#[warn(clippy::unnecessary_cast)]` on by default
```
The MSRV was recently raised in [1], but clippy was missed.

[1] chronotope@95532db
@LingMan
Copy link
Contributor Author

LingMan commented Feb 13, 2023

Gentle ping.

@djc
Copy link
Member

djc commented Feb 14, 2023

@esheppa going to merge this, please feel free to review post-merge.

@djc djc merged commit c718e03 into chronotope:main Feb 14, 2023
@djc
Copy link
Member

djc commented Feb 14, 2023

Thanks, and sorry for the delay!

@LingMan LingMan deleted the clippy148 branch February 14, 2023 10:50
Copy link
Collaborator

@esheppa esheppa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants