Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 collisions.
let param_name = format!("__bench_{}", fn_.ident.name);
let bencher_param = Ident::new(Symbol::intern(&param_name), attr_sp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change it from from_str_and_span to new + intern?

Copy link
Author

@IntegralPilot IntegralPilot Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s mostly a style preference, @oli-obk. Since format! gives us a String (unlike the old str), we still need either a conversion or an interning step - from_str_and_span would need a .as_str() call, while new needs a Symbol::intern call. So from_str_and_span doesn’t really simplify anything, and I think the explicit intern call makes it flow a bit clearer and cleaner than a conversion, and also separates the logical steps of building the string and then interning it. That said, if you’d rather keep from_str_and_span and just add .as_str() for consistency, I’m good with that too, I really don't mind. Thank you for your time in reviewing! 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use &format...?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work to as well I think, I considered that but preferred the explicit intern style. I'm fine with whatever everyone else wants to go for. :)

cx.expr_call(
sp,
cx.expr_path(test_path("StaticBenchFn")),
Expand All @@ -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,
)), // )
],
)
Expand Down
Loading