Skip to content

Commit 531e578

Browse files
authored
Rollup merge of #134170 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents eefefbe + a18e38e commit 531e578

File tree

226 files changed

+7515
-2865
lines changed

Some content is hidden

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

226 files changed

+7515
-2865
lines changed

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

+31-13
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ dependencies = [
8484
"vfs",
8585
]
8686

87+
[[package]]
88+
name = "base64"
89+
version = "0.22.1"
90+
source = "registry+https://github.com/rust-lang/crates.io-index"
91+
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
92+
8793
[[package]]
8894
name = "bitflags"
8995
version = "1.3.2"
@@ -509,6 +515,7 @@ dependencies = [
509515
"base-db",
510516
"cfg",
511517
"either",
518+
"expect-test",
512519
"hir-def",
513520
"hir-expand",
514521
"hir-ty",
@@ -519,6 +526,9 @@ dependencies = [
519526
"span",
520527
"stdx",
521528
"syntax",
529+
"syntax-bridge",
530+
"test-fixture",
531+
"test-utils",
522532
"tracing",
523533
"triomphe",
524534
"tt",
@@ -1492,9 +1502,9 @@ dependencies = [
14921502

14931503
[[package]]
14941504
name = "ra-ap-rustc_abi"
1495-
version = "0.80.0"
1505+
version = "0.85.0"
14961506
source = "registry+https://github.com/rust-lang/crates.io-index"
1497-
checksum = "613760a3071b25a67a8d7bc97b37c7fd4722562e9479137b83ae9cf8f8c1601a"
1507+
checksum = "af462c3a2d524b84a51b6848b439787f01b35c6c1086d3e3086a5f5eea92ed9a"
14981508
dependencies = [
14991509
"bitflags 2.6.0",
15001510
"ra-ap-rustc_index",
@@ -1503,20 +1513,19 @@ dependencies = [
15031513

15041514
[[package]]
15051515
name = "ra-ap-rustc_index"
1506-
version = "0.80.0"
1516+
version = "0.85.0"
15071517
source = "registry+https://github.com/rust-lang/crates.io-index"
1508-
checksum = "5b2bc6b4ecede8ff28295041e22c2e66853f8e0125990c05135bad3c30bad12c"
1518+
checksum = "be6bb8cb0ab78d94a222f1ffd3e87254cdfb57413382b8d6ebe26a85482f99d1"
15091519
dependencies = [
1510-
"arrayvec",
15111520
"ra-ap-rustc_index_macros",
15121521
"smallvec",
15131522
]
15141523

15151524
[[package]]
15161525
name = "ra-ap-rustc_index_macros"
1517-
version = "0.80.0"
1526+
version = "0.85.0"
15181527
source = "registry+https://github.com/rust-lang/crates.io-index"
1519-
checksum = "2374a39fb2d92d0509178c2b442eadca3cc10e403ef9729a040c1855b08ff261"
1528+
checksum = "c24b1641455b46e87435b7321219672077066e678963d239a4a2904732979b16"
15201529
dependencies = [
15211530
"proc-macro2",
15221531
"quote",
@@ -1525,29 +1534,29 @@ dependencies = [
15251534

15261535
[[package]]
15271536
name = "ra-ap-rustc_lexer"
1528-
version = "0.80.0"
1537+
version = "0.85.0"
15291538
source = "registry+https://github.com/rust-lang/crates.io-index"
1530-
checksum = "5a2cf8e48b69af3ecc29ed3449892e8a999111d2f75212a78aa242e117cf1711"
1539+
checksum = "94daa86974417981fed2f12bd8fb00158dfa6fee561152bed689278c846d0272"
15311540
dependencies = [
15321541
"unicode-properties",
15331542
"unicode-xid",
15341543
]
15351544

15361545
[[package]]
15371546
name = "ra-ap-rustc_parse_format"
1538-
version = "0.80.0"
1547+
version = "0.85.0"
15391548
source = "registry+https://github.com/rust-lang/crates.io-index"
1540-
checksum = "8d6f59a22b559263c5c42747ae362cf5d4fb272293fa119a4623f8ec288f9656"
1549+
checksum = "fc07f6bd581746f358e39c4b6bfe8d455b3d6ad1a857821016d0d42eeb5e1e3e"
15411550
dependencies = [
15421551
"ra-ap-rustc_index",
15431552
"ra-ap-rustc_lexer",
15441553
]
15451554

15461555
[[package]]
15471556
name = "ra-ap-rustc_pattern_analysis"
1548-
version = "0.80.0"
1557+
version = "0.85.0"
15491558
source = "registry+https://github.com/rust-lang/crates.io-index"
1550-
checksum = "a7d0575b54ffe09bc5d2f158454bc05f0c30c01d9992310965f854be50ae22b8"
1559+
checksum = "2f49b86e1276c1c3c72898410def29b699415f4e7d1dfb3531daf79794694372"
15511560
dependencies = [
15521561
"ra-ap-rustc_index",
15531562
"rustc-hash 2.0.0",
@@ -1645,6 +1654,7 @@ version = "0.0.0"
16451654
dependencies = [
16461655
"always-assert",
16471656
"anyhow",
1657+
"base64",
16481658
"cargo_metadata",
16491659
"cfg",
16501660
"crossbeam-channel",
@@ -1655,6 +1665,7 @@ dependencies = [
16551665
"hir-def",
16561666
"hir-ty",
16571667
"ide",
1668+
"ide-completion",
16581669
"ide-db",
16591670
"ide-ssr",
16601671
"intern",
@@ -1683,6 +1694,7 @@ dependencies = [
16831694
"stdx",
16841695
"syntax",
16851696
"syntax-bridge",
1697+
"tenthash",
16861698
"test-fixture",
16871699
"test-utils",
16881700
"tikv-jemallocator",
@@ -1986,6 +1998,12 @@ dependencies = [
19861998
"tt",
19871999
]
19882000

2001+
[[package]]
2002+
name = "tenthash"
2003+
version = "0.4.0"
2004+
source = "registry+https://github.com/rust-lang/crates.io-index"
2005+
checksum = "d67f9f3cf70e0852941d7bc3cb884b49b24b8ee956baf91ad0abae31f5ef11fb"
2006+
19892007
[[package]]
19902008
name = "test-fixture"
19912009
version = "0.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.80", default-features = false }
88-
ra-ap-rustc_parse_format = { version = "0.80", default-features = false }
89-
ra-ap-rustc_index = { version = "0.80", default-features = false }
90-
ra-ap-rustc_abi = { version = "0.80", default-features = false }
91-
ra-ap-rustc_pattern_analysis = { version = "0.80", default-features = false }
87+
ra-ap-rustc_lexer = { version = "0.85", default-features = false }
88+
ra-ap-rustc_parse_format = { version = "0.85", default-features = false }
89+
ra-ap-rustc_index = { version = "0.85", default-features = false }
90+
ra-ap-rustc_abi = { version = "0.85", default-features = false }
91+
ra-ap-rustc_pattern_analysis = { version = "0.85", 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/base-db/src/input.rs

-23
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,6 @@ impl CrateGraph {
547547
None
548548
}
549549

550-
// Work around for https://github.com/rust-lang/rust-analyzer/issues/6038.
551-
// As hacky as it gets.
552-
pub fn patch_cfg_if(&mut self) -> bool {
553-
// we stupidly max by version in an attempt to have all duplicated std's depend on the same cfg_if so that deduplication still works
554-
let cfg_if =
555-
self.hacky_find_crate("cfg_if").max_by_key(|&it| self.arena[it].version.clone());
556-
let std = self.hacky_find_crate("std").next();
557-
match (cfg_if, std) {
558-
(Some(cfg_if), Some(std)) => {
559-
self.arena[cfg_if].dependencies.clear();
560-
self.arena[std]
561-
.dependencies
562-
.push(Dependency::new(CrateName::new("cfg_if").unwrap(), cfg_if));
563-
true
564-
}
565-
_ => false,
566-
}
567-
}
568-
569-
fn hacky_find_crate<'a>(&'a self, display_name: &'a str) -> impl Iterator<Item = CrateId> + 'a {
570-
self.iter().filter(move |it| self[*it].display_name.as_deref() == Some(display_name))
571-
}
572-
573550
/// Removes all crates from this crate graph except for the ones in `to_keep` and fixes up the dependencies.
574551
/// Returns a mapping from old crate ids to new crate ids.
575552
pub fn remove_crates_except(&mut self, to_keep: &[CrateId]) -> Vec<Option<CrateId>> {

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

+133-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
path::{ModPath, Path},
3232
src::HasSource,
3333
type_ref::{TypeRef, TypeRefId, TypesMap, TypesSourceMap},
34-
BlockId, DefWithBodyId, HasModule, Lookup,
34+
BlockId, DefWithBodyId, HasModule, Lookup, SyntheticSyntax,
3535
};
3636

3737
/// A wrapper around [`span::SyntaxContextId`] that is intended only for comparisons.
@@ -141,7 +141,7 @@ pub struct BodySourceMap {
141141
field_map_back: FxHashMap<ExprId, FieldSource>,
142142
pat_field_map_back: FxHashMap<PatId, PatFieldSource>,
143143

144-
types: TypesSourceMap,
144+
pub types: TypesSourceMap,
145145

146146
// FIXME: Make this a sane struct.
147147
template_map: Option<
@@ -160,9 +160,6 @@ pub struct BodySourceMap {
160160
diagnostics: Vec<BodyDiagnostic>,
161161
}
162162

163-
#[derive(Default, Debug, Eq, PartialEq, Clone, Copy)]
164-
pub struct SyntheticSyntax;
165-
166163
#[derive(Debug, Eq, PartialEq)]
167164
pub enum BodyDiagnostic {
168165
InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions },
@@ -408,7 +405,8 @@ impl Body {
408405
f(else_branch);
409406
}
410407
}
411-
Expr::Let { expr, .. } => {
408+
Expr::Let { expr, pat } => {
409+
self.walk_exprs_in_pat(*pat, &mut f);
412410
f(*expr);
413411
}
414412
Expr::Block { statements, tail, .. }
@@ -444,7 +442,10 @@ impl Body {
444442
}
445443
Expr::Match { expr, arms } => {
446444
f(*expr);
447-
arms.iter().map(|arm| arm.expr).for_each(f);
445+
arms.iter().for_each(|arm| {
446+
f(arm.expr);
447+
self.walk_exprs_in_pat(arm.pat, &mut f);
448+
});
448449
}
449450
Expr::Break { expr, .. }
450451
| Expr::Return { expr }
@@ -505,6 +506,131 @@ impl Body {
505506
}
506507
}
507508

509+
pub fn walk_child_exprs_without_pats(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) {
510+
let expr = &self[expr_id];
511+
match expr {
512+
Expr::Continue { .. }
513+
| Expr::Const(_)
514+
| Expr::Missing
515+
| Expr::Path(_)
516+
| Expr::OffsetOf(_)
517+
| Expr::Literal(_)
518+
| Expr::Underscore => {}
519+
Expr::InlineAsm(it) => it.operands.iter().for_each(|(_, op)| match op {
520+
AsmOperand::In { expr, .. }
521+
| AsmOperand::Out { expr: Some(expr), .. }
522+
| AsmOperand::InOut { expr, .. } => f(*expr),
523+
AsmOperand::SplitInOut { in_expr, out_expr, .. } => {
524+
f(*in_expr);
525+
if let Some(out_expr) = out_expr {
526+
f(*out_expr);
527+
}
528+
}
529+
AsmOperand::Out { expr: None, .. }
530+
| AsmOperand::Const(_)
531+
| AsmOperand::Label(_)
532+
| AsmOperand::Sym(_) => (),
533+
}),
534+
Expr::If { condition, then_branch, else_branch } => {
535+
f(*condition);
536+
f(*then_branch);
537+
if let &Some(else_branch) = else_branch {
538+
f(else_branch);
539+
}
540+
}
541+
Expr::Let { expr, .. } => {
542+
f(*expr);
543+
}
544+
Expr::Block { statements, tail, .. }
545+
| Expr::Unsafe { statements, tail, .. }
546+
| Expr::Async { statements, tail, .. } => {
547+
for stmt in statements.iter() {
548+
match stmt {
549+
Statement::Let { initializer, else_branch, .. } => {
550+
if let &Some(expr) = initializer {
551+
f(expr);
552+
}
553+
if let &Some(expr) = else_branch {
554+
f(expr);
555+
}
556+
}
557+
Statement::Expr { expr: expression, .. } => f(*expression),
558+
Statement::Item(_) => (),
559+
}
560+
}
561+
if let &Some(expr) = tail {
562+
f(expr);
563+
}
564+
}
565+
Expr::Loop { body, .. } => f(*body),
566+
Expr::Call { callee, args, .. } => {
567+
f(*callee);
568+
args.iter().copied().for_each(f);
569+
}
570+
Expr::MethodCall { receiver, args, .. } => {
571+
f(*receiver);
572+
args.iter().copied().for_each(f);
573+
}
574+
Expr::Match { expr, arms } => {
575+
f(*expr);
576+
arms.iter().map(|arm| arm.expr).for_each(f);
577+
}
578+
Expr::Break { expr, .. }
579+
| Expr::Return { expr }
580+
| Expr::Yield { expr }
581+
| Expr::Yeet { expr } => {
582+
if let &Some(expr) = expr {
583+
f(expr);
584+
}
585+
}
586+
Expr::Become { expr } => f(*expr),
587+
Expr::RecordLit { fields, spread, .. } => {
588+
for field in fields.iter() {
589+
f(field.expr);
590+
}
591+
if let &Some(expr) = spread {
592+
f(expr);
593+
}
594+
}
595+
Expr::Closure { body, .. } => {
596+
f(*body);
597+
}
598+
Expr::BinaryOp { lhs, rhs, .. } => {
599+
f(*lhs);
600+
f(*rhs);
601+
}
602+
Expr::Range { lhs, rhs, .. } => {
603+
if let &Some(lhs) = rhs {
604+
f(lhs);
605+
}
606+
if let &Some(rhs) = lhs {
607+
f(rhs);
608+
}
609+
}
610+
Expr::Index { base, index, .. } => {
611+
f(*base);
612+
f(*index);
613+
}
614+
Expr::Field { expr, .. }
615+
| Expr::Await { expr }
616+
| Expr::Cast { expr, .. }
617+
| Expr::Ref { expr, .. }
618+
| Expr::UnaryOp { expr, .. }
619+
| Expr::Box { expr } => {
620+
f(*expr);
621+
}
622+
Expr::Tuple { exprs, .. } => exprs.iter().copied().for_each(f),
623+
Expr::Array(a) => match a {
624+
Array::ElementList { elements, .. } => elements.iter().copied().for_each(f),
625+
Array::Repeat { initializer, repeat } => {
626+
f(*initializer);
627+
f(*repeat)
628+
}
629+
},
630+
&Expr::Assignment { target: _, value } => f(value),
631+
}
632+
}
633+
508634
pub fn walk_exprs_in_pat(&self, pat_id: PatId, f: &mut impl FnMut(ExprId)) {
509635
self.walk_pats(pat_id, &mut |pat| {
510636
if let Pat::Expr(expr) | Pat::ConstBlock(expr) = self[pat] {

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1510,20 +1510,20 @@ impl ExprCollector<'_> {
15101510
BuiltinShadowMode::Other,
15111511
None,
15121512
);
1513+
// Funnily enough, record structs/variants *can* be shadowed
1514+
// by pattern bindings (but unit or tuple structs/variants
1515+
// can't).
15131516
match resolved.take_values() {
15141517
Some(ModuleDefId::ConstId(_)) => (None, Pat::Path(name.into())),
1515-
Some(ModuleDefId::EnumVariantId(_)) => {
1516-
// this is only really valid for unit variants, but
1517-
// shadowing other enum variants with a pattern is
1518-
// an error anyway
1518+
Some(ModuleDefId::EnumVariantId(variant))
1519+
if self.db.variant_data(variant.into()).kind()
1520+
!= StructKind::Record =>
1521+
{
15191522
(None, Pat::Path(name.into()))
15201523
}
15211524
Some(ModuleDefId::AdtId(AdtId::StructId(s)))
15221525
if self.db.struct_data(s).variant_data.kind() != StructKind::Record =>
15231526
{
1524-
// Funnily enough, record structs *can* be shadowed
1525-
// by pattern bindings (but unit or tuple structs
1526-
// can't).
15271527
(None, Pat::Path(name.into()))
15281528
}
15291529
// shadowing statics is an error as well, so we just ignore that case here

0 commit comments

Comments
 (0)