Skip to content

Commit 3c9e070

Browse files
committed
Auto merge of #112784 - lnicola:sync-from-ra, r=lnicola
⬆️ rust-analyzer r? `@ghost`
2 parents 8d1fa47 + 4004f5a commit 3c9e070

File tree

114 files changed

+3891
-1250
lines changed

Some content is hidden

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

114 files changed

+3891
-1250
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Publish Crates
2929
env:
3030
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
31-
PATCH: ${{ github.run_number }}
31+
RUN_NUMBER: ${{ github.run_number }}
3232
shell: bash
3333
run: |
3434
git config --global user.email "[email protected]"
@@ -53,4 +53,4 @@ jobs:
5353
# Remove library crates from the workspaces so we don't auto-publish them as well
5454
sed -i 's/ "lib\/\*",//' ./Cargo.toml
5555
find crates/rust-analyzer -type f -name '*.rs' -exec sed -i 's/rust_analyzer/ra_ap_rust_analyzer/g' {} +
56-
cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$PATCH
56+
cargo workspaces publish --yes --force '*' --exact --no-git-commit --allow-dirty --skip-published custom 0.0.$(($RUN_NUMBER + 133))

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
pull-requests: read
2525
outputs:
2626
typescript: ${{ steps.filter.outputs.typescript }}
27+
proc_macros: ${{ steps.filter.outputs.proc_macros }}
2728
steps:
2829
- uses: actions/checkout@v3
2930
- uses: dorny/paths-filter@4067d885736b84de7c414f582ac45897079b0a78
@@ -45,8 +46,8 @@ jobs:
4546
runs-on: ${{ matrix.os }}
4647
env:
4748
CC: deny_c
48-
RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable'}}"
49-
USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || ''}}"
49+
RUST_CHANNEL: "${{ needs.changes.outputs.proc_macros == 'true' && 'nightly' || 'stable' }}"
50+
USE_SYSROOT_ABI: "${{ needs.changes.outputs.proc_macros == 'true' && '--features sysroot-abi' || '' }}"
5051

5152
strategy:
5253
fail-fast: false
@@ -62,7 +63,8 @@ jobs:
6263
- name: Install Rust toolchain
6364
run: |
6465
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
65-
rustup component add rustfmt rust-src
66+
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src
67+
rustup default ${{ env.RUST_CHANNEL }}
6668
6769
- name: Cache Dependencies
6870
uses: Swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894

src/tools/rust-analyzer/Cargo.lock

+29-19
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
177177

178178
[[package]]
179179
name = "chalk-derive"
180-
version = "0.89.0"
180+
version = "0.91.0"
181181
source = "registry+https://github.com/rust-lang/crates.io-index"
182-
checksum = "ea176c50987dc4765961aa165001e8eb5a722a26308c5797a47303ea91686aab"
182+
checksum = "c59178fded594fe78c47b841520e5a4399d00fe15fffee19b945958a878cd02d"
183183
dependencies = [
184184
"proc-macro2",
185185
"quote",
186-
"syn",
186+
"syn 2.0.15",
187187
"synstructure",
188188
]
189189

