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

Cleanup with more clippy lints #336

Merged
merged 8 commits into from
Jul 31, 2022
Merged

Cleanup with more clippy lints #336

merged 8 commits into from
Jul 31, 2022

Conversation

marioortizmanero
Copy link
Collaborator

@marioortizmanero marioortizmanero commented Jul 9, 2022

Description

This PR cleans up a lot of code thanks to the clippy lints described in #204.

#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(clippy::module_name_repetitions, clippy::module_name_repetitions, clippy::cast_possible_truncation)]
  • Proper metadata in Cargo.toml (categories field)
  • Lots of new #[must_use]
  • Use Self where possible
  • Avoid useless closures
  • Remove useless functions: Offset constructors

Motivation and Context

Some code is overly complex or not well annotated.

Dependencies

None

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

CI still passes

Is this change properly documented?

Yes

@marioortizmanero marioortizmanero marked this pull request as draft July 9, 2022 18:59
@marioortizmanero marioortizmanero changed the title More clippy lints Cleanup with more clippy lints Jul 9, 2022
@marioortizmanero marioortizmanero marked this pull request as ready for review July 27, 2022 13:10
@@ -217,7 +217,7 @@ pub mod space_separated_scopes {
D: de::Deserializer<'de>,
{
let scopes: &str = Deserialize::deserialize(d)?;
Ok(scopes.split_whitespace().map(|x| x.to_owned()).collect())
Ok(scopes.split_whitespace().map(ToOwned::to_owned).collect())
Copy link
Owner

Choose a reason for hiding this comment

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

I learned a new thing :)

@@ -210,6 +210,7 @@ macro_rules! define_idtypes {
/// Only returns `true` in case the given string is valid
/// according to that specific ID (e.g., some may require
/// alphanumeric characters only).
#[must_use]
Copy link
Owner

Choose a reason for hiding this comment

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

Just out of curiosity, these functions are all must_use ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? Yes, I marked all of them with must_use because clippy told me to, and it makes sense.

MinValence(x) => x.to_string(),
MaxValence(x) => x.to_string(),
TargetValence(x) => x.to_string(),
MinAcousticness(x)
Copy link
Owner

Choose a reason for hiding this comment

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

Cool, Huge work!

@@ -5,7 +5,7 @@ use std::collections::HashMap;
use serde::Serialize;
use std::marker::PhantomData;

pub(crate) fn build_map<'key, 'value, const N: usize>(
pub fn build_map<'key, 'value, const N: usize>(
Copy link
Owner

Choose a reason for hiding this comment

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

Will this change the visibility from crate public to globally public?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because the entire module is already public to the crate only. No need to do that again.

Copy link
Owner

@ramsayleung ramsayleung left a comment

Choose a reason for hiding this comment

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

In summary, clippy is a great mentor.

@ramsayleung
Copy link
Owner

ramsayleung commented Jul 31, 2022

This PR is ready to merge, but the merge button disappears again.

@marioortizmanero
Copy link
Collaborator Author

That's weird... Maybe try disabling the adblocker or something like that? I'll merge myself.

@marioortizmanero marioortizmanero merged commit ddb6f49 into master Jul 31, 2022
@marioortizmanero marioortizmanero deleted the clippy-lints branch July 31, 2022 10:35
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.

2 participants