Skip to content

suggest adding #[test] on otherwise-dead code that looks like a test? #33166

Closed
@sourcefrog

Description

@sourcefrog

On this code:

#[cfg(test)]
mod tests {

    pub fn test_addition() {
        assert_eq!(2+2, 4);
    }
}

I currently get

function is never used: `test_addition`, #[warn(dead_code)] on by default

What I need here is a #[test] before the function of course. Perhaps rustc could suggest this if some of the following hints are seen

  • it's in #[cfg(test)]
  • it's in a submodule tests
  • the function's called test_*

I don't know if making suggestions based on names is considered unhygienic, but this would remove a small speed bump for new users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions