-
Notifications
You must be signed in to change notification settings - Fork 13.9k
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names #148279
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
base: master
Are you sure you want to change the base?
Conversation
… user-defined function names
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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.
|
r? hkBst |
|
Failed to set assignee to
|
|
oh heh @bors delegate=hkBst |
| // 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. |
There was a problem hiding this comment.
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.
| // 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 |
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 distinctfrom the user’s function.
Because the prefix is applied recursively (e.g. benchmarking
__bench_bproduces a lambda ident
__bench___bench_b), there is no possible functionname 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.