-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Major clippy overhaul. #2298
Major clippy overhaul. #2298
Conversation
* add "clippy.toml" in order to set MSRV for clippy linting this works only if clippy is invoked with "+nightly" * add "--target" to clippy in order to also lint tests
linting for all targets
Add a test for when the reference file is not found and both `-r` and `-s` options are given on the command-line.
Remove "read" permissions from the `OpenOptions` when opening a new file just to truncate it. We will never read from the file, only write to it. (Specifically, we will only call `File::set_len()`.)
Add a helper function to contain the code for parsing the size and the modifier symbol, if any. This commit also changes the `TruncateMode` enum so that the parameter for each "mode" is stored along with the enumeration value. This is because the parameter has a different meaning in each mode.
Create a method that computes the final target size in bytes for the file to truncate, given the reference file size and the parameter to the `TruncateMode`.
Reorganize the code in `truncate.rs` into three distinct functions representing the three modes of operation of the `truncate` program. The three modes are - `truncate -r RFILE FILE`, which sets the length of `FILE` to match the length of `RFILE`, - `truncate -r RFILE -s NUM FILE`, which sets the length of `FILE` relative to the given `RFILE`, - `truncate -s NUM FILE`, which sets the length of `FILE` either absolutely or relative to its curent length. This organization of the code makes it more concise and easier to follow.
@@ -1089,7 +1089,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu | |||
} | |||
|
|||
#[cfg(not(windows))] | |||
#[allow(clippy::unnecessary_wraps)] // needed for windows version | |||
#[allow(clippy::unnecessary_unwrap)] // needed for windows version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this allow needed? Also, it seems like we're not handling errors in symlink_file
for linux/macos, but always returning Ok(()). Maybe it should be the same as for windows below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't checked yet (it's so cumbersome to boot up a windows VM).
I also noticed errors are not handled in symlink_file
, however there's an 'unwrap' which should be enough, i.e. print the error message and then panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand. Which unwrap
are you referring to? Any error from the call to std::os::unix::fs::symlink(source, dest).context(context)
is not handled, or am I missing something?
Also, you changed this from unnecessary_wraps
to unnecessary_unwrap
, but... there's no unwrap in here. That's what confused me. Anyways,I'm booting up my windows VM to check :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this allow doesn't make clippy complain on windows (checked in a VM).
However, there are two other warnings:
warning: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> src\uu\du\src/du.rs:150:27
|
150 | fn get_size_on_disk(path: &PathBuf) -> u64 {
| ^^^^^^^^ help: change this to: `&Path`
|
= note: `#[warn(clippy::ptr_arg)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
warning: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
--> src\uu\du\src/du.rs:182:24
|
182 | fn get_file_info(path: &PathBuf) -> Option<FileInfo> {
| ^^^^^^^^ help: change this to: `&Path`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
warning: 2 warnings emitted
With stable there is another one:
warning: name `DWORD` contains a capitalized acronym
--> src\uu\rm\src/rm.rs:406:14
|
406 | pub type DWORD = c_ulong;
| ^^^^^ help: consider making the acronym lowercase, except the initial letter: `Dword`
|
= note: `#[warn(clippy::upper_case_acronyms)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms
warning: 1 warning emitted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand. Which unwrap are you referring to? Any error from the call to std::os::unix::fs::symlink(source, dest).context(context) is not handled, or am I missing something?
Oh, I was referring to L539:
coreutils/tests/common/util.rs
Lines 533 to 540 in 3d42d41
pub fn symlink_file(&self, src: &str, dst: &str) { | |
log_info( | |
"symlink", | |
&format!("{},{}", self.plus_as_string(src), self.plus_as_string(dst)), | |
); | |
symlink_file(&self.plus(src), &self.plus(dst)).unwrap(); | |
} |
Also, you changed this from unnecessary_wraps to unnecessary_unwrap, but... there's no unwrap in here. That's what confused me.
Clippy complained that there's no unnecessary_wraps
, I thought it's a typo and followed clippy's suggestion to use unnecessary_unwrap
. However, now that you mention it, I checked and unnecessary_wraps
does indeed exit. Strange.
There is:
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
Jan Scheer ***@***.***> schrieb am Sa., 29. Mai 2021, 19:08:
… ***@***.**** commented on this pull request.
------------------------------
In src/uu/cp/src/cp.rs
<#2298 (comment)>:
> @@ -1089,7 +1089,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
}
#[cfg(not(windows))]
-#[allow(clippy::unnecessary_wraps)] // needed for windows version
+#[allow(clippy::unnecessary_unwrap)] // needed for windows version
I'm not sure I understand. Which unwrap are you referring to? Any error
from the call to std::os::unix::fs::symlink(source, dest).context(context)
is not handled, or am I missing something?
Oh, I was referring to L539:
https://github.com/uutils/coreutils/blob/3d42d41a72e7f43d6d5a88d73eed4dae181f7dc9/tests/common/util.rs#L533-L540
Also, you changed this from unnecessary_wraps to unnecessary_unwrap,
but... there's no unwrap in here. That's what confused me.
There is no unnecessary_wraps, probably a typo and clippy's suggestion
was to use unnecessary_unwrap.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2298 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKQ77NSAOPTRA6A6MRBEY6TTQENRNANCNFSM45XTOCSA>
.
|
There were severe problems with our clippy linting:
This PR:
clippy.toml
to be able to set MSRV for clippy. However, this only works if clippy is invoked like this:cargo +nightly clippy
.--target=${{ matrix.job.target }}
to github actions (I hope this is enough, locally I runcargo +nightly clippy --all-targets --all-features