All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@redhat.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Cc: Wedson Almeida Filho <wedsonaf@gmail.com>,
	ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
	gary@garyguo.net, bjorn3_gh@protonmail.com,
	benno.lossin@proton.me, a.hindborg@samsung.com,
	aliceryhl@google.com, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v3] rust: alloc: fix dangling pointer in VecExt<T>::reserve()
Date: Tue, 7 May 2024 00:30:14 +0200	[thread overview]
Message-ID: <b57dde93-06db-405b-ab94-864779c76010@redhat.com> (raw)
In-Reply-To: <CANiq72nHubtd7oB=JUTY8B0H9WA35jio1L0tfTSxDpJFLBcdMw@mail.gmail.com>

On 5/6/24 19:50, Miguel Ojeda wrote:
> On Mon, May 6, 2024 at 5:22 PM Danilo Krummrich <dakr@redhat.com> wrote:
>>
>> Is there any benefit using an if here, or is that your personal preference?
> 
> `if` is meant to test a boolean condition, which is what you are doing
> here, so the question is why would we want to use a `match` here -- we
> should first of all try to be consistent.
> 
> Now, I can understand the appeal of how the `match` looks like (e.g.
> less braces, less zig-zag indentation), and if this were a `if`-`else`
> chain with several cases and the wildcard `_` was not used, e.g.
> something like:
> 
>      ... = match n {
>          1 => ...
>          2 => ...
>          3 => ...
>      }
> 
> then I agree it would be clearly better.
> 
> Perhaps you are arguing for something like "let's always use `match`
> in cases where a value is returned, i.e. when used as an expression,
> and save `if` for the C-like cases". If so, would that mean then that
> we need to do:
> 
>      match c {
>          false => ...
>          true => ...
>      }
> 
> to be consistent?
> 
> Then there are other things like `if let`, the potential `is` operator
> and postfix `match` that should probably be considered.
> 

Thanks for your thoughts, but style wise I don't have a strong preference
for either of those. My question was honestly about whether there is any
other reason other than style.

However, I don't think using match is that unreasonable. There are cases
in the std library as well, e.g. [1]. But again, I'm fine with either of
those.

> Anyway, I am picking the fix as it is.

Please feel free to change the match statement to an if statement if that's
what you prefer.

- Danilo

[1] https://doc.rust-lang.org/src/alloc/string.rs.html#1358

> 
> Cheers,
> Miguel
> 


  reply	other threads:[~2024-05-06 22:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 13:47 [PATCH v3] rust: alloc: fix dangling pointer in VecExt<T>::reserve() Danilo Krummrich
2024-05-06 14:11 ` Wedson Almeida Filho
2024-05-06 15:22   ` Danilo Krummrich
2024-05-06 16:37     ` Wedson Almeida Filho
2024-05-07  0:36       ` some aside maintainer advice (was Re: [PATCH v3] rust: alloc: fix dangling pointer in VecExt<T>::reserve()) David Airlie
2024-05-07  2:33         ` Wedson Almeida Filho
2024-05-07  2:47           ` David Airlie
2024-05-07  3:10             ` Wedson Almeida Filho
2024-05-07  2:54           ` David Airlie
2024-05-07 20:16           ` Danilo Krummrich
2024-05-06 17:50     ` [PATCH v3] rust: alloc: fix dangling pointer in VecExt<T>::reserve() Miguel Ojeda
2024-05-06 22:30       ` Danilo Krummrich [this message]
2024-05-06 22:24 ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b57dde93-06db-405b-ab94-864779c76010@redhat.com \
    --to=dakr@redhat.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.