Re: [PATCH v2 3/4] rust: pci: impl TryFrom<&Device> for &pci::Device
From: Danilo Krummrich
Date: Fri Mar 21 2025 - 15:11:41 EST
On Fri, Mar 21, 2025 at 07:59:08PM +0100, Miguel Ojeda wrote:
> On Fri, Mar 21, 2025 at 6:44 PM Danilo Krummrich <dakr@xxxxxxxxxx> wrote:
> >
> > This requires an unsafe block for compilers < 1.82. For compilers >= 1.82 it
> > turns into a warning *if* using an unsafe block.
> >
> > *Not* requiring unsafe for this seems like the correct thing -- was this a
> > bugfix in the compiler?
> >
> > I guess to make it work for all compiler versions supported by the kernel we
> > have to use unsafe and suppress the warning?
>
> It was a feature, but it has been fairly annoying -- it affected
> several series, e.g. the latest KUnit one as well as:
>From the second link:
"Previously, the compiler's safety checks were not aware that the raw ref
operator did not actually affect the operand's place, treating it as a possible
read or write to a pointer. No unsafety is actually present, however, as it just
creates a pointer.
That sounds like it was a bug, or do I miss anything?
>
> https://lore.kernel.org/rust-for-linux/CANiq72kuebpOa4aPxmTXNMA0eo-SLL+Ht9u1SGHymXBF5_92eA@xxxxxxxxxxxxxx/
>
> Please see:
>
> https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#safely-addressing-unsafe-statics
>
> So, yeah, we use `allow(unused_unsafe)` (no `expect`, since it depends
> on the version).
>
> I hope that helps.
Yeah, thanks a lot. Especially for the second link, I couldn't find it even
after quite a while of searching.
I will respin right away, since otherwise the patches of v3 are reviewed.