Skip to content

Commit 6445df5

Browse files
committed
censor attribute derive
1 parent 926e1f9 commit 6445df5

File tree

1 file changed

+14
-2
lines changed
  • crates/hir-expand/src

1 file changed

+14
-2
lines changed

crates/hir-expand/src/db.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use mbe::{syntax_node_to_token_tree, ValueResult};
77
use rustc_hash::FxHashSet;
88
use span::{AstIdMap, SyntaxContextData, SyntaxContextId};
99
use syntax::{ast, AstNode, Parse, SyntaxElement, SyntaxError, SyntaxNode, SyntaxToken, T};
10+
use tracing::debug;
1011
use triomphe::Arc;
1112

1213
use crate::{
@@ -345,7 +346,13 @@ fn smart_macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
345346
// FIXME: We called lookup_intern_macro_call twice.
346347
match loc.kind {
347348
// Get the macro arg for the derive macro
348-
MacroCallKind::Derive { derive_macro_id, .. } => db.macro_arg(derive_macro_id),
349+
MacroCallKind::Derive { derive_macro_id, .. } => {
350+
debug!(
351+
?loc,
352+
"{id:?} is a derive macro. Using the derive macro, id: {derive_macro_id:?}, attribute as the macro arg."
353+
);
354+
db.macro_arg(derive_macro_id)
355+
}
349356
// Normal macro arg
350357
_ => db.macro_arg(id),
351358
}
@@ -455,7 +462,12 @@ fn macro_arg(
455462
}
456463
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
457464
let node = ast_id.to_ptr(db).to_node(&root);
458-
(censor_attr_input(invoc_attr_index, &node), node)
465+
if loc.def.is_attribute_derive() && ast::Adt::can_cast(node.syntax().kind()) {
466+
let node = ast::Adt::cast(node.syntax().clone()).unwrap();
467+
(censor_derive_input(invoc_attr_index, &node), node.into())
468+
} else {
469+
(censor_attr_input(invoc_attr_index, &node), node)
470+
}
459471
}
460472
};
461473

0 commit comments

Comments
 (0)