I was looking at the Microsoft Rust guide and while reading the generics chapters, I came across the following problem.
Consider the two following pieces of code:
struct Point<T>
{
x: T,
y: T,
}
fn main()
{
let intro = Point{ x: "Hello", y: "World" };
}
struct Point
{
x: &str,
y: &str,
}
fn main()
{
let intro = Point{ x: "Hello", y: "World" };
}
Both have x and y have the types &str.
Why is the compiler able to infer lifetime in first piece and not in the second?