Skip to content

Commit c92aefc

Browse files
committed
rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names
1 parent 292be5c commit c92aefc

File tree

1 file changed

+5
-5
lines changed
  • compiler/rustc_builtin_macros/src

1 file changed

+5
-5
lines changed

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ pub(crate) fn expand_test_or_bench(
207207
};
208208

209209
let test_fn = if is_bench {
210-
// A simple ident for a lambda
211-
let b = Ident::from_str_and_span("b", attr_sp);
212-
210+
// A simple ident for a lambda, using the user's function name within it to avoid collisons.
211+
let param_name = format!("__bench_{}", fn_.ident.name);
212+
let bencher_param = Ident::new(Symbol::intern(&param_name), attr_sp);
213213
cx.expr_call(
214214
sp,
215215
cx.expr_path(test_path("StaticBenchFn")),
@@ -226,11 +226,11 @@ pub(crate) fn expand_test_or_bench(
226226
cx.expr_call(
227227
ret_ty_sp,
228228
cx.expr_path(cx.path(sp, vec![fn_.ident])),
229-
thin_vec![cx.expr_ident(sp, b)],
229+
thin_vec![cx.expr_ident(sp, bencher_param)],
230230
),
231231
],
232232
),
233-
b,
233+
bencher_param,
234234
)), // )
235235
],
236236
)

0 commit comments

Comments
 (0)