Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RwLockReadGuard covariant over its type parameter #9

Closed
Kestrer opened this issue Dec 26, 2020 · 0 comments · Fixed by #45
Closed

Make RwLockReadGuard covariant over its type parameter #9

Kestrer opened this issue Dec 26, 2020 · 0 comments · Fixed by #45

Comments

@Kestrer
Copy link

Kestrer commented Dec 26, 2020

Currently RwLockReadGuard is invariant over its type parameter, meaning that for instance this sound code:

use async_lock::{RwLock, RwLockReadGuard};

fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {}

fn main() {
    let j: i32 = 5;
    let lock = RwLock::new(&j);
    {
        let i = 6;
        do_stuff(futures_lite::future::block_on(lock.read()), &i);
    }
    drop(lock);
}

Will not compile. However, since RwLockReadGuard does not allow for mutation of the inner value, it would be sound to make it covariant, and it would be useful in some circumstances.

See also the same issue in parking_lot and in std.

notgull pushed a commit that referenced this issue May 27, 2023
Closes #9 by making the RwLockReadGuard type covariant.

This involves splitting the RwLock implementation into a "raw" RwLock part and the public API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant