Skip to content

Enforce even more library clippy lints in CI - #161328

Open
ChrisDenton wants to merge 34 commits into
rust-lang:mainfrom
ChrisDenton:clippy3
Open

Enforce even more library clippy lints in CI#161328
ChrisDenton wants to merge 34 commits into
rust-lang:mainfrom
ChrisDenton:clippy3

Conversation

@ChrisDenton

@ChrisDenton ChrisDenton commented Aug 18, 2026

Copy link
Copy Markdown
Member

View all comments

Once again, this is best reviewed commit-by-commit since each commit fixes a lint.

I've bundled together a large(ish) number of lints because I feel they shouldn't be controversial and don't touch too much code. A large chunk of them is just telling clippy that, for example, implementing is_digit by calling is_digit just isn't going to work. I have reviewed each and every fix myself but please do double or triple check my working!

@rustbot

rustbot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added 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 Aug 18, 2026
@ChrisDenton

Copy link
Copy Markdown
Member Author

Btw, they'll likely be platform specific fixes that CI tells me about so I'll probably be updating these in a few hours.

Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment on lines +2918 to +2922
match cond {
crate::option::Option::Some(cond) => {
if !cond(&ret) {
// Emit no unwind panic in case this was a safety requirement.
crate::panicking::panic_nounwind("failed ensures check");
}
},
crate::option::Option::None => {},
if let crate::option::Option::Some(cond) = cond {
if !cond(&ret) {
// Emit no unwind panic in case this was a safety requirement.
crate::panicking::panic_nounwind("failed ensures check");
}

@ChrisDenton ChrisDenton Aug 18, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the intrinsic that got people pinged (sorry). If you rather I didn't change this then please say!

View changes since the review

@matthiaskrgr

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 18, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 18, 2026
Enforce even more library clippy lints in CI
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 18, 2026
Comment thread library/core/src/slice/mod.rs Outdated
if next_read != next_write {
let ptr_write = prev_ptr_write.add(1);
mem::swap(&mut *ptr_read, &mut *ptr_write);
ptr::swap(ptr_read, ptr_write);

@ChrisDenton ChrisDenton Aug 18, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This should probably be looked at closer. Clippy says these do the same thing but it's possible going via an &mut is doing something useful.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mem::swap will emit noalias so it assumes the areas don't overlap (thus better opts). I would say it's fine to use swap_nonoverlapping to make clippy happy as well here fwiw

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm, it might be better to not enforce this lint since it's so situational.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this may be a deficiency in the clippy lint? &mut implies nonoverlapping, the lint should probably account for that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, it should.

@nia-e nia-e left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mostly looks good, with a couple worries:

  • clippy wants us to do a lot more method calls. this is fine but needs a perf run for sure, and i'm a smidge worried about binary size and/or bootstrap time, esp since it might put more pressure on the inliner
  • a lot of these allows should be expects with a comment... but also, i'm not gonna do that to you chris ^^ that can be a later pr

let's see what a perf run comes up with before anything.

@bors try @rust-timer queue

View changes since this review

Comment thread library/core/src/char/methods.rs Outdated
@@ -1,5 +1,7 @@
//! impl char {}

#![allow(clippy::manual_is_ascii_check)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this lint worth adding, given that it seems the only change is, uh, allowing it anyway? :D

I suppose there's the point of "let's add this so it doesn't show up in the future" which is fair but I'd like to know if that is indeed your specific intent here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah. A lot of these #[allow] are to stop clippy complaining about the implementation of things it's linting for so when you run x clippy library you don't get a bunch of spurious warnings. I guess it is possible clippy might one day get smarter about this but it's more an us problem rather than a clippy problem per se.

Comment thread library/core/src/num/f32.rs
ret
} else {
match cond {
crate::option::Option::Some(cond) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why isn't this if let $whatever && !cond? of all things I'd expect clippy to yell about this nested if :D

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Clippy moves in mysterious ways. Though it is entirely possible I missed the particular lint that would complain about it.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 18, 2026
Enforce even more library clippy lints in CI
@nia-e

nia-e commented Aug 18, 2026

Copy link
Copy Markdown
Member

huh, how did the comment from matthias not show up? apologies ^^ github has been odd

@rust-log-analyzer

This comment has been minimized.

Comment thread src/bootstrap/src/core/build_steps/clippy.rs Outdated
@rust-bors

rust-bors Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 8906bf7 (8906bf76a8be8117da1f6c656fd34abfa6ebb3a0)
Base parent: e71c0f1 (e71c0f1e3395b10a8c331317be1a5c107bdf7b2e)

@rust-timer

This comment has been minimized.

@clarfonthey

Copy link
Copy Markdown
Contributor

Just comparing to my personal clippy lint list, what I see missing is:

  • borrow_as_ptr
  • default_trait_access
  • doc_markdown
  • filter_map_next
  • if_not_else
  • ignored_unit_patterns
  • inconsistent_struct_constructor
  • manual_assert
  • manual_is_power_of_two
  • map_unwrap_or
  • match_same_arms
  • missing_docs_in_private_items (the spiciest one, imho)
  • `needless_continue
  • needless_raw_string_hashes
  • redundant_closure_for_method_calls
  • redundant_else
  • ref_as_ptr
  • semicolon_if_nothing_returned
  • unnecessary_semicolon

Besides missing_docs_in_private_items being almost certainly undesired at the moment (unless we want more untriaged comments), I haven't actually checked which of these are most reasonable for libstd.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (8906bf7): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (primary 0.9%, secondary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.1%, 2.4%] 2
Regressions ❌
(secondary)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
-1.9% [-1.9%, -1.9%] 1
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) 0.9% [-1.9%, 2.4%] 3

Cycles

This perf run didn't have relevant results for this metric.

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.3% [0.0%, 0.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 21
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 80
All ❌✅ (primary) -0.1% [-0.2%, 0.5%] 23

Bootstrap: 456.919s -> 457.665s (0.16%)
Artifact size: 398.99 MiB -> 398.96 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 19, 2026
@ChrisDenton

Copy link
Copy Markdown
Member Author

a lot of these allows should be expects with a comment... but also, i'm not gonna do that to you chris ^^ that can be a later pr

I went ahead and added a bunch of expect messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

8 participants