Skip to content

Commit b2f8c16

Browse files
authored
Rollup merge of #149390 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@a2a4a95. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents 4912d12 + ac118f9 commit b2f8c16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1603
-362
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,18 @@ version = "1.15.0"
560560
source = "registry+https://github.com/rust-lang/crates.io-index"
561561
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
562562

563+
[[package]]
564+
name = "embedded-io"
565+
version = "0.4.0"
566+
source = "registry+https://github.com/rust-lang/crates.io-index"
567+
checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced"
568+
569+
[[package]]
570+
name = "embedded-io"
571+
version = "0.6.1"
572+
source = "registry+https://github.com/rust-lang/crates.io-index"
573+
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
574+
563575
[[package]]
564576
name = "ena"
565577
version = "0.14.3"
@@ -1456,6 +1468,7 @@ name = "mbe"
14561468
version = "0.0.0"
14571469
dependencies = [
14581470
"arrayvec",
1471+
"bitflags 2.9.4",
14591472
"cov-mark",
14601473
"expect-test",
14611474
"intern",
@@ -1785,6 +1798,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
17851798
checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24"
17861799
dependencies = [
17871800
"cobs",
1801+
"embedded-io 0.4.0",
1802+
"embedded-io 0.6.1",
17881803
"heapless",
17891804
"serde",
17901805
]
@@ -1820,8 +1835,10 @@ dependencies = [
18201835
"indexmap",
18211836
"intern",
18221837
"paths",
1838+
"postcard",
18231839
"proc-macro-srv",
18241840
"rustc-hash 2.1.1",
1841+
"semver",
18251842
"serde",
18261843
"serde_derive",
18271844
"serde_json",

src/tools/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ object = { version = "0.36.7", default-features = false, features = [
127127
"macho",
128128
"pe",
129129
] }
130+
postcard = {version = "1.1.3", features = ["alloc"]}
130131
process-wrap = { version = "8.2.1", features = ["std"] }
131132
pulldown-cmark-to-cmark = "10.0.4"
132133
pulldown-cmark = { version = "0.9.6", default-features = false }

src/tools/rust-analyzer/crates/hir-def/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
338338
let kind = |expander, file_id, m| {
339339
let in_file = InFile::new(file_id, m);
340340
match expander {
341-
MacroExpander::Declarative => MacroDefKind::Declarative(in_file),
341+
MacroExpander::Declarative { styles } => MacroDefKind::Declarative(in_file, styles),
342342
MacroExpander::BuiltIn(it) => MacroDefKind::BuiltIn(in_file, it),
343343
MacroExpander::BuiltInAttr(it) => MacroDefKind::BuiltInAttr(in_file, it),
344344
MacroExpander::BuiltInDerive(it) => MacroDefKind::BuiltInDerive(in_file, it),

src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,16 @@ impl TypeRef {
195195
TypeRef::Tuple(ThinVec::new())
196196
}
197197

198-
pub fn walk(this: TypeRefId, map: &ExpressionStore, f: &mut impl FnMut(&TypeRef)) {
198+
pub fn walk(this: TypeRefId, map: &ExpressionStore, f: &mut impl FnMut(TypeRefId, &TypeRef)) {
199199
go(this, f, map);
200200

201-
fn go(type_ref: TypeRefId, f: &mut impl FnMut(&TypeRef), map: &ExpressionStore) {
202-
let type_ref = &map[type_ref];
203-
f(type_ref);
201+
fn go(
202+
type_ref_id: TypeRefId,
203+
f: &mut impl FnMut(TypeRefId, &TypeRef),
204+
map: &ExpressionStore,
205+
) {
206+
let type_ref = &map[type_ref_id];
207+
f(type_ref_id, type_ref);
204208
match type_ref {
205209
TypeRef::Fn(fn_) => {
206210
fn_.params.iter().for_each(|&(_, param_type)| go(param_type, f, map))
@@ -224,7 +228,7 @@ impl TypeRef {
224228
};
225229
}
226230

227-
fn go_path(path: &Path, f: &mut impl FnMut(&TypeRef), map: &ExpressionStore) {
231+
fn go_path(path: &Path, f: &mut impl FnMut(TypeRefId, &TypeRef), map: &ExpressionStore) {
228232
if let Some(type_ref) = path.type_anchor() {
229233
go(type_ref, f, map);
230234
}

src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use thin_vec::ThinVec;
1717

1818
use crate::{
1919
AdtId, BuiltinType, ConstId, ExternBlockId, ExternCrateId, FxIndexMap, HasModule, ImplId,
20-
LocalModuleId, Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
20+
LocalModuleId, Lookup, MacroCallStyles, MacroId, ModuleDefId, ModuleId, TraitId, UseId,
2121
db::DefDatabase,
22-
nameres::MacroSubNs,
2322
per_ns::{Item, MacrosItem, PerNs, TypesItem, ValuesItem},
2423
visibility::Visibility,
2524
};
@@ -740,11 +739,15 @@ impl ItemScope {
740739
let mut entries: Vec<_> = self.resolutions().collect();
741740
entries.sort_by_key(|(name, _)| name.clone());
742741

743-
let print_macro_sub_ns =
744-
|buf: &mut String, macro_id: MacroId| match MacroSubNs::from_id(db, macro_id) {
745-
MacroSubNs::Bang => buf.push('!'),
746-
MacroSubNs::Attr => buf.push('#'),
747-
};
742+
let print_macro_sub_ns = |buf: &mut String, macro_id: MacroId| {
743+
let styles = crate::nameres::macro_styles_from_id(db, macro_id);
744+
if styles.contains(MacroCallStyles::FN_LIKE) {
745+
buf.push('!');
746+
}
747+
if styles.contains(MacroCallStyles::ATTR) || styles.contains(MacroCallStyles::DERIVE) {
748+
buf.push('#');
749+
}
750+
};
748751

749752
for (name, def) in entries {
750753
let display_name: &dyn fmt::Display = match &name {

src/tools/rust-analyzer/crates/hir-def/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use std::hash::{Hash, Hasher};
6161

6262
use base_db::{Crate, impl_intern_key};
6363
use hir_expand::{
64-
AstId, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId,
65-
MacroDefKind,
64+
AstId, ExpandResult, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroCallStyles,
65+
MacroDefId, MacroDefKind,
6666
builtin::{BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander},
6767
db::ExpandDatabase,
6868
eager::expand_eager_macro_input,
@@ -403,7 +403,7 @@ bitflags::bitflags! {
403403

404404
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
405405
pub enum MacroExpander {
406-
Declarative,
406+
Declarative { styles: MacroCallStyles },
407407
BuiltIn(BuiltinFnLikeExpander),
408408
BuiltInAttr(BuiltinAttrExpander),
409409
BuiltInDerive(BuiltinDeriveExpander),

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use tt::TextRange;
7777

7878
use crate::{
7979
AstId, BlockId, BlockLoc, CrateRootModuleId, ExternCrateId, FunctionId, FxIndexMap,
80-
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
80+
LocalModuleId, Lookup, MacroCallStyles, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
8181
db::DefDatabase,
8282
item_scope::{BuiltinShadowMode, ItemScope},
8383
item_tree::TreeId,
@@ -813,26 +813,25 @@ pub enum MacroSubNs {
813813
Attr,
814814
}
815815

816-
impl MacroSubNs {
817-
pub(crate) fn from_id(db: &dyn DefDatabase, macro_id: MacroId) -> Self {
818-
let expander = match macro_id {
819-
MacroId::Macro2Id(it) => it.lookup(db).expander,
820-
MacroId::MacroRulesId(it) => it.lookup(db).expander,
821-
MacroId::ProcMacroId(it) => {
822-
return match it.lookup(db).kind {
823-
ProcMacroKind::CustomDerive | ProcMacroKind::Attr => Self::Attr,
824-
ProcMacroKind::Bang => Self::Bang,
825-
};
826-
}
827-
};
816+
pub(crate) fn macro_styles_from_id(db: &dyn DefDatabase, macro_id: MacroId) -> MacroCallStyles {
817+
let expander = match macro_id {
818+
MacroId::Macro2Id(it) => it.lookup(db).expander,
819+
MacroId::MacroRulesId(it) => it.lookup(db).expander,
820+
MacroId::ProcMacroId(it) => {
821+
return match it.lookup(db).kind {
822+
ProcMacroKind::CustomDerive => MacroCallStyles::DERIVE,
823+
ProcMacroKind::Bang => MacroCallStyles::FN_LIKE,
824+
ProcMacroKind::Attr => MacroCallStyles::ATTR,
825+
};
826+
}
827+
};
828828

829+
match expander {
830+
MacroExpander::Declarative { styles } => styles,
829831
// Eager macros aren't *guaranteed* to be bang macros, but they *are* all bang macros currently.
830-
match expander {
831-
MacroExpander::Declarative
832-
| MacroExpander::BuiltIn(_)
833-
| MacroExpander::BuiltInEager(_) => Self::Bang,
834-
MacroExpander::BuiltInAttr(_) | MacroExpander::BuiltInDerive(_) => Self::Attr,
835-
}
832+
MacroExpander::BuiltIn(_) | MacroExpander::BuiltInEager(_) => MacroCallStyles::FN_LIKE,
833+
MacroExpander::BuiltInAttr(_) => MacroCallStyles::ATTR,
834+
MacroExpander::BuiltInDerive(_) => MacroCallStyles::DERIVE,
836835
}
837836
}
838837

@@ -842,9 +841,19 @@ impl MacroSubNs {
842841
/// We ignore resolutions from one sub-namespace when searching names in scope for another.
843842
///
844843
/// [rustc]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_resolve/src/macros.rs#L75
845-
fn sub_namespace_match(candidate: Option<MacroSubNs>, expected: Option<MacroSubNs>) -> bool {
846-
match (candidate, expected) {
847-
(Some(candidate), Some(expected)) => candidate == expected,
848-
_ => true,
844+
fn sub_namespace_match(
845+
db: &dyn DefDatabase,
846+
macro_id: MacroId,
847+
expected: Option<MacroSubNs>,
848+
) -> bool {
849+
let candidate = macro_styles_from_id(db, macro_id);
850+
match expected {
851+
Some(MacroSubNs::Bang) => candidate.contains(MacroCallStyles::FN_LIKE),
852+
Some(MacroSubNs::Attr) => {
853+
candidate.contains(MacroCallStyles::ATTR) || candidate.contains(MacroCallStyles::DERIVE)
854+
}
855+
// If we aren't expecting a specific sub-namespace
856+
// (e.g. in `use` declarations), match any macro.
857+
None => true,
849858
}
850859
}

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,10 @@ impl ModCollector<'_, '_> {
23002300
}
23012301
} else {
23022302
// Case 2: normal `macro_rules!` macro
2303-
MacroExpander::Declarative
2303+
let id = InFile::new(self.file_id(), ast_id);
2304+
let decl_expander = self.def_collector.db.decl_macro_expander(krate, id.upcast());
2305+
let styles = decl_expander.mac.rule_styles();
2306+
MacroExpander::Declarative { styles }
23042307
};
23052308
let allow_internal_unsafe = attrs.by_key(sym::allow_internal_unsafe).exists();
23062309

@@ -2369,7 +2372,10 @@ impl ModCollector<'_, '_> {
23692372
}
23702373
} else {
23712374
// Case 2: normal `macro`
2372-
MacroExpander::Declarative
2375+
let id = InFile::new(self.file_id(), ast_id);
2376+
let decl_expander = self.def_collector.db.decl_macro_expander(krate, id.upcast());
2377+
let styles = decl_expander.mac.rule_styles();
2378+
MacroExpander::Declarative { styles }
23732379
};
23742380
let allow_internal_unsafe = attrs.by_key(sym::allow_internal_unsafe).exists();
23752381

@@ -2429,12 +2435,7 @@ impl ModCollector<'_, '_> {
24292435
})
24302436
.or_else(|| def_map[self.module_id].scope.get(name).take_macros())
24312437
.or_else(|| Some(def_map.macro_use_prelude.get(name).copied()?.0))
2432-
.filter(|&id| {
2433-
sub_namespace_match(
2434-
Some(MacroSubNs::from_id(db, id)),
2435-
Some(MacroSubNs::Bang),
2436-
)
2437-
})
2438+
.filter(|&id| sub_namespace_match(db, id, Some(MacroSubNs::Bang)))
24382439
.map(|it| self.def_collector.db.macro_def(it))
24392440
})
24402441
},

src/tools/rust-analyzer/crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ impl PerNs {
8585
db: &dyn DefDatabase,
8686
expected: Option<MacroSubNs>,
8787
) -> Self {
88-
self.macros = self.macros.filter(|def| {
89-
let this = MacroSubNs::from_id(db, def.def);
90-
sub_namespace_match(Some(this), expected)
91-
});
88+
self.macros = self.macros.filter(|def| sub_namespace_match(db, def.def, expected));
9289

9390
self
9491
}
@@ -668,9 +665,7 @@ impl DefMap {
668665
// FIXME: shadowing
669666
.and_then(|it| it.last())
670667
.copied()
671-
.filter(|&id| {
672-
sub_namespace_match(Some(MacroSubNs::from_id(db, id)), expected_macro_subns)
673-
})
668+
.filter(|&id| sub_namespace_match(db, id, expected_macro_subns))
674669
.map_or_else(PerNs::none, |m| PerNs::macros(m, Visibility::Public, None));
675670
let from_scope = self[module].scope.get(name).filter_macro(db, expected_macro_subns);
676671
let from_builtin = match self.block {

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/incremental.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub struct S {}
222222
"ast_id_map_shim",
223223
"parse_shim",
224224
"real_span_map_shim",
225+
"decl_macro_expander_shim",
225226
"file_item_tree_query",
226227
"ast_id_map_shim",
227228
"parse_shim",
@@ -235,7 +236,6 @@ pub struct S {}
235236
"ast_id_map_shim",
236237
"parse_macro_expansion_shim",
237238
"macro_arg_shim",
238-
"decl_macro_expander_shim",
239239
]
240240
"#]],
241241
expect![[r#"
@@ -404,6 +404,7 @@ pub struct S {}
404404
"ast_id_map_shim",
405405
"parse_shim",
406406
"real_span_map_shim",
407+
"decl_macro_expander_shim",
407408
"file_item_tree_query",
408409
"ast_id_map_shim",
409410
"parse_shim",
@@ -423,7 +424,6 @@ pub struct S {}
423424
"ast_id_map_shim",
424425
"parse_macro_expansion_shim",
425426
"macro_arg_shim",
426-
"decl_macro_expander_shim",
427427
"crate_local_def_map",
428428
"proc_macros_for_crate_shim",
429429
"file_item_tree_query",
@@ -446,9 +446,9 @@ pub struct S {}
446446
"file_item_tree_query",
447447
"real_span_map_shim",
448448
"macro_arg_shim",
449-
"macro_arg_shim",
450449
"decl_macro_expander_shim",
451450
"macro_arg_shim",
451+
"macro_arg_shim",
452452
]
453453
"#]],
454454
);
@@ -520,6 +520,7 @@ m!(Z);
520520
"ast_id_map_shim",
521521
"parse_shim",
522522
"real_span_map_shim",
523+
"decl_macro_expander_shim",
523524
"file_item_tree_query",
524525
"ast_id_map_shim",
525526
"parse_shim",
@@ -533,7 +534,6 @@ m!(Z);
533534
"ast_id_map_shim",
534535
"parse_macro_expansion_shim",
535536
"macro_arg_shim",
536-
"decl_macro_expander_shim",
537537
"file_item_tree_query",
538538
"ast_id_map_shim",
539539
"parse_macro_expansion_shim",

0 commit comments

Comments
 (0)