Skip to content

regression: error: module should be marked with the #[cfg(test)] attribute #140225

Closed

Description

@cuviper
[INFO] [stdout] error: module should be marked with the `#[cfg(test)]` attribute
[INFO] [stdout]        
[INFO] [stdout]          = help: add `#[cfg(test)]` to the module
[INFO] [stdout]        
[INFO] [stdout]   --> crates/after-test_test/src/lib.rs:3:1
[INFO] [stdout]    |
[INFO] [stdout] 3  | / mod panics {
[INFO] [stdout] 4  | |     fn panic_with_message() {
[INFO] [stdout] 5  | |         panic!("This is a panic message");
[INFO] [stdout] ...  |
[INFO] [stdout] 10 | |     fn test_should_panic() {}
[INFO] [stdout] 11 | | }
[INFO] [stdout]    | |_^

(and several more like that)

That particular error message comes from their own proc-macro. The module does have the expected attribute, but I suppose something must have changed in how we provide that to the macro.

#[after_test::cleanup(panic_with_message)]
#[cfg(test)]
mod panics {
    fn panic_with_message() {
        panic!("This is a panic message");
    }

    #[test]
    #[should_panic(expected = "This is a panic message")]
    fn test_should_panic() {}
}

Version it worked on

It most recently worked on: 1.86.0

Version with regression

rustc 1.87.0-beta.5 (386abeb93 2025-04-19) in crater #139827.

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Apr 23, 2025
  2. added this to the 1.87.0 milestone on Apr 23, 2025
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Apr 23, 2025
  4. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Apr 23, 2025
  5. cyrgani commented on Apr 23, 2025

    @cyrgani
    Contributor

    cargo test with the following reduced macro:

    use proc_macro::TokenStream;
    
    #[proc_macro_attribute]
    pub fn cleanup(_: TokenStream, item: TokenStream) -> TokenStream {
        dbg!(&item);
        TokenStream::new()
    }

    and usage

    #[y::cleanup]
    #[cfg(test)]
    mod panics {}

    beta is indeed just printing

    [src/lib.rs:5:5] &item = TokenStream [
        Ident {
            ident: "mod",
            span: #0 bytes(41..44),
        },
        Ident {
            ident: "panics",
            span: #0 bytes(45..51),
        },
        Group {
            delimiter: Brace,
            stream: TokenStream [],
            span: #0 bytes(52..54),
        },
    ]
    

    but stable gets

    [src/lib.rs:5:5] &item = TokenStream [
        Punct {
            ch: '#',
            spacing: Alone,
            span: #0 bytes(28..29),
        },
        Group {
            delimiter: Bracket,
            stream: TokenStream [
                Ident {
                    ident: "cfg",
                    span: #0 bytes(30..33),
                },
                Group {
                    delimiter: Parenthesis,
                    stream: TokenStream [
                        Ident {
                            ident: "test",
                            span: #0 bytes(34..38),
                        },
                    ],
                    span: #0 bytes(33..39),
                },
            ],
            span: #0 bytes(29..40),
        },
        Ident {
            ident: "mod",
            span: #0 bytes(41..44),
        },
        Ident {
            ident: "panics",
            span: #0 bytes(45..51),
        },
        Group {
            delimiter: Brace,
            stream: TokenStream [],
            span: #0 bytes(52..54),
        },
    ]
    
  6. cyrgani commented on Apr 23, 2025

    @cyrgani
    Contributor

    Regression in rust-lang-ci@8d60e92
    The PR introducing the regression in this rollup is #138844: expand: Leave traces when expanding cfg attributes

    searched nightlies: from nightly-2025-01-01 to nightly-2025-04-23
    regressed nightly: nightly-2025-03-28
    searched commit range: a2e6356...3f55023
    regressed commit: 3f55023

    bisected with cargo-bisect-rustc v0.6.9

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --start=2025-01-01 -- test 

    @rustbot label S-has-mcve S-has-bisection

  7. added
    S-has-bisectionStatus: A bisection has been found for this issue
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Apr 23, 2025
  8. jieyouxu commented on Apr 24, 2025

    @jieyouxu
    Member

    This needs a crater run, because it changes observable behavior (in an intended way) - proc macros can no longer see expanded cfg(true) attributes.

    cc @petrochenkov: can you please double-check if this is intended observable behavior change re. #138844.

  9. added
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    A-cfgArea: `cfg` conditional compilation
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 24, 2025
  10. jieyouxu commented on Apr 24, 2025

    @jieyouxu
    Member

    I also tagged #138844 w/ compat relnotes (#140243) to be safe.

  11. petrochenkov commented on Apr 24, 2025

    @petrochenkov
    Contributor

    This needs a crater run, because it changes observable behavior (in an intended way) - proc macros can no longer see expanded cfg(true) attributes.

    cc @petrochenkov: can you please double-check if this is intended observable behavior change re. #138844.

    Yes, this is an intended change.

  12. jieyouxu commented on May 1, 2025

    @jieyouxu
    Member

    Closing in favor of compat relnotes (#140243) since this is an intended change.

  13. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-cfgArea: `cfg` conditional compilationA-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions