-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Macro expansion often produces invalid Span values #23480
Copy link
Copy link
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-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.
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The span of many AST node types is pieced together from the spans of the node's children. Here is an example from
Parser::parse_more_binops:Unfortunately, in the macro expansion phase, this can lead to undesirable results. Consider the following example:
Here
lhsandrhscome from completely different contexts.lhs_spancomes from the macro-definition-site (lo: 50, hi: 51) whilerhs_spancomes from the expansion-site (lo: 6, hi:7). Takinglofromlhsandhifromrhs, as the above code does, we end up with a span oflo: 50, hi: 7. This value can't be interpreted in any meaningful way.A similar error can occur for any kind of AST node where a sub-node is located directly at the border of a parent:
This invalid
Spanvalues may lead to strange error messages and caused at least one ICE (#23115).