@@ -611,7 +611,27 @@ impl dyn Any + Send + Sync {
611611/// noting that the hashes and ordering will vary between Rust releases. Beware
612612/// of relying on them inside of your code!
613613///
614- /// **Note on Variance**:
614+ /// # Remarks and gotchas around `unsafe` code
615+ ///
616+ /// ## Variance
617+ ///
618+ /// A generic `<T: 'static>` type is still susceptible to variance,
619+ /// since there exist distinct types in a subtyping relationship
620+ /// which nonetheless are very much `: 'static`.
621+ ///
622+ /// For instance:
623+ /// - `T = fn(&str) = for<'any> fn(&'any str)`, and
624+ /// - `U = fn(&'static str)`
625+ /// are both distinct, `: 'static`, and yet `T` is a subtype of `U`.
626+ ///
627+ /// This means that abstractions around `TypeId`, despite its
628+ /// `: 'static` requirement, still need to worry about unnecessary
629+ /// and improper variance: it is advisable to strive for invariance
630+ /// first. The usability impact will be negligible, while the reduction
631+ /// in the risk of unsoundness will be most welcome.
632+ ///
633+ /// ### Illustration of improper variance
634+ ///
615635/// Suppose `SubType` is a subtype of `SuperType`, that is,
616636/// values of type `SubType` can be used wherever `SuperType` is
617637/// expected (so they can, for instance, be freely `as`-casted to it).
@@ -713,7 +733,7 @@ impl PartialEq for TypeId {
713733}
714734
715735impl TypeId {
716- /// Given a type (as a generic type argument), returns the `TypeId` of that type.
736+ /// Returns the `TypeId` of the generic type parameter .
717737 ///
718738 /// # Examples
719739 ///
0 commit comments