190190
[[package]]
191191
name = "chalk-ir"
192-
version = "0.89.0"
192+
version = "0.91.0"
193193
source = "registry+https://github.com/rust-lang/crates.io-index"
194-
checksum = "473b480241695428c14e8f84f1c9a47ef232450a50faf3a4041e5c9dc11e0a3b"
194+
checksum = "8824be92876823b828d551bb792f79eb1f69c69d1948abf69fccbf84e448e57b"
195195
dependencies = [
196196
"bitflags 1.3.2",
197197
"chalk-derive",
@@ -200,9 +200,9 @@ dependencies = [
200200

201201
[[package]]
202202
name = "chalk-recursive"
203-
version = "0.89.0"
203+
version = "0.91.0"
204204
source = "registry+https://github.com/rust-lang/crates.io-index"
205-
checksum = "6764b4fe67cac3a3758185084efbfbd39bf0352795824ba849ddd2b64cd4bb28"
205+
checksum = "1e110d1260809c238072d1c8ef84060e39983e8ea9d4c6f74b19b0ebbf8904dc"
206206
dependencies = [
207207
"chalk-derive",
208208
"chalk-ir",
@@ -213,9 +213,9 @@ dependencies = [
213213

214214
[[package]]
215215
name = "chalk-solve"
216-
version = "0.89.0"
216+
version = "0.91.0"
217217
source = "registry+https://github.com/rust-lang/crates.io-index"
218-
checksum = "55a7e6160966eceb6e7dcc2f479a2af4c477aaf5bccbc640d82515995ab1a6cc"
218+
checksum = "12200b19abf4b0633095f7bd099f3ef609d314754b6adb358c68cc04d10589e5"
219219
dependencies = [
220220
"chalk-derive",
221221
"chalk-ir",
@@ -327,7 +327,7 @@ checksum = "f3cdeb9ec472d588e539a818b2dee436825730da08ad0017c4b1a17676bdc8b7"
327327
dependencies = [
328328
"proc-macro2",
329329
"quote",
330-
"syn",
330+
"syn 1.0.109",
331331
]
332332

333333
[[package]]
@@ -1505,7 +1505,6 @@ dependencies = [
15051505
"parking_lot 0.12.1",
15061506
"parking_lot_core 0.9.6",
15071507
"proc-macro-api",
1508-
"proc-macro-srv-cli",
15091508
"profile",
15101509
"project-model",
15111510
"rayon",
@@ -1578,7 +1577,7 @@ dependencies = [
15781577
"heck",
15791578
"proc-macro2",
15801579
"quote",
1581-
"syn",
1580+
"syn 1.0.109",
15821581
]
15831582

15841583
[[package]]
@@ -1637,7 +1636,7 @@ checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
16371636
dependencies = [
16381637
"proc-macro2",
16391638
"quote",
1640-
"syn",
1639+
"syn 1.0.109",
16411640
]
16421641

16431642
[[package]]
@@ -1660,7 +1659,7 @@ checksum = "395627de918015623b32e7669714206363a7fc00382bf477e72c1f7533e8eafc"
16601659
dependencies = [
16611660
"proc-macro2",
16621661
"quote",
1663-
"syn",
1662+
"syn 1.0.109",
16641663
]
16651664

16661665
[[package]]
@@ -1730,15 +1729,26 @@ dependencies = [
17301729
"unicode-ident",
17311730
]
17321731

1732+
[[package]]
1733+
name = "syn"
1734+
version = "2.0.15"
1735+
source = "registry+https://github.com/rust-lang/crates.io-index"
1736+
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
1737+
dependencies = [
1738+
"proc-macro2",
1739+
"quote",
1740+
"unicode-ident",
1741+
]
1742+
17331743
[[package]]
17341744
name = "synstructure"
1735-
version = "0.12.6"
1745+
version = "0.13.0"
17361746
source = "registry+https://github.com/rust-lang/crates.io-index"
1737-
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
1747+
checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
17381748
dependencies = [
17391749
"proc-macro2",
17401750
"quote",
1741-
"syn",
1751+
"syn 2.0.15",
17421752
"unicode-xid",
17431753
]
17441754

@@ -1811,7 +1821,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
18111821
dependencies = [
18121822
"proc-macro2",
18131823
"quote",
1814-
"syn",
1824+
"syn 1.0.109",
18151825
]
18161826

18171827
[[package]]
@@ -1913,7 +1923,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
19131923
dependencies = [
19141924
"proc-macro2",
19151925
"quote",
1916-
"syn",
1926+
"syn 1.0.109",
19171927
]
19181928

19191929
[[package]]

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl ChangeFixture {
215215
None,
216216
default_cfg,
217217
Default::default(),
218-
Env::default(),
218+
Env::new_for_test_fixture(),
219219
false,
220220
CrateOrigin::Local { repo: None, name: None },
221221
default_target_data_layout
@@ -259,7 +259,7 @@ impl ChangeFixture {
259259
None,
260260
Default::default(),
261261
Default::default(),
262-
Env::default(),
262+
Env::new_for_test_fixture(),
263263
false,
264264
CrateOrigin::Lang(LangCrateOrigin::Core),
265265
target_layout.clone(),
@@ -298,7 +298,7 @@ impl ChangeFixture {
298298
None,
299299
Default::default(),
300300
Default::default(),
301-
Env::default(),
301+
Env::new_for_test_fixture(),
302302
true,
303303
CrateOrigin::Local { repo: None, name: None },
304304
target_layout,

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

+23
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ pub enum CrateOrigin {
151151
Lang(LangCrateOrigin),
152152
}
153153

154+
impl CrateOrigin {
155+
pub fn is_local(&self) -> bool {
156+
matches!(self, CrateOrigin::Local { .. })
157+
}
158+
}
159+
154160
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
155161
pub enum LangCrateOrigin {
156162
Alloc,
@@ -333,6 +339,17 @@ pub struct Env {
333339
entries: FxHashMap<String, String>,
334340
}
335341

342+
impl Env {
343+
pub fn new_for_test_fixture() -> Self {
344+
Env {
345+
entries: FxHashMap::from_iter([(
346+
String::from("__ra_is_test_fixture"),
347+
String::from("__ra_is_test_fixture"),
348+
)]),
349+
}
350+
}
351+
}
352+
336353
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
337354
pub struct Dependency {
338355
pub crate_id: CrateId,
@@ -456,6 +473,12 @@ impl CrateGraph {
456473
self.arena.iter().map(|(idx, _)| idx)
457474
}
458475

476+
// FIXME: used for `handle_hack_cargo_workspace`, should be removed later
477+
#[doc(hidden)]
478+
pub fn iter_mut(&mut self) -> impl Iterator<Item = (CrateId, &mut CrateData)> + '_ {
479+
self.arena.iter_mut()
480+
}
481+
459482
/// Returns an iterator over all transitive dependencies of the given crate,
460483
/// including the crate itself.
461484
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId> {

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

+36-14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct Body {
3737
pub pats: Arena<Pat>,
3838
pub bindings: Arena<Binding>,
3939
pub labels: Arena<Label>,
40+
/// Id of the closure/generator that owns the corresponding binding. If a binding is owned by the
41+
/// top level expression, it will not be listed in here.
42+
pub binding_owners: FxHashMap<BindingId, ExprId>,
4043
/// The patterns for the function's parameters. While the parameter types are
4144
/// part of the function signature, the patterns are not (they don't change
4245
/// the external type of the function).
@@ -118,7 +121,8 @@ impl Body {
118121
let _p = profile::span("body_with_source_map_query");
119122
let mut params = None;
120123

121-
let (file_id, module, body, is_async_fn) = {
124+
let mut is_async_fn = false;
125+
let InFile { file_id, value: body } = {
122126
match def {
123127
DefWithBodyId::FunctionId(f) => {
124128
let data = db.function_data(f);
@@ -138,31 +142,27 @@ impl Body {
138142
}),
139143
)
140144
});
141-
(
142-
src.file_id,
143-
f.module(db),
144-
src.value.body().map(ast::Expr::from),
145-
data.has_async_kw(),
146-
)
145+
is_async_fn = data.has_async_kw();
146+
src.map(|it| it.body().map(ast::Expr::from))
147147
}
148148
DefWithBodyId::ConstId(c) => {
149149
let c = c.lookup(db);
150150
let src = c.source(db);
151-
(src.file_id, c.module(db), src.value.body(), false)
151+
src.map(|it| it.body())
152152
}
153153
DefWithBodyId::StaticId(s) => {
154154
let s = s.lookup(db);
155155
let src = s.source(db);
156-
(src.file_id, s.module(db), src.value.body(), false)
156+
src.map(|it| it.body())
157157
}
158158
DefWithBodyId::VariantId(v) => {
159-
let e = v.parent.lookup(db);
160159
let src = v.parent.child_source(db);
161-
let variant = &src.value[v.local_id];
162-
(src.file_id, e.container, variant.expr(), false)
160+
src.map(|it| it[v.local_id].expr())
163161
}
162+
DefWithBodyId::InTypeConstId(c) => c.lookup(db).id.map(|_| c.source(db).expr()),
164163
}
165164
};
165+
let module = def.module(db);
166166
let expander = Expander::new(db, file_id, module);
167167
let (mut body, source_map) =
168168
Body::new(db, def, expander, params, body, module.krate, is_async_fn);
@@ -209,14 +209,24 @@ impl Body {
209209
}
210210

211211
fn shrink_to_fit(&mut self) {
212-
let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats, bindings } =
213-
self;
212+
let Self {
213+
_c: _,
214+
body_expr: _,
215+
block_scopes,
216+
exprs,
217+
labels,
218+
params,
219+
pats,
220+
bindings,
221+
binding_owners,
222+
} = self;
214223
block_scopes.shrink_to_fit();
215224
exprs.shrink_to_fit();
216225
labels.shrink_to_fit();
217226
params.shrink_to_fit();
218227
pats.shrink_to_fit();
219228
bindings.shrink_to_fit();
229+
binding_owners.shrink_to_fit();
220230
}
221231

222232
pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) {
@@ -260,6 +270,17 @@ impl Body {
260270
f(pat_id);
261271
self.walk_pats_shallow(pat_id, |p| self.walk_pats(p, f));
262272
}
273+
274+
pub fn is_binding_upvar(&self, binding: BindingId, relative_to: ExprId) -> bool {
275+
match self.binding_owners.get(&binding) {
276+
Some(x) => {
277+
// We assign expression ids in a way that outer closures will receive
278+
// a lower id
279+
x.into_raw() < relative_to.into_raw()
280+
}
281+
None => true,
282+
}
283+
}
263284
}
264285

265286
impl Default for Body {
@@ -272,6 +293,7 @@ impl Default for Body {
272293
labels: Default::default(),
273294
params: Default::default(),
274295
block_scopes: Default::default(),
296+
binding_owners: Default::default(),
275297
_c: Default::default(),
276298
}
277299
}

0 commit comments

Comments
 (0)