Skip to content

Commit 402f419

Browse files
authored
Merge pull request #579 from wedsonaf/sized-bound
rust: add `?Sized` bound to revocable wrapped type.
2 parents cfeaf05 + a9f8c4a commit 402f419

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

rust/kernel/revocable.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ impl<T> Revocable<T> {
6565
data: ManuallyDrop::new(UnsafeCell::new(data)),
6666
}
6767
}
68+
}
6869

70+
impl<T: ?Sized> Revocable<T> {
6971
/// Tries to access the \[revocable\] wrapped object.
7072
///
7173
/// Returns `None` if the object has been revoked and is therefore no longer accessible.
@@ -125,12 +127,12 @@ impl<T: ?Sized> Drop for Revocable<T> {
125127
/// # Invariants
126128
///
127129
/// The RCU read-side lock is held while the guard is alive.
128-
pub struct RevocableGuard<'a, T> {
130+
pub struct RevocableGuard<'a, T: ?Sized> {
129131
data_ref: *const T,
130132
_p: PhantomData<&'a ()>,
131133
}
132134

133-
impl<T> RevocableGuard<'_, T> {
135+
impl<T: ?Sized> RevocableGuard<'_, T> {
134136
fn new(data_ref: *const T) -> Self {
135137
// SAFETY: Just an FFI call, there are no further requirements.
136138
unsafe { bindings::rcu_read_lock() };
@@ -143,14 +145,14 @@ impl<T> RevocableGuard<'_, T> {
143145
}
144146
}
145147

146-
impl<T> Drop for RevocableGuard<'_, T> {
148+
impl<T: ?Sized> Drop for RevocableGuard<'_, T> {
147149
fn drop(&mut self) {
148150
// SAFETY: By the type invariants, we know that we hold the RCU read-side lock.
149151
unsafe { bindings::rcu_read_unlock() };
150152
}
151153
}
152154

153-
impl<T> Deref for RevocableGuard<'_, T> {
155+
impl<T: ?Sized> Deref for RevocableGuard<'_, T> {
154156
type Target = T;
155157

156158
fn deref(&self) -> &Self::Target {

0 commit comments

Comments
 (0)