8000 `macro_metavars_in_unsafe` does not lint "without a statement". · Issue #13219 · rust-lang/rust-clippy · GitHub
[go: up one dir, main page]

Skip to content
macro_metavars_in_unsafe does not lint "without a statement". #13219
@ojeda

Description

@ojeda

Summary

The current existing tests all have statements.

Lint Name

macro_metavars_in_unsafe

Reproducer

I tried this code:

#[macro_export]
macro_rules! m {
    ($e:expr) => {
        unsafe { $e }
    };
}

pub fn f(p: *const i32) -> i32 {
    m!(*p)
}

I expected to see this happen: Lint emitted.

Instead, this happened: No lint emitted.

However, this will correctly lint:

#[macro_export]
macro_rules! m {
    ($e:expr) => {
        unsafe { $e }
    };
}

pub fn f(p: *const i32) -> i32 {
    m!(*p);
    42
}

This will correctly lint as well:

#[macro_export]
macro_rules! m {
    ($e:expr) => {
        unsafe { $e; } // Notice the semicolon.
    };
}

pub fn f(p: *const i32) -> i32 {
    m!(return *p)
}

But if we remove the semicolon, it will again incorrectly not lint:

#[macro_export]
macro_rules! m {
    ($e:expr) => {
        unsafe { $e } // Now gone.
    };
}

pub fn f(p: *const i32) -> i32 {
    m!(return *p)
}

Version

Reproduced with Rust 1.80.0 and nightly (rustc 1.82.0-nightly (64ebd39da 2024-08-03)).

Cc: @y21

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0