-
Notifications
You must be signed in to change notification settings - Fork 549
Open
Labels
A-macrosArea: macros (general sense)Area: macros (general sense)C-bugCategory: bugCategory: bugE-hardDifficulty: might require advanced knowledgeDifficulty: might require advanced knowledgeI-incorrectIssue: info is incorrect or misleadingIssue: info is incorrect or misleadingI-terseIssue: info is very terseIssue: info is very terse
Description
The guide says right here:
Error: some fatal error has occurred in the parser. For example, this happens if there are more than one pattern match, since that indicates the macro is ambiguous.
This seems not to be the case.
macro_rules! times {
(a b) => (5000);
($x:ident b) => ($x * $x);
($x:ident $y:ident) => ($x * $y);
}
fn main() {
dbg!(times!(a b));
}
Output: 5000
Rust just chooses the first pattern that matches. In fact, you can use the exact same pattern twice and the Rust compiler won't complain.
macro_rules! times {
(a b) => (5000);
(a b) => (10000);
}
fn main() {
dbg!(times!(a b));
}
Output: 5000
Am I misunderstanding the description or is the description wrong?
Metadata
Metadata
Assignees
Labels
A-macrosArea: macros (general sense)Area: macros (general sense)C-bugCategory: bugCategory: bugE-hardDifficulty: might require advanced knowledgeDifficulty: might require advanced knowledgeI-incorrectIssue: info is incorrect or misleadingIssue: info is incorrect or misleadingI-terseIssue: info is very terseIssue: info is very terse