Skip to content

Incorrect unused_import lint firing for a function-local macro_rules! #78894

Closed

Description

I tried this code:

fn main ()
{
    m!();
    // where
    macro_rules! m {
        () => ();
    } use m;
}

I expected to see this happen: no warning.

Instead, this happened: I get a warning saying:

warning: the item `m` is imported redundantly
 --> src/main.rs:7:11
  |
5 | /     macro_rules! m {
6 | |         () => ();
7 | |     } use m;
  | |     -     ^
  | |_____|
  |       the item `m` is already defined here
  |
  = note: `#[warn(unused_imports)]` on by default

This is incorrect since removing that use "statement" leads to the code not compiling.

Meta

Affects all three versions currently available in the Playground (1.47.0 -> 1.49.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-help-wantedCall for participation: Help is requested to fix this issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions