File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -3608,6 +3608,26 @@ The notation `&self` is a shorthand for `self: &Self`. In this case,
3608
3608
in the impl, ` Self ` refers to the value of type ` String ` that is the
3609
3609
receiver for a call to the method ` make_string ` .
3610
3610
3611
+ ## Subtyping
3612
+
3613
+ Subtyping is implicit and can occur at any stage in type checking or
3614
+ inference. Subtyping in Rust is very restricted and occurs only due to
3615
+ variance with respect to lifetimes and between types with higher ranked
3616
+ lifetimes. If we were to erase lifetimes from types, then the only subtyping
3617
+ would be due to type equality.
3618
+
3619
+ Consider the following example: string literals always have ` 'static `
3620
+ lifetime. Nevertheless, we can assign ` s ` to ` t ` :
3621
+
3622
+ ```
3623
+ fn bar<'a>() {
3624
+ let s: &'static str = "hi";
3625
+ let t: &'a str = s;
3626
+ }
3627
+ ```
3628
+ Since ` 'static ` "lives longer" than ` 'a ` , ` &'static str ` is a subtype of
3629
+ ` &'a str ` .
3630
+
3611
3631
# Special traits
3612
3632
3613
3633
Several traits define special evaluation behavior.
You can’t perform that action at this time.
0 commit comments