Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c381d0f

Browse files
committed
Review Updates
1 parent 262e06f commit c381d0f

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

crates/hir-def/src/nameres/collector.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ impl DefCollector<'_> {
12321232
Some(def) if def.is_attribute() => def,
12331233
_ => return Resolved::No,
12341234
};
1235+
12351236
let call_id =
12361237
attr_macro_as_call_id(self.db, file_ast_id, attr, self.def_map.krate, def);
12371238
if let MacroDefId {
@@ -1264,7 +1265,6 @@ impl DefCollector<'_> {
12641265
};
12651266

12661267
let ast_id = ast_id.with_value(ast_adt_id);
1267-
// the call_id for the actual derive macro. This is used so all the derive proc macros can share a token tree
12681268

12691269
match attr.parse_path_comma_token_tree(self.db.upcast()) {
12701270
Some(derive_macros) => {
@@ -2305,7 +2305,7 @@ impl ModCollector<'_, '_> {
23052305

23062306
fn collect_macro_call(
23072307
&mut self,
2308-
&MacroCall { ref path, ast_id, expand_to, ctxt, .. }: &MacroCall,
2308+
&MacroCall { ref path, ast_id, expand_to, ctxt }: &MacroCall,
23092309
container: ItemContainerId,
23102310
) {
23112311
let ast_id = AstIdWithPath::new(self.file_id(), ast_id, ModPath::clone(path));
@@ -2444,10 +2444,7 @@ mod tests {
24442444
use base_db::SourceDatabase;
24452445
use test_fixture::WithFixture;
24462446

2447-
use crate::{
2448-
nameres::{DefMapCrateData, ModuleData, ModuleOrigin},
2449-
test_db::TestDB,
2450-
};
2447+
use crate::{nameres::DefMapCrateData, test_db::TestDB};
24512448

24522449
use super::*;
24532450

crates/hir-expand/src/db.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn expand_speculative(
151151
let span_map = RealSpanMap::absolute(FileId::BOGUS);
152152
let span_map = SpanMapRef::RealSpanMap(&span_map);
153153

154-
let (_, _, span) = db.macro_arg(actual_macro_call);
154+
let (_, _, span) = db.macro_arg_considering_derives(actual_macro_call, &loc.kind);
155155

156156
// Build the subtree and token mapping for the speculative args
157157
let (mut tt, undo_info) = match loc.kind {
@@ -346,8 +346,6 @@ pub(crate) fn parse_with_map(
346346
}
347347
}
348348

349-
/// Imagine the word smart in quotes.
350-
///
351349
/// This resolves the [MacroCallId] to check if it is a derive macro if so get the [macro_arg] for the derive.
352350
/// Other wise return the [macro_arg] for the macro_call_id.
353351
///
@@ -435,20 +433,9 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
435433
}
436434
return (Arc::new(tt), SyntaxFixupUndoInfo::NONE, span);
437435
}
438-
439436
// MacroCallKind::Derive should not be here. As we are getting the argument for the derive macro
440-
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
441-
let node = ast_id.to_ptr(db).to_node(&root);
442-
let censor_derive_input = censor_derive_input(derive_attr_index, &node);
443-
let item_node = node.into();
444-
let attr_source = attr_source(derive_attr_index, &item_node);
445-
// FIXME: This is wrong, this should point to the path of the derive attribute`
446-
let span =
447-
map.span_for_range(attr_source.as_ref().and_then(|it| it.path()).map_or_else(
448-
|| item_node.syntax().text_range(),
449-
|it| it.syntax().text_range(),
450-
));
451-
(censor_derive_input, item_node, span)
437+
MacroCallKind::Derive { .. } => {
438+
unreachable!("`ExpandDatabase::macro_arg` called with `MacroCallKind::Derive`")
452439
}
453440
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
454441
let node = ast_id.to_ptr(db).to_node(&root);
@@ -637,7 +624,7 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
637624

638625
fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt::Subtree>> {
639626
let loc = db.lookup_intern_macro_call(id);
640-
let (macro_arg, undo_info, span) = db.macro_arg_considering_derives(id, &loc.kind.clone());
627+
let (macro_arg, undo_info, span) = db.macro_arg_considering_derives(id, &loc.kind);
641628

642629
let (expander, ast) = match loc.def.kind {
643630
MacroDefKind::ProcMacro(expander, _, ast) => (expander, ast),

0 commit comments

Comments
 (0)