Skip to content

Conversation

@dcampbell24
Copy link
Contributor

I ran cargo clippy --workspace --all-targets --all-features -- --warn clippy::LINT for all the lints listed in the below thread. I can't figure out what is different about running clippy through the file pre-commit-config.yaml, but it gives different results. I fixed all the lints in the below listed thread except for clippy::match_same_arm, clippy::redundant_else, clippy::single_match_else, clippy::unnecessary_wraps, and clippy::unnested_or_patterns. They seemed either unlike they should be fixed or hard to fix.

This works on #4949.

@dcampbell24
Copy link
Contributor Author

I don't have a windows machine and don't understand why the windows checks are failing.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/timeout/timeout. tests/timeout/timeout is passing on 'main'. Maybe you have to rebase?


let commands = match matches.get_many::<String>(options::COMMAND) {
Some(v) => v.map(|s| s.as_str()).collect(),
Some(v) => v.map(std::string::String::as_str).collect(),
Copy link
Contributor

Choose a reason for hiding this comment

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

i would prefer just
String::as_str
and have an import

repeating std::string isn't providing much value

let root_path = current_dir.join(root);
let root_parent = if target.exists() && !root.to_str().unwrap().ends_with("/.") {
root_path.parent().map(|p| p.to_path_buf())
root_path.parent().map(std::path::Path::to_path_buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment about Path

Suggested change
root_path.parent().map(std::path::Path::to_path_buf)
root_path.parent().map(Path::to_path_buf)

@sylvestre
Copy link
Contributor

For the windows error, you can test using MS images:
https://developer.microsoft.com/windows/downloads/virtual-machines/

Here, for this error, the type is probably different on windows vs linux

 error[E0631]: type mismatch in function arguments
   --> src\uu\env\src\native_int_str.rs:268:48
    |
268 |             |o| o.strip_prefix(&*n_prefix).map(<[u8]>::to_vec).ok_or(()),
    |                                            --- ^^^^^^^^^^^^^^
    |                                            |   |
    |                                            |   expected due to this
    |                                            |   found signature defined here
    |                                            required by a bound introduced by this call
    |
    = note: expected function signature `fn(&[u16]) -> _`
               found function signature `fn(&[u8]) -> _`
note: required by a bound in `std::option::Option::<T>::map`

(Some(w), None) => {
// Only allow a goal of zero if the width is set to be zero
let g = (w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100).max(if w == 0 { 0 } else { 1 });
let g = (w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100).max(usize::from(w != 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure to see the improvement here

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be rephrased anyway? Something like

let computed_goal = w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100;
let g = if computed_goal > 0 {
    computed_goal
} else if width == 0 {
    0
} else {
    1
}

This is probably not yet ideal, but it might make the intent clearer.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

Interesting! Thanks! I like most of this, especially the format string improvements and the underscores in literals. I also think that it's important to consider that these are pedantic lints for a reason: they are more subjective than others. For instance, I dislike the map_or lint in complex expressions, because I think it's easier to read the the map and unwrap parts as separate calls. I also agree with Sylvestre that the paths should be shortened for the map calls.

Here are the commits I'd definitely accept:

  • manual_assert
  • uninlined_format_args
  • unnecessary_join
  • unreadable_literal
  • inconsistent_struct_literal
  • cloned_instead_of_copied
  • flat_map_option

The more difficult cases that we should maybe split off into separate PRs for more discussion are:

  • format_collect
  • bool_to_int_with_if
  • inefficient_to_string
  • map_unwrap_or
  • redundant_closure_for_method_calls
  • used_underscore_binding (I agree with the lint, but maybe it can be fixed without allows)
  • map_or_else

I think splitting this up makes it much easier to discuss. Hope that makes sense!

};
#[cfg(unix)]
#[allow(clippy::used_underscore_binding)]
let usage = FsUsage::new(statfs(_stat_path).ok()?);
Copy link
Member

Choose a reason for hiding this comment

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

Is there are reason to keep this as an underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I change it to not an underscore, then I would have to add #[allow(unused_variables)] to the windows side of things.

Copy link
Contributor Author

@dcampbell24 dcampbell24 Sep 21, 2024

Choose a reason for hiding this comment

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

Oh. in this case I was worried about the possibility of other #[cfg(system)]s existing, like one for browsers, or some other unknown system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's not the case, then why isn't it #[cfg(unix)] and #[cfg(not(unix))].

Copy link
Member

Choose a reason for hiding this comment

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

Probably should be yeah!

(Some(w), None) => {
// Only allow a goal of zero if the width is set to be zero
let g = (w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100).max(if w == 0 { 0 } else { 1 });
let g = (w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100).max(usize::from(w != 0));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be rephrased anyway? Something like

let computed_goal = w * DEFAULT_GOAL_TO_WIDTH_RATIO / 100;
let g = if computed_goal > 0 {
    computed_goal
} else if width == 0 {
    0
} else {
    1
}

This is probably not yet ideal, but it might make the intent clearer.

.opts
.prefix
.as_ref()
.map_or(0, std::string::String::len)..]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can extract this to a variable:

let prefix_len = self.opts.prefix.as_ref().map_or(0, String::len);

I think that makes the intent and the formatting clearer and allows us to reuse the value.


fn obsolete_result(src: &[&str]) -> Option<Result<Vec<String>, ParseError>> {
Some(Ok(src.iter().map(|s| s.to_string()).collect()))
Some(Ok(src.iter().map(|s| (*s).to_string()).collect()))
Copy link
Member

Choose a reason for hiding this comment

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

What clippy lint triggered this? It seems to make it more complicted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inefficient_to_string the compiler specializes the to_string in the changed case: https://rust-lang.github.io/rust-clippy/master/index.html#/to_string.

@dcampbell24
Copy link
Contributor Author

Do you suggest an easy way to split the commits up? I looked online and there were a few different suggestions including copy and pasting. Sorry for being unexperienced in git.

@sylvestre
Copy link
Contributor

sylvestre commented Sep 21, 2024

make a backup and:
git rebase -i origin/main
and dropped the various patches

Copy link
Contributor Author

@dcampbell24 dcampbell24 left a comment

Choose a reason for hiding this comment

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

I want to get my comments out of "Pending" status.

};
#[cfg(unix)]
#[allow(clippy::used_underscore_binding)]
let usage = FsUsage::new(statfs(_stat_path).ok()?);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's not the case, then why isn't it #[cfg(unix)] and #[cfg(not(unix))].


fn obsolete_result(src: &[&str]) -> Option<Result<Vec<String>, ParseError>> {
Some(Ok(src.iter().map(|s| s.to_string()).collect()))
Some(Ok(src.iter().map(|s| (*s).to_string()).collect()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

inefficient_to_string the compiler specializes the to_string in the changed case: https://rust-lang.github.io/rust-clippy/master/index.html#/to_string.

@BenWiederhake
Copy link
Collaborator

I can't review this, as this touches way too many files at once. Consider splitting this PR into several smaller PRs. That's my personal opinion, and not coordinated with sylvestre or tertsdiepraam, who seem to take no issue with this.

@dcampbell24
Copy link
Contributor Author

tertsdiepraam said to split it up too and that he only found some of the changes agreeable without further consideration. I am going to split up the PR based on his feedback, I just haven't gotten to it yet.

@BenWiederhake
Copy link
Collaborator

Ah, sorry for my duplication then. Awesome!

@cakebaker cakebaker changed the title Clippy Pendantic Clippy Pedantic Oct 4, 2024
@dcampbell24
Copy link
Contributor Author

dcampbell24 commented Oct 13, 2024

This was automatically closed when I tried to force push rebasing and merging with main.

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