- Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-hygieneArea: Macro hygieneArea: Macro hygieneA-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` libraryA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.Relevant 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.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
#![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.
rust/compiler/rustc_builtin_macros/src/test.rs
Lines 210 to 218 in 292be5c
| // 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")
SabrinaJewson, IntegralPilot, homomorphist, zachs18, Scripter17 and 2 more
Metadata
Metadata
Assignees
Labels
A-hygieneArea: Macro hygieneArea: Macro hygieneA-libtestArea: `#[test]` / the `test` libraryArea: `#[test]` / the `test` libraryA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.Relevant 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.This issue may need triage. Remove it if it has been sufficiently triaged.
Type
Projects
Status
No status