mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Rename ProcMacroKind::FuncLike to Bang
This commit is contained in:
parent
fc0d51ae65
commit
8e324e98a1
18 changed files with 83 additions and 66 deletions
|
@ -500,13 +500,6 @@ impl CrateGraph {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: this only finds one crate with the given root; we could have multiple
|
||||
pub fn crate_id_for_crate_root(&self, file_id: FileId) -> Option<CrateId> {
|
||||
let (crate_id, _) =
|
||||
self.arena.iter().find(|(_crate_id, data)| data.root_file_id == file_id)?;
|
||||
Some(crate_id)
|
||||
}
|
||||
|
||||
pub fn sort_deps(&mut self) {
|
||||
self.arena
|
||||
.iter_mut()
|
||||
|
|
|
@ -453,8 +453,8 @@ impl ProcMacroData {
|
|||
(
|
||||
def.name,
|
||||
match def.kind {
|
||||
ProcMacroKind::CustomDerive { helpers } => Some(helpers),
|
||||
ProcMacroKind::FnLike | ProcMacroKind::Attr => None,
|
||||
ProcMacroKind::Derive { helpers } => Some(helpers),
|
||||
ProcMacroKind::Bang | ProcMacroKind::Attr => None,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
|
@ -484,10 +484,11 @@ impl ExternCrateDeclData {
|
|||
let extern_crate = &item_tree[loc.id.value];
|
||||
|
||||
let name = extern_crate.name.clone();
|
||||
let krate = loc.container.krate();
|
||||
let crate_id = if name == hir_expand::name![self] {
|
||||
Some(loc.container.krate())
|
||||
Some(krate)
|
||||
} else {
|
||||
db.crate_def_map(loc.container.krate())
|
||||
db.crate_def_map(krate)
|
||||
.extern_prelude()
|
||||
.find(|&(prelude_name, ..)| *prelude_name == name)
|
||||
.map(|(_, (root, _))| root.krate())
|
||||
|
|
|
@ -737,7 +737,7 @@ impl MacroSubNs {
|
|||
MacroId::ProcMacroId(it) => {
|
||||
return match it.lookup(db).kind {
|
||||
ProcMacroKind::CustomDerive | ProcMacroKind::Attr => Self::Attr,
|
||||
ProcMacroKind::FuncLike => Self::Bang,
|
||||
ProcMacroKind::Bang => Self::Bang,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -604,7 +604,7 @@ impl DefCollector<'_> {
|
|||
.intern(self.db);
|
||||
self.define_proc_macro(def.name.clone(), proc_macro_id);
|
||||
let crate_data = Arc::get_mut(&mut self.def_map.data).unwrap();
|
||||
if let ProcMacroKind::CustomDerive { helpers } = def.kind {
|
||||
if let ProcMacroKind::Derive { helpers } = def.kind {
|
||||
crate_data.exported_derives.insert(self.db.macro_def(proc_macro_id.into()), helpers);
|
||||
}
|
||||
crate_data.fn_proc_macro_mapping.insert(fn_id, proc_macro_id);
|
||||
|
|
|
@ -13,18 +13,16 @@ pub struct ProcMacroDef {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive { helpers: Box<[Name]> },
|
||||
FnLike,
|
||||
Derive { helpers: Box<[Name]> },
|
||||
Bang,
|
||||
Attr,
|
||||
}
|
||||
|
||||
impl ProcMacroKind {
|
||||
pub(super) fn to_basedb_kind(&self) -> hir_expand::proc_macro::ProcMacroKind {
|
||||
match self {
|
||||
ProcMacroKind::CustomDerive { .. } => {
|
||||
hir_expand::proc_macro::ProcMacroKind::CustomDerive
|
||||
}
|
||||
ProcMacroKind::FnLike => hir_expand::proc_macro::ProcMacroKind::FuncLike,
|
||||
ProcMacroKind::Derive { .. } => hir_expand::proc_macro::ProcMacroKind::CustomDerive,
|
||||
ProcMacroKind::Bang => hir_expand::proc_macro::ProcMacroKind::Bang,
|
||||
ProcMacroKind::Attr => hir_expand::proc_macro::ProcMacroKind::Attr,
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +32,13 @@ impl Attrs {
|
|||
#[rustfmt::skip]
|
||||
pub fn parse_proc_macro_decl(&self, func_name: &Name) -> Option<ProcMacroDef> {
|
||||
if self.is_proc_macro() {
|
||||
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::FnLike })
|
||||
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Bang })
|
||||
} else if self.is_proc_macro_attribute() {
|
||||
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Attr })
|
||||
} else if self.by_key("proc_macro_derive").exists() {
|
||||
let derive = self.by_key("proc_macro_derive").tt_values().next()?;
|
||||
let def = parse_macro_name_and_helper_attrs(&derive.token_trees)
|
||||
.map(|(name, helpers)| ProcMacroDef { name, kind: ProcMacroKind::CustomDerive { helpers } });
|
||||
.map(|(name, helpers)| ProcMacroDef { name, kind: ProcMacroKind::Derive { helpers } });
|
||||
|
||||
if def.is_none() {
|
||||
tracing::trace!("malformed `#[proc_macro_derive]`: {}", derive);
|
||||
|
|
|
@ -200,7 +200,7 @@ pub struct EagerCallInfo {
|
|||
/// Call id of the eager macro's input file (this is the macro file for its fully expanded input).
|
||||
arg_id: MacroCallId,
|
||||
error: Option<ExpandError>,
|
||||
/// TODO: Doc
|
||||
/// The call site span of the eager macro
|
||||
span: Span,
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ pub enum MacroCallKind {
|
|||
expand_to: ExpandTo,
|
||||
/// Some if this is a macro call for an eager macro. Note that this is `None`
|
||||
/// for the eager input macro file.
|
||||
// FIXME: This is being interned, subtrees can vary quickly differ just slightly causing
|
||||
// FIXME: This is being interned, subtrees can vary quickly differing just slightly causing
|
||||
// leakage problems here
|
||||
eager: Option<Arc<EagerCallInfo>>,
|
||||
},
|
||||
|
@ -486,7 +486,7 @@ impl MacroDefId {
|
|||
matches!(
|
||||
self.kind,
|
||||
MacroDefKind::BuiltIn(..)
|
||||
| MacroDefKind::ProcMacro(_, ProcMacroKind::FuncLike, _)
|
||||
| MacroDefKind::ProcMacro(_, ProcMacroKind::Bang, _)
|
||||
| MacroDefKind::BuiltInEager(..)
|
||||
| MacroDefKind::Declarative(..)
|
||||
)
|
||||
|
@ -808,7 +808,8 @@ impl ExpansionInfo {
|
|||
let (parse, exp_map) = db.parse_macro_expansion(macro_file).value;
|
||||
let expanded = InMacroFile { file_id: macro_file, value: parse.syntax_node() };
|
||||
|
||||
let (macro_arg, _, _) = db.macro_arg(macro_file.macro_call_id);
|
||||
let (macro_arg, _, _) =
|
||||
db.macro_arg_considering_derives(macro_file.macro_call_id, &loc.kind);
|
||||
|
||||
let def = loc.def.ast_id().left().and_then(|id| {
|
||||
let def_tt = match id.to_node(db) {
|
||||
|
|
|
@ -23,7 +23,7 @@ impl ProcMacroId {
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive,
|
||||
FuncLike,
|
||||
Bang,
|
||||
Attr,
|
||||
}
|
||||
|
||||
|
|
|
@ -2592,7 +2592,7 @@ impl Macro {
|
|||
},
|
||||
MacroId::ProcMacroId(it) => match it.lookup(db.upcast()).kind {
|
||||
ProcMacroKind::CustomDerive => MacroKind::Derive,
|
||||
ProcMacroKind::FuncLike => MacroKind::ProcMacro,
|
||||
ProcMacroKind::Bang => MacroKind::ProcMacro,
|
||||
ProcMacroKind::Attr => MacroKind::Attr,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<span class="comment documentation">/// This is a doc comment</span>
|
||||
<span class="comment">// This is a normal comment</span>
|
||||
<span class="comment documentation">/// This is a doc comment</span>
|
||||
|
@ -58,4 +58,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="comment">// This is another normal comment</span>
|
||||
<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>
|
||||
<span class="comment">// The reason for these being here is to test AttrIds</span>
|
||||
<span class="keyword">struct</span> <span class="struct declaration">Foo</span><span class="semicolon">;</span></code></pre>
|
||||
<span class="keyword">enum</span> <span class="enum declaration">Foo</span> <span class="brace">{</span>
|
||||
<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>
|
||||
<span class="enum_variant declaration">Bar</span>
|
||||
<span class="brace">}</span></code></pre>
|
|
@ -22,11 +22,11 @@ fn attributes() {
|
|||
check_highlighting(
|
||||
r#"
|
||||
//- proc_macros: identity
|
||||
//- minicore: derive, copy
|
||||
//- minicore: derive, copy, default
|
||||
#[allow(dead_code)]
|
||||
#[rustfmt::skip]
|
||||
#[proc_macros::identity]
|
||||
#[derive(Copy)]
|
||||
#[derive(Default)]
|
||||
/// This is a doc comment
|
||||
// This is a normal comment
|
||||
/// This is a doc comment
|
||||
|
@ -36,7 +36,10 @@ fn attributes() {
|
|||
// This is another normal comment
|
||||
#[derive(Copy, Unresolved)]
|
||||
// The reason for these being here is to test AttrIds
|
||||
struct Foo;
|
||||
enum Foo {
|
||||
#[default]
|
||||
Bar
|
||||
}
|
||||
"#,
|
||||
expect_file!["./test_data/highlight_attributes.html"],
|
||||
false,
|
||||
|
|
|
@ -387,7 +387,7 @@ fn expander_to_proc_macro(
|
|||
let name = From::from(expander.name());
|
||||
let kind = match expander.kind() {
|
||||
proc_macro_api::ProcMacroKind::CustomDerive => ProcMacroKind::CustomDerive,
|
||||
proc_macro_api::ProcMacroKind::FuncLike => ProcMacroKind::FuncLike,
|
||||
proc_macro_api::ProcMacroKind::Bang => ProcMacroKind::Bang,
|
||||
proc_macro_api::ProcMacroKind::Attr => ProcMacroKind::Attr,
|
||||
};
|
||||
let disabled = ignored_macros.iter().any(|replace| **replace == name);
|
||||
|
|
|
@ -35,8 +35,11 @@ pub use version::{read_dylib_info, read_version, RustCInfo};
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive,
|
||||
FuncLike,
|
||||
Attr,
|
||||
// This used to be called FuncLike, so that's what the server expects currently.
|
||||
#[serde(alias = "bang")]
|
||||
#[serde(rename(serialize = "func_like", deserialize = "func_like"))]
|
||||
Bang,
|
||||
}
|
||||
|
||||
/// A handle to an external process which load dylibs with macros (.so or .dll)
|
||||
|
|
|
@ -108,7 +108,7 @@ impl ProcMacros {
|
|||
(trait_name.to_string(), ProcMacroKind::CustomDerive)
|
||||
}
|
||||
bridge::client::ProcMacro::Bang { name, .. } => {
|
||||
(name.to_string(), ProcMacroKind::FuncLike)
|
||||
(name.to_string(), ProcMacroKind::Bang)
|
||||
}
|
||||
bridge::client::ProcMacro::Attr { name, .. } => {
|
||||
(name.to_string(), ProcMacroKind::Attr)
|
||||
|
|
|
@ -254,14 +254,14 @@ fn list_test_macros() {
|
|||
let res = list().join("\n");
|
||||
|
||||
expect![[r#"
|
||||
fn_like_noop [FuncLike]
|
||||
fn_like_panic [FuncLike]
|
||||
fn_like_error [FuncLike]
|
||||
fn_like_clone_tokens [FuncLike]
|
||||
fn_like_mk_literals [FuncLike]
|
||||
fn_like_mk_idents [FuncLike]
|
||||
fn_like_span_join [FuncLike]
|
||||
fn_like_span_ops [FuncLike]
|
||||
fn_like_noop [Bang]
|
||||
fn_like_panic [Bang]
|
||||
fn_like_error [Bang]
|
||||
fn_like_clone_tokens [Bang]
|
||||
fn_like_mk_literals [Bang]
|
||||
fn_like_mk_idents [Bang]
|
||||
fn_like_span_join [Bang]
|
||||
fn_like_span_ops [Bang]
|
||||
attr_noop [Attr]
|
||||
attr_panic [Attr]
|
||||
attr_error [Attr]
|
||||
|
|
|
@ -719,19 +719,22 @@ impl ProjectWorkspace {
|
|||
) -> (CrateGraph, ProcMacroPaths) {
|
||||
let _p = tracing::span!(tracing::Level::INFO, "ProjectWorkspace::to_crate_graph").entered();
|
||||
|
||||
let (mut crate_graph, proc_macros) = match self {
|
||||
let ((mut crate_graph, proc_macros), sysroot) = match self {
|
||||
ProjectWorkspace::Json {
|
||||
project,
|
||||
sysroot,
|
||||
rustc_cfg,
|
||||
toolchain: _,
|
||||
target_layout: _,
|
||||
} => project_json_to_crate_graph(
|
||||
rustc_cfg.clone(),
|
||||
load,
|
||||
project,
|
||||
sysroot.as_ref().ok(),
|
||||
extra_env,
|
||||
} => (
|
||||
project_json_to_crate_graph(
|
||||
rustc_cfg.clone(),
|
||||
load,
|
||||
project,
|
||||
sysroot.as_ref().ok(),
|
||||
extra_env,
|
||||
),
|
||||
sysroot,
|
||||
),
|
||||
ProjectWorkspace::Cargo {
|
||||
cargo,
|
||||
|
@ -743,14 +746,17 @@ impl ProjectWorkspace {
|
|||
toolchain: _,
|
||||
target_layout: _,
|
||||
cargo_config_extra_env: _,
|
||||
} => cargo_to_crate_graph(
|
||||
load,
|
||||
rustc.as_ref().map(|a| a.as_ref()).ok(),
|
||||
cargo,
|
||||
sysroot.as_ref().ok(),
|
||||
rustc_cfg.clone(),
|
||||
cfg_overrides,
|
||||
build_scripts,
|
||||
} => (
|
||||
cargo_to_crate_graph(
|
||||
load,
|
||||
rustc.as_ref().map(|a| a.as_ref()).ok(),
|
||||
cargo,
|
||||
sysroot.as_ref().ok(),
|
||||
rustc_cfg.clone(),
|
||||
cfg_overrides,
|
||||
build_scripts,
|
||||
),
|
||||
sysroot,
|
||||
),
|
||||
ProjectWorkspace::DetachedFiles {
|
||||
files,
|
||||
|
@ -758,11 +764,20 @@ impl ProjectWorkspace {
|
|||
rustc_cfg,
|
||||
toolchain: _,
|
||||
target_layout: _,
|
||||
} => {
|
||||
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot.as_ref().ok())
|
||||
}
|
||||
} => (
|
||||
detached_files_to_crate_graph(
|
||||
rustc_cfg.clone(),
|
||||
load,
|
||||
files,
|
||||
sysroot.as_ref().ok(),
|
||||
),
|
||||
sysroot,
|
||||
),
|
||||
};
|
||||
if crate_graph.patch_cfg_if() {
|
||||
|
||||
if matches!(sysroot.as_ref().map(|it| it.mode()), Ok(SysrootMode::Workspace(_)))
|
||||
&& crate_graph.patch_cfg_if()
|
||||
{
|
||||
tracing::debug!("Patched std to depend on cfg-if")
|
||||
} else {
|
||||
tracing::debug!("Did not patch std to depend on cfg-if")
|
||||
|
|
|
@ -26,7 +26,6 @@ use itertools::Itertools;
|
|||
use load_cargo::{load_proc_macro, ProjectFolders};
|
||||
use proc_macro_api::ProcMacroServer;
|
||||
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
|
||||
use rustc_hash::FxHashSet;
|
||||
use stdx::{format_to, thread::ThreadIntent};
|
||||
use triomphe::Arc;
|
||||
use vfs::{AbsPath, AbsPathBuf, ChangeKind};
|
||||
|
@ -526,7 +525,7 @@ impl GlobalState {
|
|||
fn recreate_crate_graph(&mut self, cause: String) {
|
||||
// crate graph construction relies on these paths, record them so when one of them gets
|
||||
// deleted or created we trigger a reconstruction of the crate graph
|
||||
let mut crate_graph_file_dependencies = FxHashSet::default();
|
||||
let mut crate_graph_file_dependencies = mem::take(&mut self.crate_graph_file_dependencies);
|
||||
self.report_progress(
|
||||
"Building CrateGraph",
|
||||
crate::lsp::utils::Progress::Begin,
|
||||
|
|
|
@ -903,6 +903,7 @@ fn out_dirs_check() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))] // windows requires elevated permissions to create symlinks
|
||||
fn root_contains_symlink_out_dirs_check() {
|
||||
out_dirs_check_impl(true);
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ pub fn mirror(input: TokenStream) -> TokenStream {
|
|||
.into(),
|
||||
ProcMacro {
|
||||
name: "mirror".into(),
|
||||
kind: ProcMacroKind::FuncLike,
|
||||
kind: ProcMacroKind::Bang,
|
||||
expander: sync::Arc::new(MirrorProcMacroExpander),
|
||||
disabled: false,
|
||||
},
|
||||
|
@ -417,7 +417,7 @@ pub fn shorten(input: TokenStream) -> TokenStream {
|
|||
.into(),
|
||||
ProcMacro {
|
||||
name: "shorten".into(),
|
||||
kind: ProcMacroKind::FuncLike,
|
||||
kind: ProcMacroKind::Bang,
|
||||
expander: sync::Arc::new(ShortenProcMacroExpander),
|
||||
disabled: false,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue