Skip to content

Make RwLockReadGuard covariant over its type parameter #80392

Closed

Description

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

use std::sync::{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(lock.read().unwrap(), &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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-concurrencyArea: ConcurrencyC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions