Skip to content

use_self lint false positive in macros #3881

@pavel-mukhanov

Description

@pavel-mukhanov

Minimal example

macro_rules! impl_binary_form_scalar {
    ($type:tt, $read:ident) => {
        impl BinaryValue for $type {
            fn to_bytes(&self) -> Vec<u8> {
                vec![*self as u8]
            }
        }
    };
}

This macros is invoked for

impl_binary_form_scalar! { u8,  read_u8 }

and

impl_binary_form_scalar! { i8,  read_i8 }

Clippy suggests to replace u8 with Self vec![*self as Self] which in case with i8 is not possible.
Also, I can't figure out how to disable lint in this particular place because

#![cfg_attr(feature="cargo-clippy", allow(clippy::use_self))]
fn to_bytes(&self) -> Vec<u8> {

is not working.

cargo +nightly clippy -V
clippy 0.0.212 (016d92d6 2019-03-10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions