rust/library
bors 00ce47209d Auto merge of #96820 - r-raymond:master, r=cuviper
Make RwLockReadGuard covariant

Hi, first time contributor here, if anything is not as expected, please let me know.

`RwLockReadGoard`'s type constructor is invariant. Since it behaves like a smart pointer to an immutable reference, there is no reason that it should not be covariant. Take e.g.

```
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);
}
```
where the compiler complains that &i doesn't live long enough. If `RwLockReadGuard` is covariant, then the above code is accepted because the lifetime can be shorter than `'a`.

In order for `RwLockReadGuard` to be covariant, it can't contain a full reference to the `RwLock`, which can never be covariant (because it exposes a mutable reference to the underlying data structure). By reducing the data structure to the required pieces of `RwLock`, the rest falls in place.

If there is a better way to do a test that tests successful compilation, please let me know.

Fixes #80392
2022-06-25 13:03:53 +00:00
..
alloc Rollup merge of #98039 - tnballo:master, r=thomcc 2022-06-24 16:43:44 +09:00
backtrace@4e5a3f7292 update libbacktrace 2022-05-20 09:30:26 +02:00
core Auto merge of #93700 - rossmacarthur:ft/iter-next-chunk, r=m-ou-se 2022-06-25 09:40:54 +00:00
panic_abort Fully stabilize NLL 2022-06-03 17:16:41 -04:00
panic_unwind Add underscores to rust_eh_personality arguments to mark them as unused 2022-06-09 09:50:26 -07:00
portable-simd Finish bumping stage0 2022-05-27 07:36:17 -04:00
proc_macro Auto merge of #98224 - eddyb:proc-macro-spurious-repr, r=bjorn3 2022-06-19 17:32:12 +00:00
profiler_builtins Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rtstartup
rustc-std-workspace-alloc Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-core Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-std Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
std Auto merge of #96820 - r-raymond:master, r=cuviper 2022-06-25 13:03:53 +00:00
stdarch@28335054b1 Also allow unused macro rules in stdarch 2022-05-10 19:53:22 +02:00
test Fully stabilize NLL 2022-06-03 17:16:41 -04:00
unwind Stabilize the bundle native library modifier 2022-06-09 23:12:58 +04:00