The various documentation, such as the types reference, does not go into the relationship between types and lifetimes in detail. This made me wonder if lifetimes are part of types themselves or if they are just compiler hints that are erased before monomorphization occurs.
Given the following example:
fn example<'a, 'b>(a: &'a str, b: &'b str) {
struct Foo<T> {
t: T,
}
let bar = Foo { t: a };
let baz = Foo { t: b };
}
Are bar and baz both of the same type with lifetimes erased (i.e. Foo<&str>) and sharing one monomorphized copy, or are they two distinct types Foo<&'a str> and Foo<&'b str> where the lifetime is part of the type?
And as a side note: is the type inference algorithm documented anywhere for how T received its final type in each case?