Re: [PATCH 04/19] rust: enable `clippy::undocumented_unsafe_blocks` lint

From: Miguel Ojeda
Date: Thu Oct 03 2024 - 14:46:13 EST


On Sun, Sep 29, 2024 at 6:33 AM Trevor Gross <tmgross@xxxxxxxxx> wrote:
>
> There are a couple places where the attributes move like this - did
> this come from an older clippy version? clippy used to warn about this
> but accepts it by default since [1]. (Still works of course, I just
> think it looks nicer to have the attributes next to their statements).

I started this series about a long time ago, but I don't think old
Clippy is the reason -- I took a look again at this a couple months
ago and created this issue about it due to these lines of code,
including some examples and test cases:

https://github.com/rust-lang/rust-clippy/issues/13189

For instance:

// SAFETY: ...
#[allow(clippy::unnecessary_cast)]
return Err(unsafe { Error::from_errno_unchecked(err as core::ffi::c_int) });

This will not work, i.e. it does not see the `// SAFETY:`. However,
putting the `#[allow]` on top to let the comment be closer will work
(like in the patch). This will also work:

return Err(
// SAFETY: ...
#[allow(clippy::unnecessary_cast)]
unsafe { Error::from_errno_unchecked(err as core::ffi::c_int) }
);

There has been no reply in the issue so far, but if you have any
comments/insights on whether those cases should or should not work,
that would be great.

Cheers,
Miguel