Skip to main content

Module attrs

Module attrs 

Source
Expand description

Defines the basics of attributes lowering.

The heart and soul of this module is expand_cfg_attr(), alongside its sibling expand_cfg_attr_with_doc_comments(). It is used to implement all attribute lowering in r-a. Its basic job is to list attributes; however, attributes do not necessarily map into [ast::Attr], because cfg_attr can map to zero, one, or more attributes (#[cfg_attr(predicate, attr1, attr2, ...)]). expand_cfg_attr() expands cfg_attrs as it goes (as its name implies), to list all attributes.

Another thing to note is that we need to be able to map an attribute back to a range (for diagnostic purposes etc.). This is only ever needed for attributes that participate in name resolution. An attribute is mapped back by its AttrId, which is just an index into the item tree attributes list. To minimize the risk of bugs, we have one place (here) and one function (is_item_tree_filtered_attr()) that decides whether an attribute participate in name resolution.

Structsยง

Attr
AttrId
This is an index of an attribute that always points to the item tree attributes.

Enumsยง

AttrInput

Traitsยง

AstKeyValueMetaExt
AstPathExt

Functionsยง

collect_item_tree_attrs
This collects attributes exactly as the item tree needs them. This is used for the item tree, as well as for resolving AttrIds.
expand_cfg_attr
The callback is passed the attribute and the outermost ast::Attr. Note that one node may map to multiple [ast::Meta]s due to cfg_attr.
expand_cfg_attr_with_doc_comments
is_item_tree_filtered_attr ๐Ÿ”’
parse_path_comma_token_tree ๐Ÿ”’
unescape ๐Ÿ”’