* Re: [PATCH] rust: types: Make Opaque::get const
2024-04-01 21:45 [PATCH] rust: types: Make Opaque::get const Boqun Feng
@ 2024-04-01 23:21 ` Wedson Almeida Filho
2024-04-02 9:46 ` Alice Ryhl
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Wedson Almeida Filho @ 2024-04-01 23:21 UTC (permalink / raw)
To: Boqun Feng
Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Martin Rodriguez Reboredo, Obei Sideg
On Mon, 1 Apr 2024 at 18:46, Boqun Feng <boqun.feng@gmail.com> wrote:
>
> To support a potential usage:
>
> static foo: Opaque<Foo> = ..; // Or defined in an extern block.
>
> ...
>
> fn bar() {
> let ptr = foo.get();
> }
>
> `Opaque::get` need to be `const`, otherwise compiler will complain
> because calls on statics are limited to const functions.
>
> Also `Opaque::get` should be naturally `const` since it's a composition
> of two `const` functions: `UnsafeCell::get` and `ptr::cast`.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Wedson Almeida Filho <walmeida@microsoft.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: types: Make Opaque::get const
2024-04-01 21:45 [PATCH] rust: types: Make Opaque::get const Boqun Feng
2024-04-01 23:21 ` Wedson Almeida Filho
@ 2024-04-02 9:46 ` Alice Ryhl
2024-04-02 12:49 ` Benno Lossin
2024-05-05 22:26 ` Miguel Ojeda
3 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2024-04-02 9:46 UTC (permalink / raw)
To: Boqun Feng
Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor,
Wedson Almeida Filho, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Martin Rodriguez Reboredo,
Obei Sideg
On Mon, Apr 1, 2024 at 11:46 PM Boqun Feng <boqun.feng@gmail.com> wrote:
>
> To support a potential usage:
>
> static foo: Opaque<Foo> = ..; // Or defined in an extern block.
>
> ...
>
> fn bar() {
> let ptr = foo.get();
> }
>
> `Opaque::get` need to be `const`, otherwise compiler will complain
> because calls on statics are limited to const functions.
>
> Also `Opaque::get` should be naturally `const` since it's a composition
> of two `const` functions: `UnsafeCell::get` and `ptr::cast`.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: types: Make Opaque::get const
2024-04-01 21:45 [PATCH] rust: types: Make Opaque::get const Boqun Feng
2024-04-01 23:21 ` Wedson Almeida Filho
2024-04-02 9:46 ` Alice Ryhl
@ 2024-04-02 12:49 ` Benno Lossin
2024-05-05 22:26 ` Miguel Ojeda
3 siblings, 0 replies; 5+ messages in thread
From: Benno Lossin @ 2024-04-02 12:49 UTC (permalink / raw)
To: Boqun Feng, rust-for-linux, linux-kernel
Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Gary Guo,
Björn Roy Baron, Andreas Hindborg, Alice Ryhl,
Martin Rodriguez Reboredo, Obei Sideg
On 01.04.24 23:45, Boqun Feng wrote:
> To support a potential usage:
>
> static foo: Opaque<Foo> = ..; // Or defined in an extern block.
>
> ...
>
> fn bar() {
> let ptr = foo.get();
> }
>
> `Opaque::get` need to be `const`, otherwise compiler will complain
> because calls on statics are limited to const functions.
>
> Also `Opaque::get` should be naturally `const` since it's a composition
> of two `const` functions: `UnsafeCell::get` and `ptr::cast`.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> ---
> rust/kernel/types.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
--
Cheers,
Benno
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: types: Make Opaque::get const
2024-04-01 21:45 [PATCH] rust: types: Make Opaque::get const Boqun Feng
` (2 preceding siblings ...)
2024-04-02 12:49 ` Benno Lossin
@ 2024-05-05 22:26 ` Miguel Ojeda
3 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2024-05-05 22:26 UTC (permalink / raw)
To: Boqun Feng
Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor,
Wedson Almeida Filho, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl,
Martin Rodriguez Reboredo, Obei Sideg
On Mon, Apr 1, 2024 at 11:46 PM Boqun Feng <boqun.feng@gmail.com> wrote:
>
> To support a potential usage:
>
> static foo: Opaque<Foo> = ..; // Or defined in an extern block.
>
> ...
>
> fn bar() {
> let ptr = foo.get();
> }
>
> `Opaque::get` need to be `const`, otherwise compiler will complain
> because calls on statics are limited to const functions.
>
> Also `Opaque::get` should be naturally `const` since it's a composition
> of two `const` functions: `UnsafeCell::get` and `ptr::cast`.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Applied to `rust-next` -- thanks everyone!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread