aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/lib.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-31 12:37:11 +0100
committerJonas Schievink <[email protected]>2021-06-03 17:09:21 +0100
commite5a2c6596ddd11b0d57042224ac7c1d7691ec33b (patch)
treef0476ad40103b5d3dea60f81fca32c63fe9618d7 /crates/hir_expand/src/lib.rs
parent7f9c4a59d9a84cd8c734286937439b5cd215be27 (diff)
Expand procedural attribute macros
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r--crates/hir_expand/src/lib.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 90d8ae240..618f26b95 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -258,14 +258,29 @@ pub enum MacroCallKind {
258 /// out-of-line modules, which may have attributes spread across 2 files! 258 /// out-of-line modules, which may have attributes spread across 2 files!
259 derive_attr_index: u32, 259 derive_attr_index: u32,
260 }, 260 },
261 Attr {
262 ast_id: AstId<ast::Item>,
263 attr_name: String,
264 attr_args: tt::Subtree,
265 /// Syntactical index of the invoking `#[attribute]`.
266 ///
267 /// Outer attributes are counted first, then inner attributes. This does not support
268 /// out-of-line modules, which may have attributes spread across 2 files!
269 invoc_attr_index: u32,
270 },
261} 271}
262 272
273// FIXME: attribute indices do not account for `cfg_attr`, which means that we'll strip the whole
274// `cfg_attr` instead of just one of the attributes it expands to
275
263impl MacroCallKind { 276impl MacroCallKind {
264 /// Returns the file containing the macro invocation. 277 /// Returns the file containing the macro invocation.
265 fn file_id(&self) -> HirFileId { 278 fn file_id(&self) -> HirFileId {
266 match self { 279 match self {
267 MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id, 280 MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id,
268 MacroCallKind::Derive { ast_id, .. } => ast_id.file_id, 281 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
282 ast_id.file_id
283 }
269 } 284 }
270 } 285 }
271 286
@@ -274,7 +289,7 @@ impl MacroCallKind {
274 MacroCallKind::FnLike { ast_id, .. } => { 289 MacroCallKind::FnLike { ast_id, .. } => {
275 ast_id.with_value(ast_id.to_node(db).syntax().clone()) 290 ast_id.with_value(ast_id.to_node(db).syntax().clone())
276 } 291 }
277 MacroCallKind::Derive { ast_id, .. } => { 292 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
278 ast_id.with_value(ast_id.to_node(db).syntax().clone()) 293 ast_id.with_value(ast_id.to_node(db).syntax().clone())
279 } 294 }
280 } 295 }
@@ -285,7 +300,9 @@ impl MacroCallKind {
285 MacroCallKind::FnLike { ast_id, .. } => { 300 MacroCallKind::FnLike { ast_id, .. } => {
286 Some(ast_id.to_node(db).token_tree()?.syntax().clone()) 301 Some(ast_id.to_node(db).token_tree()?.syntax().clone())
287 } 302 }
288 MacroCallKind::Derive { ast_id, .. } => Some(ast_id.to_node(db).syntax().clone()), 303 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
304 Some(ast_id.to_node(db).syntax().clone())
305 }
289 } 306 }
290 } 307 }
291 308
@@ -293,6 +310,7 @@ impl MacroCallKind {
293 match self { 310 match self {
294 MacroCallKind::FnLike { fragment, .. } => *fragment, 311 MacroCallKind::FnLike { fragment, .. } => *fragment,
295 MacroCallKind::Derive { .. } => FragmentKind::Items, 312 MacroCallKind::Derive { .. } => FragmentKind::Items,
313 MacroCallKind::Attr { .. } => FragmentKind::Items, // is this always correct?
296 } 314 }
297 } 315 }
298} 316}