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
@hkBst
Copy link
Member

hkBst commented Nov 7, 2025

Looks fine now, but please squash your commits.

@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@IntegralPilot
Copy link
Author

@hkBst, just squashed the commits! Thanks again for your review & help :)

@hkBst
Copy link
Member

hkBst commented Nov 8, 2025

@bors r=@hkBst

@bors
Copy link
Collaborator

bors commented Nov 8, 2025

📌 Commit 67802e0 has been approved by hkBst

It is now in the queue for this repository.

@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 8, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 8, 2025
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names

Resolves rust-lang#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.
bors added a commit that referenced this pull request Nov 8, 2025
Rollup of 16 pull requests

Successful merges:

 - #147534 (Implement SIMD funnel shifts in const-eval/Miri)
 - #147686 (update isolate_highest_one for NonZero<T>)
 - #148020 (Show backtrace on allocation failures when possible)
 - #148204 (Modify contributor email entries in .mailmap)
 - #148230 (rustdoc: Properly highlight shebang, frontmatter & weak keywords in source code pages and code blocks)
 - #148279 (rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names)
 - #148555 (Fix rust-by-example spanish translation)
 - #148556 (Fix suggestion for returning async closures)
 - #148585 ([rustdoc] Replace `print` methods with functions to improve code readability)
 - #148600 (re-use `self.get_all_attrs` result for pass indirectly attribute)
 - #148612 (Add note for identifier with attempted hygiene violation)
 - #148613 (Switch hexagon targets to rust-lld)
 - #148619 (Enable std locking functions on AIX)
 - #148644 ([bootstrap] Make `--open` option work with `doc src/tools/error_index_generator`)
 - #148649 (don't completely reset `HeadUsages`)
 - #148675 (Remove eslint-js from npm dependencies)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 8, 2025
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names

Resolves rust-lang#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.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 8, 2025
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names

Resolves rust-lang#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.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 8, 2025
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names

Resolves rust-lang#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.
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 9, 2025
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names

Resolves rust-lang#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.
bors added a commit that referenced this pull request Nov 9, 2025
Rollup of 22 pull requests

Successful merges:

 - #128666 (Add `overflow_checks` intrinsic)
 - #146305 (Add correct suggestion for multi-references for self type in method)
 - #147179 ([DebugInfo] Fix container types failing to find template args)
 - #147743 (Show packed field alignment in mir_transform_unaligned_packed_ref)
 - #148079 (Rename `downcast_[ref|mut]_unchecked` -> `downcast_unchecked_[ref|mut]`)
 - #148084 (Optimize path components iteration on platforms that don't have prefixes)
 - #148126 (Fix rust stdlib build failing for VxWorks)
 - #148204 (Modify contributor email entries in .mailmap)
 - #148279 (rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names)
 - #148333 (constify result unwrap unchecked)
 - #148539 (Add Allocator proxy impls for Box, Rc, and Arc)
 - #148601 (`invalid_atomic_ordering`: also lint `update` & `try_update`)
 - #148612 (Add note for identifier with attempted hygiene violation)
 - #148613 (Switch hexagon targets to rust-lld)
 - #148619 (Enable std locking functions on AIX)
 - #148644 ([bootstrap] Make `--open` option work with `doc src/tools/error_index_generator`)
 - #148649 (don't completely reset `HeadUsages`)
 - #148673 (Remove a remnant of `dyn*` from the parser)
 - #148675 (Remove eslint-js from npm dependencies)
 - #148680 (Recover `[T: N]` as `[T; N]`)
 - #148688 (Remove unused argument `features` from `eval_config_entry`)
 - #148711 (Use the current lint note id when parsing `cfg!()`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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