Skip to content

rustc warns macros unused if declaration is after usage #104221

Closed
@eli-front

Description

@eli-front

I tried this code:

fn main() {
    print!("hi");
}

macro_rules! print {
    ($t: expr) => {
        println!("{}", $t);
    };
}

I expected to see this happen: no errors/warnings

Instead, this happened: unused macro definition: print
#[warn(unused_macros)] on by default. NOTE: this only occurs when the macro is defined after usage.

Meta

rustc --version --verbose:

binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5
Backtrace

 --> src/main.rs:5:14
  |
5 | macro_rules! print {
  |              ^^^^^
  |
  = note: `#[warn(unused_macros)]` on by default

warning: `learn_test` (bin "learn_test") generated 1 warning

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions