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

Miguel Ojeda
2024-10-03T18:45:52Z

On Sun, Sep 29, 2024 at 6:33 AM Trevor Gross <tmgross@umich.edu> 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