Rust-GCC / Rust-GCC/gccrs

Test-harness attribute macros are stripped before HIR, blocking duplicate_macro_attributes lint

Open
#4,655 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

missing-lint
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

While porting rustc warn-by-default lints, duplicate_macro_attributes cannot be implemented because the attributes it targets are gone by the time the HIR is built.

rustc scopes duplicate_macro_attributes to the built-in test-harness attribute macros: test, bench, test_case, cfg_eval. A lint needs to scan an item's outer attributes and warn when one of those appears twice.

In gccrs these attributes are stripped before HIR. A function lowered from:

#[test]
#[test]
pub fn foo() {}

has an empty get_outer_attrs() at the lint stage, whereas #[inline] / #[cold] survive. So the lint has nothing to inspect.

If the test-harness attributes were preserved on the HIR (or surfaced some other way), the lint would be straightforward.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the gccrs lowering path where test-harness attributes are stripped before HIR, then inspect the HIR item's get_outer_attrs() behavior at the lint stage. The work is done when attributes such as test, bench, test_case, and cfg_eval remain available, or are surfaced another way, so duplicate occurrences can be inspected by the lint.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.