Skip to content

Can't #[bench] a function named b #148275

@theemathas

Description

@theemathas
#![feature(test)] extern crate test; #[bench] fn b(_: &mut test::bench::Bencher) {}

I should be able to run this as a benchmark, but I got the following error:

error[E0308]: mismatched types --> src/lib.rs:6:1 | 5 | #[bench] | -------- in this attribute macro expansion 6 | fn b(_: &mut test::bench::Bencher) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | expected `&mut Bencher`, found `TestDescAndFn` | expected due to this | constant defined here | `b` is interpreted as a constant, not a new binding | help: introduce a new binding instead: `other_b` error[E0308]: mismatched types --> src/lib.rs:6:1 | 5 | #[bench] | -------- in this attribute macro expansion 6 | fn b(_: &mut test::bench::Bencher) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | expected `&mut Bencher`, found `TestDescAndFn` | arguments to this function are incorrect | note: function defined here --> src/lib.rs:6:4 | 6 | fn b(_: &mut test::bench::Bencher) {} | ^ ---------------------------- For more information about this error, try `rustc --explain E0308`. 

It seems that the macro expansion of #[bench] has a name collision with a variable named b.

// A simple ident for a lambda
let b = Ident::from_str_and_span("b", attr_sp);
cx.expr_call(
sp,
cx.expr_path(test_path("StaticBenchFn")),
thin_vec![
// #[coverage(off)]
// |b| self::test::assert_test_result(

Meta

Reproducible on the playground with version 1.93.0-nightly (2025-10-28 278a90913daf77077910) (click on the three dots on top left -> "test")

Metadata

Metadata

Assignees

Labels

A-hygieneArea: Macro hygieneA-libtestArea: `#[test]` / the `test` libraryA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions