Conversation
|
I don't have a windows machine and don't understand why the windows checks are failing. |
|
GNU testsuite comparison: |
src/uu/chroot/src/chroot.rs
Outdated
|
|
||
| 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(), |
There was a problem hiding this comment.
i would prefer just
String::as_str
and have an import
repeating std::string isn't providing much value
src/uu/cp/src/copydir.rs
Outdated
| 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) |
There was a problem hiding this comment.
same comment about Path
| root_path.parent().map(std::path::Path::to_path_buf) | |
| root_path.parent().map(Path::to_path_buf) |
|
For the windows error, you can test using MS images: Here, for this error, the type is probably different on windows vs linux |
src/uu/fmt/src/fmt.rs
Outdated
| (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)); |
There was a problem hiding this comment.
not sure to see the improvement here
There was a problem hiding this comment.
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.
tertsdiepraam
left a comment
There was a problem hiding this comment.
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()?); |
There was a problem hiding this comment.
Is there are reason to keep this as an underscore?
There was a problem hiding this comment.
If I change it to not an underscore, then I would have to add #[allow(unused_variables)] to the windows side of things.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
If that's not the case, then why isn't it #[cfg(unix)] and #[cfg(not(unix))].
There was a problem hiding this comment.
Probably should be yeah!
src/uu/fmt/src/fmt.rs
Outdated
| (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)); |
There was a problem hiding this comment.
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.
src/uu/fmt/src/parasplit.rs
Outdated
| .opts | ||
| .prefix | ||
| .as_ref() | ||
| .map_or(0, std::string::String::len)..] |
There was a problem hiding this comment.
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.
src/uu/head/src/parse.rs
Outdated
|
|
||
| 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())) |
There was a problem hiding this comment.
What clippy lint triggered this? It seems to make it more complicted.
There was a problem hiding this comment.
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.
|
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. |
|
make a backup and: |
dcampbell24
left a comment
There was a problem hiding this comment.
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()?); |
There was a problem hiding this comment.
If that's not the case, then why isn't it #[cfg(unix)] and #[cfg(not(unix))].
src/uu/head/src/parse.rs
Outdated
|
|
||
| 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())) |
There was a problem hiding this comment.
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.
|
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. |
|
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. |
|
Ah, sorry for my duplication then. Awesome! |
418cd10 to
3c26dd8
Compare
|
This was automatically closed when I tried to force push rebasing and merging with main. |
I ran
cargo clippy --workspace --all-targets --all-features -- --warn clippy::LINTfor all the lints listed in the below thread. I can't figure out what is different about running clippy through the filepre-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.