Skip to content

Commit be2ca1e

Browse files
fbqojeda
authored andcommitted
rust: types: Make Opaque::get const
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>
1 parent 2c10928 commit be2ca1e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rust/kernel/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<T> Opaque<T> {
270270
}
271271

272272
/// Returns a raw pointer to the opaque data.
273-
pub fn get(&self) -> *mut T {
273+
pub const fn get(&self) -> *mut T {
274274
UnsafeCell::get(&self.value).cast::<T>()
275275
}
276276

0 commit comments

Comments
 (0)