mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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>
This commit is contained in:
parent
77ee2eaee4
commit
d6344cc86f
1 changed files with 1 additions and 1 deletions
|
@ -248,7 +248,7 @@ impl<T> Opaque<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a raw pointer to the opaque data.
|
/// 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>()
|
UnsafeCell::get(&self.value).cast::<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue