From c92aefc2997a6fb6a0c8938c2ec4b69f2f47f94d Mon Sep 17 00:00:00 2001 From: MolecularPilot Date: Thu, 30 Oct 2025 17:36:11 +1100 Subject: [PATCH 1/3] rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names --- compiler/rustc_builtin_macros/src/test.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 7a189ee1f4d05..40b348c05b06e 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -207,9 +207,9 @@ pub(crate) fn expand_test_or_bench( }; let test_fn = if is_bench { - // A simple ident for a lambda - let b = Ident::from_str_and_span("b", attr_sp); - + // A simple ident for a lambda, using the user's function name within it to avoid collisons. + let param_name = format!("__bench_{}", fn_.ident.name); + let bencher_param = Ident::new(Symbol::intern(¶m_name), attr_sp); cx.expr_call( sp, cx.expr_path(test_path("StaticBenchFn")), @@ -226,11 +226,11 @@ pub(crate) fn expand_test_or_bench( cx.expr_call( ret_ty_sp, cx.expr_path(cx.path(sp, vec![fn_.ident])), - thin_vec![cx.expr_ident(sp, b)], + thin_vec![cx.expr_ident(sp, bencher_param)], ), ], ), - b, + bencher_param, )), // ) ], ) From ebe155a549c24dd04a532e1edcc1736d46488549 Mon Sep 17 00:00:00 2001 From: MolecularPilot Date: Thu, 30 Oct 2025 17:51:49 +1100 Subject: [PATCH 2/3] fix typo in comment --- compiler/rustc_builtin_macros/src/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 40b348c05b06e..2891c1095cf4a 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -207,7 +207,7 @@ pub(crate) fn expand_test_or_bench( }; let test_fn = if is_bench { - // A simple ident for a lambda, using the user's function name within it to avoid collisons. + // A simple ident for a lambda, using the user's function name within it to avoid collisions. let param_name = format!("__bench_{}", fn_.ident.name); let bencher_param = Ident::new(Symbol::intern(¶m_name), attr_sp); cx.expr_call( From 7f382acfd2af3e420b5629aa9622d8b20cadc222 Mon Sep 17 00:00:00 2001 From: MolecularPilot Date: Fri, 31 Oct 2025 19:03:54 +1100 Subject: [PATCH 3/3] nit: continue using from_str_and_span as requested --- compiler/rustc_builtin_macros/src/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 2891c1095cf4a..6163ed12fcd8d 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -209,7 +209,7 @@ pub(crate) fn expand_test_or_bench( let test_fn = if is_bench { // A simple ident for a lambda, using the user's function name within it to avoid collisions. let param_name = format!("__bench_{}", fn_.ident.name); - let bencher_param = Ident::new(Symbol::intern(¶m_name), attr_sp); + let bencher_param = Ident::from_str_and_span(¶m_name, attr_sp); cx.expr_call( sp, cx.expr_path(test_path("StaticBenchFn")),