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

Fix some clippy lints for library/std/src/sys/windows #118154

Merged
merged 17 commits into from
Nov 23, 2023

Conversation

ChrisDenton
Copy link
Contributor

These issues were shown by running x clippy on library/std and filtering for windows/ paths. I think running clippy on the full std would be great but I wanted to start smaller and with something that's hopefully easier to review. It'd be good to eventually run clippy in CI but that's a bigger conversation.

I've created separate commits for each clippy lint fixed (with the commit title set to the lint name) and reviewed the changes myself. Most of the fixes here are trivial.

r? libs

We intentional use the Windows API style here.
@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 22, 2023
@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Contributor Author

I was so busy playing with clippy that I forgot fmt.

@matthiaskrgr
Copy link
Member

should definitely get a perf run when you think its ready.

@ChrisDenton
Copy link
Contributor Author

A perf run is very unlikely to show any changes seeing as this is Windows only. Also I'm not really convinced any of these lints would affect perf. I think the only ones that might potentially (and I'm sceptical) are unnecessary_lazy_evaluations, manual_slice_size_calculation, duration_subsec and manual_range_contains. Of those, only manual_range_contains is in perf sensitive code (utf-8 <--> utf-16 conversion).

unneeded `return` statement
This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references.
the borrowed expression implements the required traits
this expression creates a reference which is immediately dereferenced by the compiler
casting to the same type is unnecessary
calling `subsec_micros()` is more concise than this calculation
unnecessary closure used with `bool::then`
manual implementation of `Option::map`
taken reference of right operand
comparing with null is better expressed by the `.is_null()` method
if first_code_unit_remaining >= 0xDCEE && first_code_unit_remaining <= 0xDFFF {
if matches!(first_code_unit_remaining, 0xDCEE..=0xDFFF) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed that using matches! is exactly equivalent to using a manual if (in terms of codegen) and I do think it's clearer.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, so long as there's only a single range in the matches! then it's just as good.

(If there's multiple then things get complicated, see #103024 (comment) if you're curious.)

@@ -156,7 +156,7 @@ impl DirEntry {
}

pub fn path(&self) -> PathBuf {
self.root.join(&self.file_name())
self.root.join(self.file_name())
Copy link
Member

Choose a reason for hiding this comment

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

Can we uplift this clippy lint? 🙂

(Not in this PR, obviously)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's needless_borrows_for_generic_args. There's also the related needless_borrow which found a lot too!

@@ -36,7 +36,7 @@ impl<'a> IoSlice<'a> {

#[inline]
pub fn as_slice(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) }
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is PSTR, which is defined as *mut u8, so the change is fine, but I wonder if it's "really" *mut u8 vs *mut c_char, since the latter might want to be signed char, and where this cast would actually do something.

Since it's not using c_char today, though, it's probably fine, since casts can be added back if it's ever relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. Though we're a bit at the mercy of the win32metadata project here (which is what our bindings are ultimately generated from) which might not necessarily follow what we think a c_char is (as it has no particular need to follow C).

@scottmcm
Copy link
Member

This all looks good to me! Nice work.

r? @scottmcm
@bors r+ rollup=iffy (it's all windows, so the PR build doesn't check much)

@bors
Copy link
Contributor

bors commented Nov 22, 2023

📌 Commit b9fe367 has been approved by scottmcm

It is now in the queue for this repository.

@rustbot rustbot assigned scottmcm and unassigned joshtriplett Nov 22, 2023
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 22, 2023
@bors
Copy link
Contributor

bors commented Nov 22, 2023

⌛ Testing commit b9fe367 with merge f3c5bff...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 22, 2023
Fix some clippy lints for library/std/src/sys/windows

These issues were shown by running `x clippy` on `library/std` and filtering for `windows/` paths. I think running clippy on the full std would be great but I wanted to start smaller and with something that's hopefully easier to review. It'd be good to eventually run clippy in CI but that's a bigger conversation.

I've created separate commits for each clippy lint fixed (with the commit title set to the lint name) and reviewed the changes myself. Most of the fixes here are trivial.

r? libs
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_codegen_ssa test:false 102.204
   Compiling rustc_hir_typeck v0.0.0 (/checkout/compiler/rustc_hir_typeck)
[RUSTC-TIMING] rustc_codegen_llvm test:false 87.695
   Compiling rustc_mir_transform v0.0.0 (/checkout/compiler/rustc_mir_transform)
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.
##[group]Clock drift check
##[group]Clock drift check
Session terminated, killing shell... ...killed.
  network time: 
##[error]The operation was canceled.
Cleaning up orphan processes

@bors
Copy link
Contributor

bors commented Nov 23, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 23, 2023
@ChrisDenton
Copy link
Contributor Author

@bors retry that looks spurious "[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled."

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 23, 2023
@bors
Copy link
Contributor

bors commented Nov 23, 2023

⌛ Testing commit b9fe367 with merge c387f01...

@bors
Copy link
Contributor

bors commented Nov 23, 2023

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing c387f01 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 23, 2023
@bors bors merged commit c387f01 into rust-lang:master Nov 23, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 23, 2023
@ChrisDenton ChrisDenton deleted the win-clippy branch November 23, 2023 02:32
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c387f01): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
0.8% [0.8%, 0.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [2.3%, 2.3%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 675.896s -> 674.393s (-0.22%)
Artifact size: 313.66 MiB -> 313.69 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants