Skip to content

Optimize msrv calls (again)#17355

Open
ArhanChaudhary wants to merge 1 commit into
rust-lang:masterfrom
ArhanChaudhary:optimize-msrv2
Open

Optimize msrv calls (again)#17355
ArhanChaudhary wants to merge 1 commit into
rust-lang:masterfrom
ArhanChaudhary:optimize-msrv2

Conversation

@ArhanChaudhary

Copy link
Copy Markdown
Contributor

Address this comment, also taking the opportunity to do some more msrv call optimizations and add it to the documentation.

changelog: none

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 4, 2026
@rustbot

rustbot commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

I will benchmark and profile this (along with my prior PR) tomorrow.

Comment on lines +488 to +490
An important consideration is that `Msrv::meets` is relatively expensive to
call, so you should typically match the MSRV at the end of an if let chain,
after other short-circuiting checks.

@Jarcho Jarcho Jul 6, 2026

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 is only partially correct. Msrv::meets only slow if the crate has a clippy::msrv attribute which is becoming less common ever since Cargo.toml got the msrv field. This slowness could even be mostly fixed if it were an unavoidable issue.

The biggest issue with it is that it's just not a good filter. The MSRV being set to whatever the current version is very common and makes this filter out nothing. Even for (actively developed) crates which set an MSRV, it's not usually more than a couple years old. This not only makes most checks not filter anything out, but the total number of ineffective filters grows over time.

View changes since the review

Comment on lines +22 to 24
&& specializes_tostring(cx, deref_self_ty)
// Since Rust 1.82, the specialized `ToString` is properly called
&& !msrv.meets(cx, msrvs::SPECIALIZED_TO_STRING_FOR_REFS)

@Jarcho Jarcho Jul 6, 2026

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.

I wouldn't touch this one. The msrv check is doing the opposite of what we normally do which undermines a large part of the argument for pushing the check later.

View changes since the review

Comment on lines +32 to 34
&& let Some(args_snip) = closure.fn_arg_span.and_then(|fn_arg_span| fn_arg_span.get_text(cx))
&& msrv.meets(cx, msrvs::ITERATOR_TRY_FOLD)
&& !is_from_proc_macro(cx, expr)

@Jarcho Jarcho Jul 6, 2026

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.

Don't move this one. Taking a snippet for a suggestions should happen after the everything else.

View changes since the review

Comment on lines +36 to 38
&& let Some(scrutinee_snip) = scrutinee.span.get_text(cx)
&& msrv.meets(cx, msrvs::MATCHES_MACRO)
&& !is_from_proc_macro(cx, expr)

@Jarcho Jarcho Jul 6, 2026

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.

Don't move this one as it's a snippet.

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 6, 2026
@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants