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

undocumented_unsafe_blocks can be broken by rustfmt #13024

Open
clarfonthey opened this issue Jul 1, 2024 · 1 comment
Open

undocumented_unsafe_blocks can be broken by rustfmt #13024

clarfonthey opened this issue Jul 1, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@clarfonthey
Copy link

clarfonthey commented Jul 1, 2024

Summary

Consider the following code:

// SAFETY: trust me ok
long_var_name = unsafe {
    /* ... */
};

Normally, rustfmt will either leave the unsafe block as above or convert this into the following, depending on its length:

// SAFETY: trust me ok
long_var_name = unsafe { /* ... */ };

However, in rare cases, if /* ... */ is exactly the right length, rustfmt will emit:

// SAFETY: trust me ok
long_var_name =
    unsafe { /* ... */ };

Which breaks the undocumented_unsafe_blocks lint, since the comment isn't immediately before the line with unsafe. It should accept cases like this.

Lint Name

undocumented_unsafe_blocks

@clarfonthey clarfonthey added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 1, 2024
@notriddle
Copy link
Contributor

When I run this with a current version of clippy, the third test doesn't lint thanks to the accept-comment-above-statement option, which is turned on by default.

This feature was actually merged before this issue was opened, and made its way to stable in November 2023.

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-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants