Skip to content

RA improperly picking up ignore in #[cfg_attr(miri, ignore)] on tests in VS Code #20580

@John-Robbins

Description

@John-Robbins

rust-analyzer version: 0.3.2593-standalone (XXXXXXXXXX 2025-08-25) [/Users/somedude/.vscode/extensions/rust-lang.rust-analyzer-0.3.2593-darwin-arm64/server/rust-analyzer]
VS Code version: Version: 1.103.2 (Universal)

In my project, I run Miri frequently and with its limitations, it's important to mark the tests that Miri can't handle with the #[cfg_attr(miri, ignore)] attribute. Unfortunately, rust-analyzer, picks up the ignore when it should not because the cfg_attr is not active. When clicking on the Run Test or Debug link above the test and the test does not run because rust-analyzer thinks it is ignored.

Steps to Reproduce

  1. Set up an test on a project. The reproduces for unit and integration tests.

  2. Add the #[cfg_attr(miri, ignore)] attribute to a test like the following.

    # [test]
    # [cfg_attr(miri, ignore)]
    fn quit_test() {
    // --snip--snip--snip    
  3. Open the test in the latest Visual Studio Code and the latest rust-analyzer installed.

  4. Go to the test with the Miri attribute and click the "Run test" link in the editor.

  5. Rust-analyzer will run the test with the following command.

    cargo test --package rl --test harness_tests -- quit_test --exact --show-output --ignored
    
  6. This shows how the --ignored switch is being added even though the cfg_attr is not applicable.

  7. Remove the # [cfg_attr(miri, ignore)] in the code.

  8. Click the "Run test" link.

  9. The test command no longer shows the --ignored, and the test runs correctly.

    cargo test --package rl --test harness_tests -- quit_test --exact --show-output
    

Ideally, rust-analyzer would take into account the build configuration and discard the ignore if the build configuration is not active.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions