diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 7a189ee1f4d05..1d4d9e2128f1b 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); - + // A collision-resistant ident for a lambda, using the user's function name within it to avoid collisions. + 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, )), // ) ], )