diff options
author | Boqun Feng <boqun.feng@gmail.com> | 2024-04-01 14:45:36 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-09-12 11:11:25 +0200 |
commit | d6344cc86f314ef9ab2001e89d2602359ffe1b70 (patch) | |
tree | a7351e168086ec55610fc6dcb6382cc029e458cd | |
parent | 77ee2eaee4d9329915dbd421ed1640d17ed500ce (diff) | |
download | linux-rpi-d6344cc86f314ef9ab2001e89d2602359ffe1b70.tar.gz linux-rpi-d6344cc86f314ef9ab2001e89d2602359ffe1b70.tar.bz2 linux-rpi-d6344cc86f314ef9ab2001e89d2602359ffe1b70.zip |
rust: types: Make Opaque::get const
commit be2ca1e03965ffb214b6cbda0ffd84daeeb5f214 upstream.
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>
Reviewed-by: Wedson Almeida Filho <walmeida@microsoft.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20240401214543.1242286-1-boqun.feng@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | rust/kernel/types.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index fdb778e65d79..e23e7827d756 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -248,7 +248,7 @@ impl<T> Opaque<T> { } /// Returns a raw pointer to the opaque data. - pub fn get(&self) -> *mut T { + pub const fn get(&self) -> *mut T { UnsafeCell::get(&self.value).cast::<T>() } |