Lifetime syntax suggestion

Lifetimes in Rust are difficult to learn how to use them properly, and I guess many people lose interest in the language because of that. I wonder if it has ever been considered adopting a syntax that allows representing this:

struct Foo<'a, 'b, 'c> {
    field1: &'a String,
    field2: &'b String,
    field3: &'c String,
}

fn bar<'r>(s: Foo<'_, 'r, '_>, t: Foo<'_, '_, 'r>) -> &'r String

Like this:

struct Foo {
    field1: &String,
    field2: &String,
    field3: &String,
}

fn bar(s: Foo, t: Foo) -> &String
where 'return: 's.field2 | 't.field3

This is not a full proposal, I'd just like to know if something similar has already been discussed. If not, do you guys think this might be worth trying?

It probably has come up before, maybe even several times. I don't think such big changes for syntax are or will ever realistically be in scope.

fields are private by default.
I think it is understanding variance that priority but not sure of a syntax that would help.

One place this came up in the past is the alternatives section of RFC 2115 and associated discussion.

1 Like

Thank you for the links! :+1:

Whilst we are here, could some kind soul explain what Milack27's example actually means?

Every time I start to look into those life time ticks I get severe headache and my brain freezes over.

I'm sure there is a simple concept in there waiting to come out for me but this kind of thing:

fn bar<'r>(s: Foo<'_, 'r, '_>, t: Foo<'_, '_, 'r>

remains nothing but line noise at the moment.

Exactly my point. In the bar function, I only need to reference one lifetime for each parameter. But because Foo itself has three generic lifetime parameters, I'm forced to reference all of them in both s and t. The ones with the '_ placeholder are irrelevant to this context, but they have to be there anyway.