You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, `Ptr<'a, T>` and `PtrInner<'a, T>` documented themselves to
be covariant in both `'a` and `T`. This was true for `PtrInner`, but not
for `Ptr`, which used GATs, which are invariant. This is also not the
desired variance: for `Exclusive` aliasing, the desired variance matches
that of `&mut` references - namely, covariant in `'a` but invariant in
`T`.
This commit fixes this by making `Ptr<'a, T>` and `PtrInner<'a, T>`
unconditionally covariant in `'a` and invariant in `T`.
gherrit-pr-id: I29f8429d9d7b14026313f030f8dc1e895a98ad56
| ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big`
11
+
|
12
+
= help: consider adding the following bound: `'small: 'big`
13
+
= note: requirement occurs because of the type `Ptr<'_, Valid<&u32>, (invariant::Exclusive, Aligned)>`, which makes the generic argument `Valid<&u32>` invariant
14
+
= note: the struct `Ptr<'a, V, I>` is invariant over the parameter `V`
15
+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
16
+
17
+
error: lifetime may not live long enough
18
+
--> tests/ui-msrv/ptr-is-invariant-over-v.rs:17:5
19
+
|
20
+
13 | fn _when_shared<'big: 'small, 'small>(
21
+
| ---- ------ lifetime `'small` defined here
22
+
| |
23
+
| lifetime `'big` defined here
24
+
...
25
+
17 | _small = big;
26
+
| ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big`
27
+
|
28
+
= help: consider adding the following bound: `'small: 'big`
29
+
= note: requirement occurs because of the type `Ptr<'_, Valid<&u32>, (Shared, Aligned)>`, which makes the generic argument `Valid<&u32>` invariant
30
+
= note: the struct `Ptr<'a, V, I>` is invariant over the parameter `V`
31
+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
| ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big`
11
+
|
12
+
= help: consider adding the following bound: `'small: 'big`
13
+
= note: requirement occurs because of the type `Ptr<'_, Valid<&u32>, (invariant::Exclusive, Aligned)>`, which makes the generic argument `Valid<&u32>` invariant
14
+
= note: the struct `Ptr<'a, V, I>` is invariant over the parameter `V`
15
+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
| ^^^^^^^^^^^^ assignment requires that `'small` must outlive `'big`
11
+
|
12
+
= help: consider adding the following bound: `'small: 'big`
13
+
= note: requirement occurs because of the type `Ptr<'_, Valid<&u32>, (invariant::Exclusive, Aligned)>`, which makes the generic argument `Valid<&u32>` invariant
14
+
= note: the struct `Ptr<'a, V, I>` is invariant over the parameter `V`
15
+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
0 commit comments