Skip to content

Commit d990861

Browse files
committed
Auto merge of #151751 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@40cda2f. Created using https://github.com/rust-lang/josh-sync. r? @ghost
2 parents e96bb7e + d400dca commit d990861

File tree

195 files changed

+6704
-1751
lines changed

Some content is hidden

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

195 files changed

+6704
-1751
lines changed

src/tools/rust-analyzer/.github/workflows/rustdoc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: rustup update --no-self-update stable
2525

2626
- name: Build Documentation
27-
run: cargo doc --all --no-deps
27+
run: cargo doc --all --no-deps --document-private-items
2828

2929
- name: Deploy Docs
3030
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0

src/tools/rust-analyzer/Cargo.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
178178

179179
[[package]]
180180
name = "camino"
181-
version = "1.2.0"
181+
version = "1.2.2"
182182
source = "registry+https://github.com/rust-lang/crates.io-index"
183-
checksum = "e1de8bc0aa9e9385ceb3bf0c152e3a9b9544f6c4a912c8ae504e80c1f0368603"
183+
checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"
184184
dependencies = [
185185
"serde_core",
186186
]
@@ -1864,6 +1864,7 @@ dependencies = [
18641864
"intern",
18651865
"libc",
18661866
"libloading",
1867+
"line-index 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
18671868
"memmap2",
18681869
"object",
18691870
"paths",
@@ -1878,9 +1879,15 @@ name = "proc-macro-srv-cli"
18781879
version = "0.0.0"
18791880
dependencies = [
18801881
"clap",
1882+
"expect-test",
1883+
"intern",
1884+
"paths",
18811885
"postcard",
18821886
"proc-macro-api",
18831887
"proc-macro-srv",
1888+
"proc-macro-test",
1889+
"span",
1890+
"tt",
18841891
]
18851892

18861893
[[package]]
@@ -2628,7 +2635,7 @@ dependencies = [
26282635

26292636
[[package]]
26302637
name = "smol_str"
2631-
version = "0.3.4"
2638+
version = "0.3.5"
26322639
dependencies = [
26332640
"arbitrary",
26342641
"borsh",

src/tools/rust-analyzer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ debug = 2
4242
# lsp-server = { path = "lib/lsp-server" }
4343

4444

45-
# ungrammar = { path = "lin/ungrammar" }
45+
# ungrammar = { path = "lib/ungrammar" }
4646

4747
# salsa = { path = "../salsa" }
4848
# salsa-macros = { path = "../salsa/components/salsa-macros" }
@@ -107,7 +107,7 @@ anyhow = "1.0.98"
107107
arrayvec = "0.7.6"
108108
bitflags = "2.9.1"
109109
cargo_metadata = "0.23.0"
110-
camino = "1.1.10"
110+
camino = "1.2.2"
111111
crossbeam-channel = "0.5.15"
112112
dissimilar = "1.0.10"
113113
dot = "0.1.4"

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub enum LangCrateOrigin {
221221
ProcMacro,
222222
Std,
223223
Test,
224+
Dependency,
224225
Other,
225226
}
226227

@@ -245,7 +246,7 @@ impl fmt::Display for LangCrateOrigin {
245246
LangCrateOrigin::ProcMacro => "proc_macro",
246247
LangCrateOrigin::Std => "std",
247248
LangCrateOrigin::Test => "test",
248-
LangCrateOrigin::Other => "other",
249+
LangCrateOrigin::Other | LangCrateOrigin::Dependency => "other",
249250
};
250251
f.write_str(text)
251252
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn match_attr_flags(attr_flags: &mut AttrFlags, attr: Meta) -> ControlFlow<Infal
135135
match attr {
136136
Meta::NamedKeyValue { name: Some(name), value, .. } => match name.text() {
137137
"deprecated" => attr_flags.insert(AttrFlags::IS_DEPRECATED),
138+
"ignore" => attr_flags.insert(AttrFlags::IS_IGNORE),
138139
"lang" => attr_flags.insert(AttrFlags::LANG_ITEM),
139140
"path" => attr_flags.insert(AttrFlags::HAS_PATH),
140141
"unstable" => attr_flags.insert(AttrFlags::IS_UNSTABLE),

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use intern::{Symbol, sym};
88
use tt::TextRange;
99

1010
use crate::{
11-
AdtId, BuiltinDeriveImplId, BuiltinDeriveImplLoc, FunctionId, HasModule, db::DefDatabase,
11+
AdtId, BuiltinDeriveImplId, BuiltinDeriveImplLoc, FunctionId, HasModule, MacroId,
12+
db::DefDatabase, lang_item::LangItems,
1213
};
1314

1415
macro_rules! declare_enum {
@@ -86,6 +87,25 @@ declare_enum!(
8687
DispatchFromDyn => [],
8788
);
8889

90+
impl BuiltinDeriveImplTrait {
91+
pub fn derive_macro(self, lang_items: &LangItems) -> Option<MacroId> {
92+
match self {
93+
BuiltinDeriveImplTrait::Copy => lang_items.CopyDerive,
94+
BuiltinDeriveImplTrait::Clone => lang_items.CloneDerive,
95+
BuiltinDeriveImplTrait::Default => lang_items.DefaultDerive,
96+
BuiltinDeriveImplTrait::Debug => lang_items.DebugDerive,
97+
BuiltinDeriveImplTrait::Hash => lang_items.HashDerive,
98+
BuiltinDeriveImplTrait::Ord => lang_items.OrdDerive,
99+
BuiltinDeriveImplTrait::PartialOrd => lang_items.PartialOrdDerive,
100+
BuiltinDeriveImplTrait::Eq => lang_items.EqDerive,
101+
BuiltinDeriveImplTrait::PartialEq => lang_items.PartialEqDerive,
102+
BuiltinDeriveImplTrait::CoerceUnsized | BuiltinDeriveImplTrait::DispatchFromDyn => {
103+
lang_items.CoercePointeeDerive
104+
}
105+
}
106+
}
107+
}
108+
89109
impl BuiltinDeriveImplMethod {
90110
pub fn trait_method(
91111
self,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
pub mod keys {
2828
use std::marker::PhantomData;
2929

30+
use either::Either;
3031
use hir_expand::{MacroCallId, attrs::AttrId};
3132
use rustc_hash::FxHashMap;
3233
use syntax::{AstNode, AstPtr, ast};
3334

3435
use crate::{
35-
BlockId, ConstId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, FieldId, FunctionId,
36-
ImplId, LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitId,
37-
TypeAliasId, TypeOrConstParamId, UnionId, UseId,
36+
BlockId, BuiltinDeriveImplId, ConstId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId,
37+
FieldId, FunctionId, ImplId, LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId,
38+
StaticId, StructId, TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
3839
dyn_map::{DynMap, Policy},
3940
};
4041

@@ -71,7 +72,8 @@ pub mod keys {
7172
(
7273
AttrId,
7374
/* derive() */ MacroCallId,
74-
/* actual derive macros */ Box<[Option<MacroCallId>]>,
75+
/* actual derive macros */
76+
Box<[Option<Either<MacroCallId, BuiltinDeriveImplId>>]>,
7577
),
7678
> = Key::new();
7779

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
expr_store::path::Path,
3333
hir::{
3434
Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat,
35-
PatId, RecordFieldPat, Statement,
35+
PatId, RecordFieldPat, RecordSpread, Statement,
3636
},
3737
nameres::{DefMap, block_def_map},
3838
type_ref::{LifetimeRef, LifetimeRefId, PathId, TypeRef, TypeRefId},
@@ -575,8 +575,8 @@ impl ExpressionStore {
575575
for field in fields.iter() {
576576
f(field.expr);
577577
}
578-
if let &Some(expr) = spread {
579-
f(expr);
578+
if let RecordSpread::Expr(expr) = spread {
579+
f(*expr);
580580
}
581581
}
582582
Expr::Closure { body, .. } => {
@@ -706,8 +706,8 @@ impl ExpressionStore {
706706
for field in fields.iter() {
707707
f(field.expr);
708708
}
709-
if let &Some(expr) = spread {
710-
f(expr);
709+
if let RecordSpread::Expr(expr) = spread {
710+
f(*expr);
711711
}
712712
}
713713
Expr::Closure { body, .. } => {

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::{
4747
hir::{
4848
Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind,
4949
Expr, ExprId, Item, Label, LabelId, Literal, MatchArm, Movability, OffsetOf, Pat, PatId,
50-
RecordFieldPat, RecordLitField, Statement, generics::GenericParams,
50+
RecordFieldPat, RecordLitField, RecordSpread, Statement, generics::GenericParams,
5151
},
5252
item_scope::BuiltinShadowMode,
5353
item_tree::FieldsShape,
@@ -150,6 +150,7 @@ pub(super) fn lower_body(
150150
};
151151

152152
let body_expr = collector.collect(
153+
&mut params,
153154
body,
154155
if is_async_fn {
155156
Awaitable::Yes
@@ -903,24 +904,57 @@ impl<'db> ExprCollector<'db> {
903904
})
904905
}
905906

906-
fn collect(&mut self, expr: Option<ast::Expr>, awaitable: Awaitable) -> ExprId {
907+
/// An `async fn` needs to capture all parameters in the generated `async` block, even if they have
908+
/// non-captured patterns such as wildcards (to ensure consistent drop order).
909+
fn lower_async_fn(&mut self, params: &mut Vec<PatId>, body: ExprId) -> ExprId {
910+
let mut statements = Vec::new();
911+
for param in params {
912+
let name = match self.store.pats[*param] {
913+
Pat::Bind { id, .. }
914+
if matches!(
915+
self.store.bindings[id].mode,
916+
BindingAnnotation::Unannotated | BindingAnnotation::Mutable
917+
) =>
918+
{
919+
// If this is a direct binding, we can leave it as-is, as it'll always be captured anyway.
920+
continue;
921+
}
922+
Pat::Bind { id, .. } => {
923+
// If this is a `ref` binding, we can't leave it as is but we can at least reuse the name, for better display.
924+
self.store.bindings[id].name.clone()
925+
}
926+
_ => self.generate_new_name(),
927+
};
928+
let binding_id =
929+
self.alloc_binding(name.clone(), BindingAnnotation::Mutable, HygieneId::ROOT);
930+
let pat_id = self.alloc_pat_desugared(Pat::Bind { id: binding_id, subpat: None });
931+
let expr = self.alloc_expr_desugared(Expr::Path(name.into()));
932+
statements.push(Statement::Let {
933+
pat: *param,
934+
type_ref: None,
935+
initializer: Some(expr),
936+
else_branch: None,
937+
});
938+
*param = pat_id;
939+
}
940+
941+
self.alloc_expr_desugared(Expr::Async {
942+
id: None,
943+
statements: statements.into_boxed_slice(),
944+
tail: Some(body),
945+
})
946+
}
947+
948+
fn collect(
949+
&mut self,
950+
params: &mut Vec<PatId>,
951+
expr: Option<ast::Expr>,
952+
awaitable: Awaitable,
953+
) -> ExprId {
907954
self.awaitable_context.replace(awaitable);
908955
self.with_label_rib(RibKind::Closure, |this| {
909-
if awaitable == Awaitable::Yes {
910-
match expr {
911-
Some(e) => {
912-
let syntax_ptr = AstPtr::new(&e);
913-
let expr = this.collect_expr(e);
914-
this.alloc_expr_desugared_with_ptr(
915-
Expr::Async { id: None, statements: Box::new([]), tail: Some(expr) },
916-
syntax_ptr,
917-
)
918-
}
919-
None => this.missing_expr(),
920-
}
921-
} else {
922-
this.collect_expr_opt(expr)
923-
}
956+
let body = this.collect_expr_opt(expr);
957+
if awaitable == Awaitable::Yes { this.lower_async_fn(params, body) } else { body }
924958
})
925959
}
926960

@@ -1232,10 +1266,16 @@ impl<'db> ExprCollector<'db> {
12321266
Some(RecordLitField { name, expr })
12331267
})
12341268
.collect();
1235-
let spread = nfl.spread().map(|s| self.collect_expr(s));
1269+
let spread_expr = nfl.spread().map(|s| self.collect_expr(s));
1270+
let has_spread_syntax = nfl.dotdot_token().is_some();
1271+
let spread = match (spread_expr, has_spread_syntax) {
1272+
(None, false) => RecordSpread::None,
1273+
(None, true) => RecordSpread::FieldDefaults,
1274+
(Some(expr), _) => RecordSpread::Expr(expr),
1275+
};
12361276
Expr::RecordLit { path, fields, spread }
12371277
} else {
1238-
Expr::RecordLit { path, fields: Box::default(), spread: None }
1278+
Expr::RecordLit { path, fields: Box::default(), spread: RecordSpread::None }
12391279
};
12401280

12411281
self.alloc_expr(record_lit, syntax_ptr)
@@ -1961,7 +2001,7 @@ impl<'db> ExprCollector<'db> {
19612001
}
19622002
}
19632003

1964-
fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId {
2004+
pub fn collect_expr_opt(&mut self, expr: Option<ast::Expr>) -> ExprId {
19652005
match expr {
19662006
Some(expr) => self.collect_expr(expr),
19672007
None => self.missing_expr(),

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/format_args.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::{
1010
builtin_type::BuiltinUint,
1111
expr_store::{HygieneId, lower::ExprCollector, path::Path},
1212
hir::{
13-
Array, BindingAnnotation, Expr, ExprId, Literal, Pat, RecordLitField, Statement,
13+
Array, BindingAnnotation, Expr, ExprId, Literal, Pat, RecordLitField, RecordSpread,
14+
Statement,
1415
format_args::{
1516
self, FormatAlignment, FormatArgs, FormatArgsPiece, FormatArgument, FormatArgumentKind,
1617
FormatArgumentsCollector, FormatCount, FormatDebugHex, FormatOptions,
@@ -869,7 +870,7 @@ impl<'db> ExprCollector<'db> {
869870
self.alloc_expr_desugared(Expr::RecordLit {
870871
path: self.lang_path(lang_items.FormatPlaceholder).map(Box::new),
871872
fields: Box::new([position, flags, precision, width]),
872-
spread: None,
873+
spread: RecordSpread::None,
873874
})
874875
} else {
875876
let format_placeholder_new =

0 commit comments

Comments
 (0)