Skip to content

Conversation

@IntegralPilot
Copy link

@IntegralPilot IntegralPilot commented Oct 30, 2025

Resolves #148275 by preventing name collisions in the #[bench] macro.

Previously, a user-defined function named "b" could not be benchmarked because
the macro-generated lambda identity collided with the same name. We now generate
the lambda ident as __bench_<function_name>, ensuring it is always distinct
from the user’s function.

Because the prefix is applied recursively (e.g. benchmarking __bench_b
produces a lambda ident __bench___bench_b), there is no possible function
name that can equal its corresponding lambda ident. This guarantees that
the user can safely bench a function of any valid name without risk of
identifier collision.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

r? @jackh726

rustbot has assigned @jackh726.
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

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@hkBst hkBst left a comment

Choose a reason for hiding this comment

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

LGTM except for a small style nit as mentioned above.

View changes since this review

@oli-obk
Copy link
Contributor

oli-obk commented Oct 31, 2025

r? hkBst

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

Failed to set assignee to hkBst: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 31, 2025

oh heh

@bors delegate=hkBst

@bors
Copy link
Collaborator

bors commented Oct 31, 2025

✌️ @hkBst, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, please make that change, then do @bors r=@oli-obk

@jackh726 jackh726 assigned oli-obk and unassigned jackh726 Nov 3, 2025
@IntegralPilot IntegralPilot requested a review from hkBst November 5, 2025 11:41
// A simple ident for a lambda
let b = Ident::from_str_and_span("b", attr_sp);

// A collision-resistant ident for a lambda, using the user's function name within it to avoid collisions.
Copy link
Member

Choose a reason for hiding this comment

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

this is now repeating "collision", and should probably also link to the bug this solves.

Suggested change
// A collision-resistant ident for a lambda, using the user's function name within it to avoid collisions.
// try to avoid name collisions, see bug #148275

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't #[bench] a function named b

7 participants