Re: [PATCH] rust: sync: add #[must_use] to Lock::try_lock

jos
2024-12-08T22:09:33Z

> I may be misunderstanding what you are trying to say, but the guard is
> created, and the lock is acquired.

Apologizes, I had a misunderstanding of the macro that was being used.
Thank you Boqun and Miguel for providing clarity, much appreciated!

> It'd be great to mention in this message (and perhaps in the code)
> that the reason this annotation is necessary is that `Option<T>` is
> not `#[must_use]` regardless of `T` being `#[must_use]`. It might also
> be handy to leave a breadcrumb pointing to
> https://github.com/rust-lang/rust/issues/71368.

Sure I can do that, thank you for the suggestion!

Thanks,
Jason

On Sun, Dec 8, 2024 at 1:58 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> On Sun, Dec 8, 2024 at 3:50 PM Jason Devers <dev.json2@gmail.com> wrote:
> >
> > The `Lock::try_lock` function returns an `Option<Guard<...>>`, but it
> > currently does not issue a warning if the return value is unused.
> > To avoid potential bugs, the `#[must_use]` annotation is added to ensure proper usage.
>
> It'd be great to mention in this message (and perhaps in the code)
> that the reason this annotation is necessary is that `Option<T>` is
> not `#[must_use]` regardless of `T` being `#[must_use]`. It might also
> be handy to leave a breadcrumb pointing to
> https://github.com/rust-lang/rust/issues/71368.