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

Commit 6f54ebb

Browse files
committed
Auto merge of rust-lang#16905 - Veykril:sysroot-patch-cfg, r=Veykril
internal: Rename ProcMacroKind::FuncLike to Bang
2 parents fc0d51a + 8e324e9 commit 6f54ebb

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,

crates/load-cargo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn expander_to_proc_macro(
387387
let name = From::from(expander.name());
388388
let kind = match expander.kind() {
389389
proc_macro_api::ProcMacroKind::CustomDerive => ProcMacroKind::CustomDerive,
390-
proc_macro_api::ProcMacroKind::FuncLike => ProcMacroKind::FuncLike,
390+
proc_macro_api::ProcMacroKind::Bang => ProcMacroKind::Bang,
391391
proc_macro_api::ProcMacroKind::Attr => ProcMacroKind::Attr,
392392
};
393393
let disabled = ignored_macros.iter().any(|replace| **replace == name);

crates/proc-macro-api/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ pub use version::{read_dylib_info, read_version, RustCInfo};
3535
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
3636
pub enum ProcMacroKind {
3737
CustomDerive,
38-
FuncLike,
3938
Attr,
39+
// This used to be called FuncLike, so that's what the server expects currently.
40+
#[serde(alias = "bang")]
41+
#[serde(rename(serialize = "func_like", deserialize = "func_like"))]
42+
Bang,
4043
}
4144

4245
/// A handle to an external process which load dylibs with macros (.so or .dll)

crates/proc-macro-srv/src/proc_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl ProcMacros {
108108
(trait_name.to_string(), ProcMacroKind::CustomDerive)
109109
}
110110
bridge::client::ProcMacro::Bang { name, .. } => {
111-
(name.to_string(), ProcMacroKind::FuncLike)
111+
(name.to_string(), ProcMacroKind::Bang)
112112
}
113113
bridge::client::ProcMacro::Attr { name, .. } => {
114114
(name.to_string(), ProcMacroKind::Attr)

crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ fn list_test_macros() {
254254
let res = list().join("\n");
255255

256256
expect![[r#"
257-
fn_like_noop [FuncLike]
258-
fn_like_panic [FuncLike]
259-
fn_like_error [FuncLike]
260-
fn_like_clone_tokens [FuncLike]
261-
fn_like_mk_literals [FuncLike]
262-
fn_like_mk_idents [FuncLike]
263-
fn_like_span_join [FuncLike]
264-
fn_like_span_ops [FuncLike]
257+
fn_like_noop [Bang]
258+
fn_like_panic [Bang]
259+
fn_like_error [Bang]
260+
fn_like_clone_tokens [Bang]
261+
fn_like_mk_literals [Bang]
262+
fn_like_mk_idents [Bang]
263+
fn_like_span_join [Bang]
264+
fn_like_span_ops [Bang]
265265
attr_noop [Attr]
266266
attr_panic [Attr]
267267
attr_error [Attr]

crates/project-model/src/workspace.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -719,19 +719,22 @@ impl ProjectWorkspace {
719719
) -> (CrateGraph, ProcMacroPaths) {
720720
let _p = tracing::span!(tracing::Level::INFO, "ProjectWorkspace::to_crate_graph").entered();
721721

722-
let (mut crate_graph, proc_macros) = match self {
722+
let ((mut crate_graph, proc_macros), sysroot) = match self {
723723
ProjectWorkspace::Json {
724724
project,
725725
sysroot,
726726
rustc_cfg,
727727
toolchain: _,
728728
target_layout: _,
729-
} => project_json_to_crate_graph(
730-
rustc_cfg.clone(),
731-
load,
732-
project,
733-
sysroot.as_ref().ok(),
734-
extra_env,
729+
} => (
730+
project_json_to_crate_graph(
731+
rustc_cfg.clone(),
732+
load,
733+
project,
734+
sysroot.as_ref().ok(),
735+
extra_env,
736+
),
737+
sysroot,
735738
),
736739
ProjectWorkspace::Cargo {
737740
cargo,
@@ -743,26 +746,38 @@ impl ProjectWorkspace {
743746
toolchain: _,
744747
target_layout: _,
745748
cargo_config_extra_env: _,
746-
} => cargo_to_crate_graph(
747-
load,
748-
rustc.as_ref().map(|a| a.as_ref()).ok(),
749-
cargo,
750-
sysroot.as_ref().ok(),
751-
rustc_cfg.clone(),
752-
cfg_overrides,
753-
build_scripts,
749+
} => (
750+
cargo_to_crate_graph(
751+
load,
752+
rustc.as_ref().map(|a| a.as_ref()).ok(),
753+
cargo,
754+
sysroot.as_ref().ok(),
755+
rustc_cfg.clone(),
756+
cfg_overrides,
757+
build_scripts,
758+
),
759+
sysroot,
754760
),
755761
ProjectWorkspace::DetachedFiles {
756762
files,
757763
sysroot,
758764
rustc_cfg,
759765
toolchain: _,
760766
target_layout: _,
761-
} => {
762-
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot.as_ref().ok())
763-
}
767+
} => (
768+
detached_files_to_crate_graph(
769+
rustc_cfg.clone(),
770+
load,
771+
files,
772+
sysroot.as_ref().ok(),
773+
),
774+
sysroot,
775+
),
764776
};
765-
if crate_graph.patch_cfg_if() {
777+
778+
if matches!(sysroot.as_ref().map(|it| it.mode()), Ok(SysrootMode::Workspace(_)))
779+
&& crate_graph.patch_cfg_if()
780+
{
766781
tracing::debug!("Patched std to depend on cfg-if")
767782
} else {
768783
tracing::debug!("Did not patch std to depend on cfg-if")

crates/rust-analyzer/src/reload.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use itertools::Itertools;
2626
use load_cargo::{load_proc_macro, ProjectFolders};
2727
use proc_macro_api::ProcMacroServer;
2828
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
29-
use rustc_hash::FxHashSet;
3029
use stdx::{format_to, thread::ThreadIntent};
3130
use triomphe::Arc;
3231
use vfs::{AbsPath, AbsPathBuf, ChangeKind};
@@ -526,7 +525,7 @@ impl GlobalState {
526525
fn recreate_crate_graph(&mut self, cause: String) {
527526
// crate graph construction relies on these paths, record them so when one of them gets
528527
// deleted or created we trigger a reconstruction of the crate graph
529-
let mut crate_graph_file_dependencies = FxHashSet::default();
528+
let mut crate_graph_file_dependencies = mem::take(&mut self.crate_graph_file_dependencies);
530529
self.report_progress(
531530
"Building CrateGraph",
532531
crate::lsp::utils::Progress::Begin,

crates/rust-analyzer/tests/slow-tests/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ fn out_dirs_check() {
903903
}
904904

905905
#[test]
906+
#[cfg(not(windows))] // windows requires elevated permissions to create symlinks
906907
fn root_contains_symlink_out_dirs_check() {
907908
out_dirs_check_impl(true);
908909
}

crates/test-fixture/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub fn mirror(input: TokenStream) -> TokenStream {
402402
.into(),
403403
ProcMacro {
404404
name: "mirror".into(),
405-
kind: ProcMacroKind::FuncLike,
405+
kind: ProcMacroKind::Bang,
406406
expander: sync::Arc::new(MirrorProcMacroExpander),
407407
disabled: false,
408408
},
@@ -417,7 +417,7 @@ pub fn shorten(input: TokenStream) -> TokenStream {
417417
.into(),
418418
ProcMacro {
419419
name: "shorten".into(),
420-
kind: ProcMacroKind::FuncLike,
420+
kind: ProcMacroKind::Bang,
421421
expander: sync::Arc::new(ShortenProcMacroExpander),
422422
disabled: false,
423423
},

0 commit comments

Comments
 (0)