aboutsummaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorBoqun Feng <[email protected]>2024-04-01 14:45:36 -0700
committerMiguel Ojeda <[email protected]>2024-05-05 13:19:37 +0200
commitbe2ca1e03965ffb214b6cbda0ffd84daeeb5f214 (patch)
tree2985316ea302b188c1a7e4fbe342ea74cdb9ad98 /rust/kernel
parent2c1092853f163762ef0aabc551a630ef233e1be3 (diff)
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Wedson Almeida Filho <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/types.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 8fad61268465..2e7c9008621f 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -270,7 +270,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>()
}