-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
ty macro arguments can be used as traits in impls #46438
Copy link
Copy link
Closed
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.I-needs-decisionIssue: In need of a decision.Issue: In need of a decision.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.I-needs-decisionIssue: In need of a decision.Issue: In need of a decision.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is a side effect of how impls are parsed - the trait in
impl Trait for Typeis first parsed as a type, and then reinterpreted as a type if it has appropriate syntactic form (trait syntax is a subset of type syntax).(Same trick was used for
pub(path)visibilities for some time, but then abandoned in favor ofpub(in path).)The reinterpretation trick in impl parsing can hardly be avoided, but this specific issue can be fixed because reinterpretation can be avoided if we see a
tyfragment afterimpl.The question is whether we should fix it or not - the issue seems benign even if it's probably unintended, an error is immediately reported if
tydoesn't fit into the trait syntax.This trick is also similar to other cases like limited use of
exprfragment in range patterns (#42886), which are intended.I would also be surprised if this was not exploited in practice.