Merge pull request #516 from emamoah/patch-2

Clarify parameter and argument compatibility
master
Yuki Okushi 3 days ago committed by GitHub
commit 69c1421f15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -118,9 +118,9 @@ This is a classic use-after-free bug!
Our first instinct might be to blame the `assign` impl, but there's really nothing wrong here. Our first instinct might be to blame the `assign` impl, but there's really nothing wrong here.
It shouldn't be surprising that we might want to assign a `T` into a `T`. It shouldn't be surprising that we might want to assign a `T` into a `T`.
The problem is that we cannot assume that `&mut &'static str` and `&mut &'b str` are compatible. The problem is that we cannot assume `&'static str` can still be downgraded into `&'world str` to satisfy `T`, once it's behind a `&mut` reference.
This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'b str`, This means that `&mut &'static str` **cannot** be a *subtype* of `&mut &'world str`,
even if `'static` is a subtype of `'b`. even if `'static` is a subtype of `'world`.
Variance is the concept that Rust borrows to define relationships about subtypes through their generic parameters. Variance is the concept that Rust borrows to define relationships about subtypes through their generic parameters.

Loading…
Cancel
Save