diff options
| author | Robin Raymond <robin@robinraymond.de> | 2022-05-07 17:15:03 +0000 |
|---|---|---|
| committer | Robin Raymond <robin@robinraymond.de> | 2022-06-19 09:21:28 +0200 |
| commit | 7cefa8f9959565acc6e3606cfa6aa1376c9f862f (patch) | |
| tree | 2097f377f9fcdadd4425b3f9310fc64e2ad2947b /library/std/src/sync/rwlock | |
| parent | 6c9be6e4e9074ca58cef8b1ded299eff72e3ac52 (diff) | |
| download | rust-7cefa8f9959565acc6e3606cfa6aa1376c9f862f.tar.gz rust-7cefa8f9959565acc6e3606cfa6aa1376c9f862f.zip | |
Make RwLockReadGuard covariant
Diffstat (limited to 'library/std/src/sync/rwlock')
| -rw-r--r-- | library/std/src/sync/rwlock/tests.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/library/std/src/sync/rwlock/tests.rs b/library/std/src/sync/rwlock/tests.rs index 53aa2b1e38a..1ffa13f8321 100644 --- a/library/std/src/sync/rwlock/tests.rs +++ b/library/std/src/sync/rwlock/tests.rs @@ -1,6 +1,6 @@ use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::mpsc::channel; -use crate::sync::{Arc, RwLock, TryLockError}; +use crate::sync::{Arc, RwLock, TryLockError, RwLockReadGuard}; use crate::thread; use rand::{self, Rng}; @@ -245,3 +245,15 @@ fn test_get_mut_poison() { Ok(x) => panic!("get_mut of poisoned RwLock is Ok: {x:?}"), } } + +#[test] +fn test_read_guard_covariance() { + fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} + let j: i32 = 5; + let lock = RwLock::new(&j); + { + let i = 6; + do_stuff(lock.read().unwrap(), &i); + } + drop(lock); +} |
