Re: [PATCH v5 4/4] rust: adding OwnableRefCounted and SimpleOwnableRefCounted

From: Miguel Ojeda
Date: Fri Mar 07 2025 - 08:17:24 EST


Hi Oliver,

Some general style nits for this and other series you may send in the
future (not a review). Please note that most may apply several times.

On Fri, Mar 7, 2025 at 11:04 AM Oliver Mangold <oliver.mangold@xxxxx> wrote:
>
> Types implementing one of these traits
> can safely convert between an ARef<T> and an Owned<T>.

The wrapping is strange here, and it also happens in your code
comments. Please use the same width as the rest of the code in a file
etc.

> +/// - The same safety requirements as for [`Ownable`] and [`RefCounted`] apply.

"same" sounds like no extra requirements -- what about something like:

The safety requirements from both [.....

I wonder if we should expand/inline them, even if they come from the
supertraits.

> +/// - the uniqueness invariant of [`Owned`] is upheld until dropped.

Please use uppercase to start sentences.

> +/// // Use a KBox to handle the actual allocation

Please use Markdown for comments too, and period at the end (also for
"SAFETY: ..." comments).

> +/// // SAFETY: we implement the trait correctly by ensuring

There is no need to say "we implement the trait correctly", i.e. the
`SAFETY` tag is enough to introduce the comment; the same way we don't
say "SAFETY: the following unsafe block is correct because ..." etc.

> +/// }
> +/// fn is_unique(&self) -> bool {

Newline between items.

> +/// let foo = Foo::new().unwrap();

In general, we try to avoid showing patterns that people should avoid
when writing actual code (at least in non-hidden code) -- could we
avoid the `unwrap()`?

> +// TODO: enable this when compiler supports it (>=1.85)
> +// #[diagnostic::do_not_recommend]

I think (untested) we could conditionally enable this already and
remove the `TODO` with something like:

config RUSTC_HAS_DO_NOT_RECOMMEND
def_bool RUSTC_VERSION >= 108500

#[cfg_attr(CONFIG_RUSTC_HAS_DO_NOT_RECOMMEND, diagnostic::do_not_recommend)]

Thanks!

Cheers,
Miguel