Skip to content

Commit d6344cc

Browse files
fbqgregkh
authored andcommitted
rust: types: Make Opaque::get const
commit be2ca1e 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 <[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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 77ee2ea commit d6344cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: rust/kernel/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<T> Opaque<T> {
248248
}
249249

250250
/// Returns a raw pointer to the opaque data.
251-
pub fn get(&self) -> *mut T {
251+
pub const fn get(&self) -> *mut T {
252252
UnsafeCell::get(&self.value).cast::<T>()
253253
}
254254

0 commit comments

Comments
 (0)