Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro_metavars_in_unsafe does not lint "without a statement". #13219

Closed
ojeda opened this issue Aug 4, 2024 · 0 comments · Fixed by #13220
Closed

macro_metavars_in_unsafe does not lint "without a statement". #13219

ojeda opened this issue Aug 4, 2024 · 0 comments · Fixed by #13220
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@ojeda
Copy link
Contributor

ojeda commented Aug 4, 2024

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

@ojeda ojeda added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Aug 4, 2024
@y21 y21 self-assigned this Aug 5, 2024
@bors bors closed this as completed in 37f98ff Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants