Skip to content

Commit 8e324e9

Browse files
committed
Rename ProcMacroKind::FuncLike to Bang
1 parent fc0d51a commit 8e324e9

File tree

18 files changed

+83
-66
lines changed

18 files changed

+83
-66
lines changed

crates/base-db/src/input.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,6 @@ impl CrateGraph {
500500
}
501501
}
502502

503-
// FIXME: this only finds one crate with the given root; we could have multiple
504-
pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
505-
let (crate_id, _) =
506-
self.arena.iter().find(|(_crate_id, data)| data.root_file_id == file_id)?;
507-
Some(crate_id)
508-
}
509-
510503
pub fn sort_deps(&mut self) {
511504
self.arena
512505
.iter_mut()

crates/hir-def/src/data.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ impl ProcMacroData {
453453
(
454454
def.name,
455455
match def.kind {
456-
ProcMacroKind::CustomDerive { helpers } => Some(helpers),
457-
ProcMacroKind::FnLike | ProcMacroKind::Attr => None,
456+
ProcMacroKind::Derive { helpers } => Some(helpers),
457+
ProcMacroKind::Bang | ProcMacroKind::Attr => None,
458458
},
459459
)
460460
} else {
@@ -484,10 +484,11 @@ impl ExternCrateDeclData {
484484
let extern_crate = &item_tree[loc.id.value];
485485

486486
let name = extern_crate.name.clone();
487+
let krate = loc.container.krate();
487488
let crate_id = if name == hir_expand::name![self] {
488-
Some(loc.container.krate())
489+
Some(krate)
489490
} else {
490-
db.crate_def_map(loc.container.krate())
491+
db.crate_def_map(krate)
491492
.extern_prelude()
492493
.find(|&(prelude_name, ..)| *prelude_name == name)
493494
.map(|(_, (root, _))| root.krate())

crates/hir-def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl MacroSubNs {
737737
MacroId::ProcMacroId(it) => {
738738
return match it.lookup(db).kind {
739739
ProcMacroKind::CustomDerive | ProcMacroKind::Attr => Self::Attr,
740-
ProcMacroKind::FuncLike => Self::Bang,
740+
ProcMacroKind::Bang => Self::Bang,
741741
};
742742
}
743743
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl DefCollector<'_> {
604604
.intern(self.db);
605605
self.define_proc_macro(def.name.clone(), proc_macro_id);
606606
let crate_data = Arc::get_mut(&mut self.def_map.data).unwrap();
607-
if let ProcMacroKind::CustomDerive { helpers } = def.kind {
607+
if let ProcMacroKind::Derive { helpers } = def.kind {
608608
crate_data.exported_derives.insert(self.db.macro_def(proc_macro_id.into()), helpers);
609609
}
610610
crate_data.fn_proc_macro_mapping.insert(fn_id, proc_macro_id);

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ pub struct ProcMacroDef {
1313

1414
#[derive(Debug, PartialEq, Eq)]
1515
pub enum ProcMacroKind {
16-
CustomDerive { helpers: Box<[Name]> },
17-
FnLike,
16+
Derive { helpers: Box<[Name]> },
17+
Bang,
1818
Attr,
1919
}
2020

2121
impl ProcMacroKind {
2222
pub(super) fn to_basedb_kind(&self) -> hir_expand::proc_macro::ProcMacroKind {
2323
match self {
24-
ProcMacroKind::CustomDerive { .. } => {
25-
hir_expand::proc_macro::ProcMacroKind::CustomDerive
26-
}
27-
ProcMacroKind::FnLike => hir_expand::proc_macro::ProcMacroKind::FuncLike,
24+
ProcMacroKind::Derive { .. } => hir_expand::proc_macro::ProcMacroKind::CustomDerive,
25+
ProcMacroKind::Bang => hir_expand::proc_macro::ProcMacroKind::Bang,
2826
ProcMacroKind::Attr => hir_expand::proc_macro::ProcMacroKind::Attr,
2927
}
3028
}
@@ -34,13 +32,13 @@ impl Attrs {
3432
#[rustfmt::skip]
3533
pub fn parse_proc_macro_decl(&self, func_name: &Name) -> Option<ProcMacroDef> {
3634
if self.is_proc_macro() {
37-
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::FnLike })
35+
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Bang })
3836
} else if self.is_proc_macro_attribute() {
3937
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Attr })
4038
} else if self.by_key("proc_macro_derive").exists() {
4139
let derive = self.by_key("proc_macro_derive").tt_values().next()?;
4240
let def = parse_macro_name_and_helper_attrs(&derive.token_trees)
43-
.map(|(name, helpers)| ProcMacroDef { name, kind: ProcMacroKind::CustomDerive { helpers } });
41+
.map(|(name, helpers)| ProcMacroDef { name, kind: ProcMacroKind::Derive { helpers } });
4442

4543
if def.is_none() {
4644
tracing::trace!("malformed `#[proc_macro_derive]`: {}", derive);

crates/hir-expand/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub struct EagerCallInfo {
200200
/// Call id of the eager macro's input file (this is the macro file for its fully expanded input).
201201
arg_id: MacroCallId,
202202
error: Option<ExpandError>,
203-
/// TODO: Doc
203+
/// The call site span of the eager macro
204204
span: Span,
205205
}
206206

@@ -211,7 +211,7 @@ pub enum MacroCallKind {
211211
expand_to: ExpandTo,
212212
/// Some if this is a macro call for an eager macro. Note that this is `None`
213213
/// for the eager input macro file.
214-
// FIXME: This is being interned, subtrees can vary quickly differ just slightly causing
214+
// FIXME: This is being interned, subtrees can vary quickly differing just slightly causing
215215
// leakage problems here
216216
eager: Option<Arc<EagerCallInfo>>,
217217
},
@@ -486,7 +486,7 @@ impl MacroDefId {
486486
matches!(
487487
self.kind,
488488
MacroDefKind::BuiltIn(..)
489-
| MacroDefKind::ProcMacro(_, ProcMacroKind::FuncLike, _)
489+
| MacroDefKind::ProcMacro(_, ProcMacroKind::Bang, _)
490490
| MacroDefKind::BuiltInEager(..)
491491
| MacroDefKind::Declarative(..)
492492
)
@@ -808,7 +808,8 @@ impl ExpansionInfo {
808808
let (parse, exp_map) = db.parse_macro_expansion(macro_file).value;
809809
let expanded = InMacroFile { file_id: macro_file, value: parse.syntax_node() };
810810

811-
let (macro_arg, _, _) = db.macro_arg(macro_file.macro_call_id);
811+
let (macro_arg, _, _) =
812+
db.macro_arg_considering_derives(macro_file.macro_call_id, &loc.kind);
812813

813814
let def = loc.def.ast_id().left().and_then(|id| {
814815
let def_tt = match id.to_node(db) {

crates/hir-expand/src/proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl ProcMacroId {
2323
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
2424
pub enum ProcMacroKind {
2525
CustomDerive,
26-
FuncLike,
26+
Bang,
2727
Attr,
2828
}
2929

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ impl Macro {
25922592
},
25932593
MacroId::ProcMacroId(it) => match it.lookup(db.upcast()).kind {
25942594
ProcMacroKind::CustomDerive => MacroKind::Derive,
2595-
ProcMacroKind::FuncLike => MacroKind::ProcMacro,
2595+
ProcMacroKind::Bang => MacroKind::ProcMacro,
25962596
ProcMacroKind::Attr => MacroKind::Attr,
25972597
},
25982598
}

crates/ide/src/syntax_highlighting/test_data/highlight_attributes.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<pre><code><span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">allow</span><span class="parenthesis attribute">(</span><span class="none attribute">dead_code</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
4949
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="tool_module attribute library">rustfmt</span><span class="operator attribute">::</span><span class="tool_module attribute library">skip</span><span class="attribute_bracket attribute">]</span>
5050
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="module attribute crate_root library">proc_macros</span><span class="operator attribute">::</span><span class="attribute attribute library">identity</span><span class="attribute_bracket attribute">]</span>
51-
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Copy</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
51+
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Default</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
5252
<span class="comment documentation">/// This is a doc comment</span>
5353
<span class="comment">// This is a normal comment</span>
5454
<span class="comment documentation">/// This is a doc comment</span>
@@ -58,4 +58,7 @@
5858
<span class="comment">// This is another normal comment</span>
5959
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Copy</span><span class="comma attribute">,</span> <span class="unresolved_reference attribute">Unresolved</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
6060
<span class="comment">// The reason for these being here is to test AttrIds</span>
61-
<span class="keyword">struct</span> <span class="struct declaration">Foo</span><span class="semicolon">;</span></code></pre>
61+
<span class="keyword">enum</span> <span class="enum declaration">Foo</span> <span class="brace">{</span>
62+
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="derive_helper attribute default_library library">default</span><span class="attribute_bracket attribute">]</span>
63+
<span class="enum_variant declaration">Bar</span>
64+
<span class="brace">}</span></code></pre>

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn attributes() {
2222
check_highlighting(
2323
r#"
2424
//- proc_macros: identity
25-
//- minicore: derive, copy
25+
//- minicore: derive, copy, default
2626
#[allow(dead_code)]
2727
#[rustfmt::skip]
2828
#[proc_macros::identity]
29-
#[derive(Copy)]
29+
#[derive(Default)]
3030
/// This is a doc comment
3131
// This is a normal comment
3232
/// This is a doc comment
@@ -36,7 +36,10 @@ fn attributes() {
3636
// This is another normal comment
3737
#[derive(Copy, Unresolved)]
3838
// The reason for these being here is to test AttrIds
39-
struct Foo;
39+
enum Foo {
40+
#[default]
41+
Bar
42+
}
4043
"#,
4144
expect_file!["./test_data/highlight_attributes.html"],
4245
false,

0 commit comments

Comments
 (0)