Skip to content

Commit 9326cf7

Browse files
committed
Merge commit 'cd3bf9fe51676b520c546460e6d8919b8c8ff99f' into sync-from-ra
1 parent bbd6955 commit 9326cf7

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

.github/workflows/autopublish.yaml

Lines changed: 2 additions & 2 deletions
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))

.github/workflows/ci.yaml

Lines changed: 5 additions & 3 deletions
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

Cargo.lock

Lines changed: 29 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base-db/src/fixture.rs

Lines changed: 3 additions & 3 deletions
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,

crates/base-db/src/input.rs

Lines changed: 23 additions & 0 deletions
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> {

crates/hir-def/src/body.rs

Lines changed: 36 additions & 14 deletions
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)