Skip to content

Regression with unused_imports on macro used in documentation #148143

@dylni

Description

@dylni

The unused_imports lint is triggered on nightly when it is not on beta or stable. The import is required.

Code

I tried this code:

//! See:
#![doc = a!()]

macro_rules! a {
    () => { "Documentation" };
}
use a;

fn main() {}

I expected to see this happen: No warnings

Instead, this happened:

warning: unused import: `a`
 --> src/main.rs:7:5
  |
7 | use a;
  |     ^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=c16575b4d9f265e4e6b9394ca8d22760

Version it worked on

It most recently worked on: 1.91.0-beta.10

Version with regression

rustc --version (differs from beta by two versions even after updating):

rustc 1.93.0-nightly (34f954f9b 2025-10-25)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-mediumMedium priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions