The following won't compile:
struct Person<'z> {
street_address: String,
postcode: String,
city: String,
company_name: String,
position: String,
annual_income: usize,
}
struct PersonBuilder<'z> {
person: &'z Person<'z>,
}
impl<'z> PersonBuilder<'z> {
fn new() -> PersonBuilder<'z> {
PersonBuilder {
person: Person {
street_address: "".to_string(),
postcode: "".to_string(),
city: "".to_string(),
company_name: "".to_string(),
position: "".to_string(),
annual_income: 0,
},
}
}
}
error[E0392]: parameter `'z` is never used
--> src/main.rs:1:15
|
1 | struct Person<'z> {
| ^^ unused type parameter
|
= help: consider removing `'z` or using a marker such as `std::marker::PhantomData`
But that's not true, is it? I mean, PersonBuilder
keeps a reference to a person as Person<'z>
and when I instantiate it with PersonBuilder::new()
, clearly the type parameter is in play to tie the two lifetimes together. So what's going on here?