-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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>::TrSubtypemay 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
wherekeyword 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 thewhereclause".
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.