Skip to content

must_use_candidate should not warn proc macros #4684

@taiki-e

Description

@taiki-e

Code:

#![warn(clippy::must_use_candidate)]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro]
pub fn proc_macro1(input: TokenStream) -> TokenStream { //~ WARN this function could have a `#[must_use]` attribute
    input
}

#[proc_macro_attribute]
pub fn proc_macro2(_: TokenStream, input: TokenStream) -> TokenStream { //~ WARN this function could have a `#[must_use]` attribute
    input
}

#[proc_macro_derive(Foo)]
pub fn proc_macro3(input: TokenStream) -> TokenStream { //~ WARN this function could have a `#[must_use]` attribute
    input
}

Output

warning: this function could have a `#[must_use]` attribute
 --> src/lib.rs:8:1
  |
8 | pub fn proc_macro1(input: TokenStream) -> TokenStream {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn proc_macro1(input: TokenStream) -> TokenStream`
  |
note: lint level defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::must_use_candidate)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

warning: this function could have a `#[must_use]` attribute
  --> src/lib.rs:13:1
   |
13 | pub fn proc_macro2(_: TokenStream, input: TokenStream) -> TokenStream {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn proc_macro2(_: TokenStream, input: TokenStream) -> TokenStream`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

warning: this function could have a `#[must_use]` attribute
  --> src/lib.rs:18:1
   |
18 | pub fn proc_macro3(input: TokenStream) -> TokenStream {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn proc_macro3(input: TokenStream) -> TokenStream`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions