From 67802e0494034e1c55205a178b2ee1843e6d39da Mon Sep 17 00:00:00 2001 From: MolecularPilot Date: Thu, 30 Oct 2025 17:36:11 +1100 Subject: [PATCH] rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names --- compiler/rustc_builtin_macros/src/test.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 7a189ee1f4d05..b0155fad139b8 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -207,30 +207,30 @@ 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); - + // avoid name collisions by using the function name within the identifier, see bug #148275 + let bencher_param = + Ident::from_str_and_span(&format!("__bench_{}", fn_.ident.name), attr_sp); cx.expr_call( sp, cx.expr_path(test_path("StaticBenchFn")), thin_vec![ // #[coverage(off)] - // |b| self::test::assert_test_result( + // |__bench_fn_name| self::test::assert_test_result( coverage_off(cx.lambda1( sp, cx.expr_call( sp, cx.expr_path(test_path("assert_test_result")), thin_vec![ - // super::$test_fn(b) + // super::$test_fn(__bench_fn_name) 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, )), // ) ], )