Skip to content

Commit fbab782

Browse files
committed
Auto merge of rust-lang#132594 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 82c24ec + 0cd3fb2 commit fbab782

Some content is hidden

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

68 files changed

+1907
-849
lines changed

Diff for: src/tools/rust-analyzer/.github/workflows/autopublish.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
cargo workspaces rename --from proc-macro-api proc_macro_api
5252
cargo workspaces rename --from proc-macro-srv proc_macro_srv
5353
cargo workspaces rename --from project-model project_model
54+
cargo workspaces rename --from test-fixture test_fixture
5455
cargo workspaces rename --from test-utils test_utils
5556
cargo workspaces rename --from text-edit text_edit
5657
# Remove library crates from the workspaces so we don't auto-publish them as well

Diff for: src/tools/rust-analyzer/Cargo.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -1492,9 +1492,9 @@ dependencies = [
14921492

14931493
[[package]]
14941494
name = "ra-ap-rustc_abi"
1495-
version = "0.75.0"
1495+
version = "0.76.0"
14961496
source = "registry+https://github.com/rust-lang/crates.io-index"
1497-
checksum = "d5bc2cfc7264d84215a08875ef90a1d35f76b5c9ad1993515d2da7e4e40b2b4b"
1497+
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
14981498
dependencies = [
14991499
"bitflags 2.6.0",
15001500
"ra-ap-rustc_index",
@@ -1503,9 +1503,9 @@ dependencies = [
15031503

15041504
[[package]]
15051505
name = "ra-ap-rustc_index"
1506-
version = "0.75.0"
1506+
version = "0.76.0"
15071507
source = "registry+https://github.com/rust-lang/crates.io-index"
1508-
checksum = "e8929140697812e5dd09e19cf446d85146332363f0dbc125d4214834c34ead96"
1508+
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
15091509
dependencies = [
15101510
"arrayvec",
15111511
"ra-ap-rustc_index_macros",
@@ -1514,9 +1514,9 @@ dependencies = [
15141514

15151515
[[package]]
15161516
name = "ra-ap-rustc_index_macros"
1517-
version = "0.75.0"
1517+
version = "0.76.0"
15181518
source = "registry+https://github.com/rust-lang/crates.io-index"
1519-
checksum = "514a3f5d04c8b4a2750f29746cc9abb1f78deb7e72e4ad1dc95bbc608f3db157"
1519+
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
15201520
dependencies = [
15211521
"proc-macro2",
15221522
"quote",
@@ -1525,29 +1525,29 @@ dependencies = [
15251525

15261526
[[package]]
15271527
name = "ra-ap-rustc_lexer"
1528-
version = "0.75.0"
1528+
version = "0.76.0"
15291529
source = "registry+https://github.com/rust-lang/crates.io-index"
1530-
checksum = "276fcb1205da071a0cd64416f3f0e198043c11f176c5b501a45dbf0cb33979f2"
1530+
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
15311531
dependencies = [
15321532
"unicode-properties",
15331533
"unicode-xid",
15341534
]
15351535

15361536
[[package]]
15371537
name = "ra-ap-rustc_parse_format"
1538-
version = "0.75.0"
1538+
version = "0.76.0"
15391539
source = "registry+https://github.com/rust-lang/crates.io-index"
1540-
checksum = "961b30b22cfac296b14b72e9f95e79c16cebc8c926872755fb1568a6c4243a62"
1540+
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
15411541
dependencies = [
15421542
"ra-ap-rustc_index",
15431543
"ra-ap-rustc_lexer",
15441544
]
15451545

15461546
[[package]]
15471547
name = "ra-ap-rustc_pattern_analysis"
1548-
version = "0.75.0"
1548+
version = "0.76.0"
15491549
source = "registry+https://github.com/rust-lang/crates.io-index"
1550-
checksum = "614232513814a4b714fea7f11345d31c0c277bca3089bb6ca1ec20870bfc022a"
1550+
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
15511551
dependencies = [
15521552
"ra-ap-rustc_index",
15531553
"rustc-hash 2.0.0",

Diff for: src/tools/rust-analyzer/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
8484
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8585
vfs = { path = "./crates/vfs", version = "0.0.0" }
8686

87-
ra-ap-rustc_lexer = { version = "0.75", default-features = false }
88-
ra-ap-rustc_parse_format = { version = "0.75", default-features = false }
89-
ra-ap-rustc_index = { version = "0.75", default-features = false }
90-
ra-ap-rustc_abi = { version = "0.75", default-features = false }
91-
ra-ap-rustc_pattern_analysis = { version = "0.75", default-features = false }
87+
ra-ap-rustc_lexer = { version = "0.76", default-features = false }
88+
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
89+
ra-ap-rustc_index = { version = "0.76", default-features = false }
90+
ra-ap-rustc_abi = { version = "0.76", default-features = false }
91+
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }
9292

9393
# local crates that aren't published to crates.io. These should not have versions.
9494
test-fixture = { path = "./crates/test-fixture" }

Diff for: src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl ExprCollector<'_> {
407407
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
408408
let generic_args = e
409409
.generic_arg_list()
410-
.and_then(|it| GenericArgs::from_ast(&self.ctx(), it))
410+
.and_then(|it| GenericArgs::from_ast(&mut self.ctx(), it))
411411
.map(Box::new);
412412
self.alloc_expr(
413413
Expr::MethodCall { receiver, method_name, args, generic_args },
@@ -533,7 +533,7 @@ impl ExprCollector<'_> {
533533
ast::Expr::TryExpr(e) => self.collect_try_operator(syntax_ptr, e),
534534
ast::Expr::CastExpr(e) => {
535535
let expr = self.collect_expr_opt(e.expr());
536-
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
536+
let type_ref = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
537537
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
538538
}
539539
ast::Expr::RefExpr(e) => {
@@ -572,13 +572,15 @@ impl ExprCollector<'_> {
572572
arg_types.reserve_exact(num_params);
573573
for param in pl.params() {
574574
let pat = this.collect_pat_top(param.pat());
575-
let type_ref = param.ty().map(|it| TypeRef::from_ast(&this.ctx(), it));
575+
let type_ref = param.ty().map(|it| TypeRef::from_ast(&mut this.ctx(), it));
576576
args.push(pat);
577577
arg_types.push(type_ref);
578578
}
579579
}
580-
let ret_type =
581-
e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&this.ctx(), it));
580+
let ret_type = e
581+
.ret_type()
582+
.and_then(|r| r.ty())
583+
.map(|it| TypeRef::from_ast(&mut this.ctx(), it));
582584

583585
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
584586
let prev_try_block_label = this.current_try_block_label.take();
@@ -705,7 +707,7 @@ impl ExprCollector<'_> {
705707
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
706708
ast::Expr::AsmExpr(e) => self.lower_inline_asm(e, syntax_ptr),
707709
ast::Expr::OffsetOfExpr(e) => {
708-
let container = TypeRef::from_ast_opt(&self.ctx(), e.ty());
710+
let container = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
709711
let fields = e.fields().map(|it| it.as_name()).collect();
710712
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
711713
}
@@ -1317,7 +1319,7 @@ impl ExprCollector<'_> {
13171319
return;
13181320
}
13191321
let pat = self.collect_pat_top(stmt.pat());
1320-
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
1322+
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&mut self.ctx(), it));
13211323
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
13221324
let else_branch = stmt
13231325
.let_else()

Diff for: src/tools/rust-analyzer/crates/hir-def/src/data.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct FunctionData {
3737
pub name: Name,
3838
pub params: Box<[TypeRefId]>,
3939
pub ret_type: TypeRefId,
40+
// FIXME: why are these stored here? They should be accessed via the query
4041
pub attrs: Attrs,
4142
pub visibility: RawVisibility,
4243
pub abi: Option<Symbol>,

Diff for: src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs

+73-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,79 @@
2121
//!
2222
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
2323
//! a coincidence.
24-
pub mod keys;
24+
25+
pub mod keys {
26+
use std::marker::PhantomData;
27+
28+
use hir_expand::{attrs::AttrId, MacroCallId};
29+
use rustc_hash::FxHashMap;
30+
use syntax::{ast, AstNode, AstPtr};
31+
32+
use crate::{
33+
dyn_map::{DynMap, Policy},
34+
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
35+
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
36+
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
37+
};
38+
39+
pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;
40+
41+
pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
42+
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
43+
pub const CONST: Key<ast::Const, ConstId> = Key::new();
44+
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
45+
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
46+
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
47+
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
48+
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
49+
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
50+
pub const UNION: Key<ast::Union, UnionId> = Key::new();
51+
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
52+
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
53+
pub const USE: Key<ast::Use, UseId> = Key::new();
54+
55+
pub const ENUM_VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
56+
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
57+
pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
58+
pub const TYPE_PARAM: Key<ast::TypeParam, TypeOrConstParamId> = Key::new();
59+
pub const CONST_PARAM: Key<ast::ConstParam, TypeOrConstParamId> = Key::new();
60+
pub const LIFETIME_PARAM: Key<ast::LifetimeParam, LifetimeParamId> = Key::new();
61+
62+
pub const MACRO_RULES: Key<ast::MacroRules, MacroRulesId> = Key::new();
63+
pub const MACRO2: Key<ast::MacroDef, Macro2Id> = Key::new();
64+
pub const PROC_MACRO: Key<ast::Fn, ProcMacroId> = Key::new();
65+
pub const MACRO_CALL: Key<ast::MacroCall, MacroCallId> = Key::new();
66+
pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
67+
pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
68+
Key::new();
69+
70+
/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
71+
/// equal if they point to exactly the same object.
72+
///
73+
/// In general, we do not guarantee that we have exactly one instance of a
74+
/// syntax tree for each file. We probably should add such guarantee, but, for
75+
/// the time being, we will use identity-less AstPtr comparison.
76+
pub struct AstPtrPolicy<AST, ID> {
77+
_phantom: PhantomData<(AST, ID)>,
78+
}
79+
80+
impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
81+
type K = AstPtr<AST>;
82+
type V = ID;
83+
fn insert(map: &mut DynMap, key: AstPtr<AST>, value: ID) {
84+
map.map
85+
.entry::<FxHashMap<AstPtr<AST>, ID>>()
86+
.or_insert_with(Default::default)
87+
.insert(key, value);
88+
}
89+
fn get<'a>(map: &'a DynMap, key: &AstPtr<AST>) -> Option<&'a ID> {
90+
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(key)
91+
}
92+
fn is_empty(map: &DynMap) -> bool {
93+
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
94+
}
95+
}
96+
}
2597

2698
use std::{
2799
hash::Hash,

Diff for: src/tools/rust-analyzer/crates/hir-def/src/dyn_map/keys.rs

-72
This file was deleted.

Diff for: src/tools/rust-analyzer/crates/hir-def/src/expander.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ impl Expander {
161161
types_map: &mut TypesMap,
162162
types_source_map: &mut TypesSourceMap,
163163
) -> Option<Path> {
164-
let ctx = LowerCtx::with_span_map_cell(
164+
let mut ctx = LowerCtx::with_span_map_cell(
165165
db,
166166
self.current_file_id,
167167
self.span_map.clone(),
168168
types_map,
169169
types_source_map,
170170
);
171-
Path::from_src(&ctx, path)
171+
Path::from_src(&mut ctx, path)
172172
}
173173

174174
fn within_limit<F, T: ast::AstNode>(

Diff for: src/tools/rust-analyzer/crates/hir-def/src/generics.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ pub(crate) struct GenericParamsCollector {
451451
impl GenericParamsCollector {
452452
pub(crate) fn fill(
453453
&mut self,
454-
lower_ctx: &LowerCtx<'_>,
454+
lower_ctx: &mut LowerCtx<'_>,
455455
node: &dyn HasGenericParams,
456456
add_param_attrs: impl FnMut(
457457
Either<LocalTypeOrConstParamId, LocalLifetimeParamId>,
@@ -468,7 +468,7 @@ impl GenericParamsCollector {
468468

469469
pub(crate) fn fill_bounds(
470470
&mut self,
471-
lower_ctx: &LowerCtx<'_>,
471+
lower_ctx: &mut LowerCtx<'_>,
472472
type_bounds: Option<ast::TypeBoundList>,
473473
target: Either<TypeRefId, LifetimeRef>,
474474
) {
@@ -479,7 +479,7 @@ impl GenericParamsCollector {
479479

480480
fn fill_params(
481481
&mut self,
482-
lower_ctx: &LowerCtx<'_>,
482+
lower_ctx: &mut LowerCtx<'_>,
483483
params: ast::GenericParamList,
484484
mut add_param_attrs: impl FnMut(
485485
Either<LocalTypeOrConstParamId, LocalLifetimeParamId>,
@@ -535,7 +535,11 @@ impl GenericParamsCollector {
535535
}
536536
}
537537

538-
fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx<'_>, where_clause: ast::WhereClause) {
538+
fn fill_where_predicates(
539+
&mut self,
540+
lower_ctx: &mut LowerCtx<'_>,
541+
where_clause: ast::WhereClause,
542+
) {
539543
for pred in where_clause.predicates() {
540544
let target = if let Some(type_ref) = pred.ty() {
541545
Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
@@ -569,7 +573,7 @@ impl GenericParamsCollector {
569573

570574
fn add_where_predicate_from_bound(
571575
&mut self,
572-
lower_ctx: &LowerCtx<'_>,
576+
lower_ctx: &mut LowerCtx<'_>,
573577
bound: ast::TypeBound,
574578
hrtb_lifetimes: Option<&[Name]>,
575579
target: Either<TypeRefId, LifetimeRef>,
@@ -670,8 +674,9 @@ impl GenericParamsCollector {
670674
{
671675
let (mut macro_types_map, mut macro_types_source_map) =
672676
(TypesMap::default(), TypesSourceMap::default());
673-
let ctx = expander.ctx(db, &mut macro_types_map, &mut macro_types_source_map);
674-
let type_ref = TypeRef::from_ast(&ctx, expanded.tree());
677+
let mut ctx =
678+
expander.ctx(db, &mut macro_types_map, &mut macro_types_source_map);
679+
let type_ref = TypeRef::from_ast(&mut ctx, expanded.tree());
675680
self.fill_implicit_impl_trait_args(
676681
db,
677682
generics_types_map,

0 commit comments

Comments
 (0)