Hint in the error message for this code appears to suggest a syntax that doesn't compile (playpen):
trait Tr {
type TrSubtype;
}
struct Bar<'a, Item: Tr> {
item: Item,
item_sub: &'a <Item as Tr>::TrSubtype,
}
error: the associated type <Item as Tr>::TrSubtype may not live long enough
[…] consider adding an explicit lifetime bound <Item as Tr>::TrSubtype: 'a...
When I did what (I thought was) suggested (since the same syntax worked in simpler cases):
struct Bar<'a, Item: Tr, <Item as Tr>::TrSubtype: 'a> {
it failed with a very unfriendly syntax error:
error: expected ident, found <
After a lot of head scratching I've discovered that it meant:
struct Bar<'a, Item: Tr> where <Item as Tr>::TrSubtype: 'a {
So I suggest either:
- Make the error hint suggest syntax with the
where keyword when necessary
- Allow the syntax without
where: <'a, Item: Tr, <Item as Tr>::TrSubtype: 'a>>
- or detect when
< is found instead of an ident and emit error along lines of "Move that to the where clause".
Hint in the error message for this code appears to suggest a syntax that doesn't compile (playpen):
When I did what (I thought was) suggested (since the same syntax worked in simpler cases):
it failed with a very unfriendly syntax error:
After a lot of head scratching I've discovered that it meant:
So I suggest either:
wherekeyword when necessarywhere:<'a, Item: Tr, <Item as Tr>::TrSubtype: 'a>><is found instead of an ident and emit error along lines of "Move that to thewhereclause".