Skip to content

Subtree update of rust-analyzer #121931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 91 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
f610e7c
update bug report issue template
Young-Flash Feb 21, 2024
689fa20
add repository link entry
Young-Flash Feb 21, 2024
4220f90
fix: replace_filter_map_next_with_find_map shouldn't work for dyn trait
Young-Flash Feb 23, 2024
0978d16
add test case
Young-Flash Feb 23, 2024
b132190
make clippy happy
Young-Flash Feb 23, 2024
6f4354f
add assist for filling fields by replacing ellipsis in record syntax
dfireBird Feb 23, 2024
9f1d4aa
prioritise rustup sysroots over system ones
MabezDev Feb 24, 2024
fb31610
Merge branch 'master' into sync-from-rust
lnicola Feb 25, 2024
5346002
Auto merge of #16668 - lnicola:sync-from-rust, r=lnicola
bors Feb 25, 2024
a336bdc
Merge `BorrowKind::Unique` into `BorrowKind::Mut`
ShoyuVanilla Feb 25, 2024
ea837d1
Document nvim 0.10 `inlay_hint`
rikhuijzer Feb 25, 2024
4060377
Add note
rikhuijzer Feb 25, 2024
309e087
Auto merge of #16627 - Young-Flash:issue_template, r=Veykril
bors Feb 26, 2024
4585b46
Auto merge of #16670 - rikhuijzer:rh/inlay-hints-nvim, r=Veykril
bors Feb 26, 2024
6903a5c
Auto merge of #16665 - MabezDev:prio-rustup-when-searching, r=Veykril
bors Feb 26, 2024
e1983d2
Auto merge of #16669 - ShoyuVanilla:merge-borrow-kind-unique, r=Veykril
bors Feb 26, 2024
fd0cddf
internal: move strip_references into dyn trait check
Young-Flash Feb 26, 2024
7a58a23
internal: format code
Young-Flash Feb 26, 2024
8929853
Auto merge of #16647 - Young-Flash:fix_replace_filter_map_next_with_f…
bors Feb 26, 2024
36298c6
fix:do not handle callsites in macros' parameters
roife Feb 26, 2024
38a50cf
test: callsites inside inline_into_callers
roife Feb 26, 2024
1ef7a99
Remove salsa compile_fail tests
lnicola Feb 26, 2024
1880117
Narrow down typos ignores
szepeviktor Feb 25, 2024
2251d06
Auto merge of #16673 - szepeviktor:patch-1, r=lnicola
bors Feb 26, 2024
91554e0
fix: Fix modules in blocks not resolving in ide layer
Veykril Feb 26, 2024
40bf8bf
Auto merge of #16679 - Veykril:block-mod, r=Veykril
bors Feb 26, 2024
f7f63cc
Auto merge of #16680 - lnicola:salsa-doc-test, r=Veykril
bors Feb 26, 2024
61b576c
fix: fmt
roife Feb 26, 2024
9650578
Auto merge of #16678 - roife:fix-issue-16660, r=lnicola
bors Feb 26, 2024
7637141
Add a new failing test
ShoyuVanilla Feb 21, 2024
e36a31b
Port closure kind deduction logic from rustc
ShoyuVanilla Feb 21, 2024
46cdce1
Update expectation tests
ShoyuVanilla Feb 21, 2024
a4021f6
Use lang-item instead of db lookup for `FnTrait` kind
ShoyuVanilla Feb 26, 2024
2ea7066
make assist not applicable if there is no missing field
dfireBird Feb 26, 2024
8fa903a
add test for checking struct generated through macro
dfireBird Feb 26, 2024
3856648
fix: Don't panic on synthetic syntax in inference diagnostics
Veykril Feb 26, 2024
1d3558b
Auto merge of #16684 - Veykril:synthetic-fmt-args, r=Veykril
bors Feb 26, 2024
c246a93
completions: speed up completions by filtering non-applicable traits
davidbarsky Feb 13, 2024
5fead60
Auto merge of #16555 - davidbarsky:david/speedup-completions-by-explo…
bors Feb 26, 2024
8bd30e9
Improve generics handling in term search
kilpkonn Feb 25, 2024
be6f8e2
Add `make_tuple` tactic
kilpkonn Feb 25, 2024
a2bf15e
Filter out false positive errors
kilpkonn Feb 25, 2024
cc7fe32
fix: Fix completions panicking with certain macro setups
Veykril Feb 27, 2024
d4d9d0c
Auto merge of #16691 - Veykril:completion-analysis-panic, r=Veykril
bors Feb 27, 2024
3a1b4c2
internal: Remove dead branches in `method_resolutiopn::is_valid_candi…
Veykril Feb 27, 2024
ea82cc4
Auto merge of #16692 - Veykril:methres, r=Veykril
bors Feb 27, 2024
64c17a9
fix: rust-project.json projects not preferring sysroot rustc
Veykril Feb 27, 2024
d8c5a61
Auto merge of #16651 - dfireBird:new_assist_fill_fields, r=Veykril
bors Feb 27, 2024
6b250a2
Auto merge of #16687 - kilpkonn:master, r=Veykril
bors Feb 27, 2024
c031246
Auto merge of #16693 - Veykril:system-rustc-sysroot, r=Veykril
bors Feb 27, 2024
a3236be
Auto merge of #16630 - ShoyuVanilla:fix-closure-kind-inference, r=Vey…
bors Feb 27, 2024
30ad0ae
internal: Revert #16541
Veykril Feb 27, 2024
d1bdebf
Add a new failing test for goto deref_mut
ShoyuVanilla Feb 27, 2024
0f4e313
Fix goto `deref_mut`
ShoyuVanilla Feb 27, 2024
6124431
Remove unused imports
ShoyuVanilla Feb 27, 2024
a41cec9
Auto merge of #16696 - ShoyuVanilla:fix-goto-deref-mut, r=Veykril
bors Feb 27, 2024
0005794
Add `to_path_buf()` method for `RelPath`
regexident Feb 27, 2024
0ac05c0
Auto merge of #16697 - regexident:relpath-to-relpathbuf, r=Veykril
bors Feb 27, 2024
c061a9e
Derive `PartialEq`, `Eq` & `Hash` for `hir::Param`
regexident Feb 27, 2024
ab533d8
fix: Ignore generic arguments in intra doc link path resolution
Veykril Feb 28, 2024
74531e4
Export `SemanticsImpl` from `ra_ap_hir` crate, since it's already exp…
regexident Feb 28, 2024
ed34978
Add public function for resolving `ast::Expr` to `hir::Callable`
regexident Feb 28, 2024
83f6dd1
Add a new failing test for Goto index_mut definition
ShoyuVanilla Feb 28, 2024
bf23dee
Fix goto `index_mut`
ShoyuVanilla Feb 28, 2024
4ee0dbd
internal: Remove load-cargo dependency on ide
Veykril Feb 28, 2024
ed23004
Add `destructure_struct_binding` action
Lindronics Feb 19, 2024
b203a07
Handle bindings to refs
Lindronics Feb 23, 2024
7c30c70
Attempt resolving name collisions
Lindronics Feb 23, 2024
dc7b502
Fix usage in other assist
Lindronics Feb 27, 2024
0ec6015
Auto merge of #16709 - ShoyuVanilla:fix-goto-index-mut, r=Veykril
bors Feb 29, 2024
71eb540
Auto merge of #16638 - Lindronics:destructure-struct-binding, r=Veykril
bors Feb 29, 2024
ef2acb6
Auto merge of #16695 - Veykril:revert-16541, r=Veykril
bors Feb 29, 2024
a6606d1
Auto merge of #16698 - regexident:param-derives, r=Veykril
bors Feb 29, 2024
ecda464
Auto merge of #16705 - regexident:resolve-callable-exprs, r=Veykril
bors Feb 29, 2024
b3b9b53
Auto merge of #16706 - Veykril:load-cargo-ide-db, r=Veykril
bors Feb 29, 2024
9efa23c
Auto merge of #16707 - regexident:pub-sema-impl, r=Veykril
bors Feb 29, 2024
83a1ad5
Give all threads names
Veykril Feb 23, 2024
c8fdcea
Fix targetDir config name
Veykril Feb 23, 2024
ed7e9aa
Simplify
Veykril Feb 28, 2024
aabaa47
fix: Don't highlight related assoc items of super traits
Veykril Mar 1, 2024
eb7a4f2
minor: Add some basic docs for spans/hygiene handling
Veykril Mar 1, 2024
8a5bb9d
Only the ROOT syntax context has `None` `outer_expn`
Veykril Mar 1, 2024
549aae7
Add a few more doc lines to the span crate
Veykril Mar 1, 2024
efd76ec
Move AstIdMap infra to the span crate
Veykril Mar 1, 2024
c512e2e
Auto merge of #16728 - Veykril:span-docs, r=Veykril
bors Mar 1, 2024
79e0fee
Auto merge of #16727 - Veykril:assoc-related, r=Veykril
bors Mar 1, 2024
dd21914
Remove outdated comment about static SmolStrs
lnicola Mar 2, 2024
6cb576a
Auto merge of #16735 - lnicola:smolstr-new-static, r=lnicola
bors Mar 2, 2024
5c4c126
Auto merge of #16704 - Veykril:stuff, r=Veykril
bors Mar 2, 2024
4ef6a49
Auto merge of #16702 - Veykril:intra-doc-links-generic, r=Veykril
bors Mar 2, 2024
964e769
Merge commit '4ef6a49b44e8aa380da7522442234bfd7a52c55e' into sync-fro…
lnicola Mar 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/tools/rust-analyzer/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ Otherwise please try to provide information which will help us to fix the issue
**rustc version**: (eg. output of `rustc -V`)

**relevant settings**: (eg. client settings, or environment variables like `CARGO`, `RUSTC`, `RUSTUP_HOME` or `CARGO_HOME`)

**repository link (if public, optional)**: (eg. [rust-analyzer](https://github.com/rust-lang/rust-analyzer))

**code snippet to reproduce**:
```rust
// add your code here

```
44 changes: 22 additions & 22 deletions src/tools/rust-analyzer/.typos.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[default.extend-identifiers]
AnserStyle = "AnserStyle"
datas = "datas"
impl_froms = "impl_froms"
selfs = "selfs"
[files]
extend-exclude = [
"*.rast",
"bench_data/",
"crates/parser/test_data/lexer/err/",
"crates/project-model/test_data/",
]
ignore-hidden = false

[default]
extend-ignore-re = [
# ignore string which contains $0, which is used widely in tests
".*\\$0.*",
# ignore generated content like `boxed....nner()`, `Defaul...efault`
"\\w*\\.{3,4}\\w*",
'"flate2"',
"raison d'être",
]

[default.extend-words]
anser = "anser"
ba = "ba"
fo = "fo"
ket = "ket"
makro = "makro"
raison = "raison"
trivias = "trivias"
TOOD = "TOOD"

[default]
extend-ignore-re = [
# ignore string which contains $x (x is a num), which use widely in test
".*\\$\\d.*",
# ignore generated content like `boxed....nner()`, `Defaul...efault`
"\\w*\\.{3,4}\\w*",
]

[files]
extend-exclude = [
"*.json",
"*.rast",
"crates/parser/test_data/lexer/err/*",
"bench_data/*",
]
[default.extend-identifiers]
datas = "datas"
impl_froms = "impl_froms"
selfs = "selfs"
5 changes: 3 additions & 2 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ dependencies = [
"arrayvec",
"cfg",
"cov-mark",
"crossbeam-channel",
"dot",
"either",
"expect-test",
Expand Down Expand Up @@ -713,6 +712,7 @@ dependencies = [
"arrayvec",
"base-db",
"cov-mark",
"crossbeam-channel",
"either",
"expect-test",
"fst",
Expand Down Expand Up @@ -951,7 +951,6 @@ dependencies = [
"anyhow",
"crossbeam-channel",
"hir-expand",
"ide",
"ide-db",
"itertools",
"proc-macro-api",
Expand Down Expand Up @@ -1856,7 +1855,9 @@ dependencies = [
name = "span"
version = "0.0.0"
dependencies = [
"hashbrown",
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash",
"salsa",
"stdx",
"syntax",
Expand Down
6 changes: 5 additions & 1 deletion src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
resolver = "2"

[workspace.package]
rust-version = "1.74"
rust-version = "1.76"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer team"]
Expand All @@ -28,6 +28,10 @@ incremental = true
# Set this to 1 or 2 to get more useful backtraces in debugger.
debug = 0

[profile.dev-rel]
inherits = "release"
debug = 2

[patch.'crates-io']
# rowan = { path = "../rowan" }

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl CrateGraph {
.arena
.iter_mut()
.take(m)
.find_map(|(id, data)| merge((id, data), (topo, &crate_data)).then_some(id));
.find_map(|(id, data)| merge((id, data), (topo, crate_data)).then_some(id));

let new_id =
if let Some(res) = res { res } else { self.arena.alloc(crate_data.clone()) };
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl CommandHandle {
let (sender, receiver) = unbounded();
let actor = CargoActor::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.name("CargoHandle".to_owned())
.name("CommandHandle".to_owned())
.spawn(move || actor.run())
.expect("failed to spawn thread");
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::mem;
use base_db::CrateId;
use either::Either;
use hir_expand::{
ast_id_map::AstIdMap,
name::{name, AsName, Name},
ExpandError, InFile,
};
use intern::Interned;
use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use span::AstIdMap;
use syntax::{
ast::{
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,
Expand Down
34 changes: 34 additions & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/body/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,40 @@ pub mod cov_mark {
);
}

#[test]
fn macro_exported_in_block_mod() {
check_at(
r#"
#[macro_export]
macro_rules! foo {
() => { pub struct FooWorks; };
}
macro_rules! bar {
() => { pub struct BarWorks; };
}
fn main() {
mod module {
foo!();
bar!();
$0
}
}
"#,
expect![[r#"
block scope
module: t

block scope::module
BarWorks: t v
FooWorks: t v

crate
foo: m
main: v
"#]],
);
}

#[test]
fn macro_resolve_legacy() {
check_at(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ impl ChildBySource for DefWithBodyId {
VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id)
}

for (_, def_map) in body.blocks(db) {
for (block, def_map) in body.blocks(db) {
// All block expressions are merged into the same map, because they logically all add
// inner items to the containing `DefWithBodyId`.
def_map[DefMap::ROOT].scope.child_by_source_to(db, res, file_id);
res[keys::BLOCK].insert(block.lookup(db).ast_id.to_node(db.upcast()), block);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/tools/rust-analyzer/crates/hir-def/src/dyn_map/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use syntax::{ast, AstNode, AstPtr};

use crate::{
dyn_map::{DynMap, Policy},
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
TypeOrConstParamId, UnionId, UseId,
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
};

pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;

pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
pub const CONST: Key<ast::Const, ConstId> = Key::new();
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
Expand Down
9 changes: 2 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ use std::{
use ast::{AstNode, StructKind};
use base_db::CrateId;
use either::Either;
use hir_expand::{
ast_id_map::{AstIdNode, FileAstId},
attrs::RawAttrs,
name::Name,
ExpandTo, HirFileId, InFile,
};
use hir_expand::{attrs::RawAttrs, name::Name, ExpandTo, HirFileId, InFile};
use intern::Interned;
use la_arena::{Arena, Idx, IdxRange, RawIdx};
use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use span::Span;
use span::{AstIdNode, FileAstId, Span};
use stdx::never;
use syntax::{ast, match_ast, SyntaxKind};
use triomphe::Arc;
Expand Down
5 changes: 2 additions & 3 deletions src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use std::collections::hash_map::Entry;

use hir_expand::{
ast_id_map::AstIdMap, mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId,
};
use hir_expand::{mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId};
use la_arena::Arena;
use span::AstIdMap;
use syntax::{
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
AstNode,
Expand Down
3 changes: 1 addition & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ use base_db::{
CrateId, Edition,
};
use hir_expand::{
ast_id_map::{AstIdNode, FileAstId},
builtin_attr_macro::BuiltinAttrExpander,
builtin_derive_macro::BuiltinDeriveExpander,
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
Expand All @@ -91,7 +90,7 @@ use hir_expand::{
use item_tree::ExternBlock;
use la_arena::Idx;
use nameres::DefMap;
use span::{FileId, Span};
use span::{AstIdNode, FileAstId, FileId, Span};
use stdx::impl_from;
use syntax::{ast, AstNode};

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use std::cell::OnceCell;

use hir_expand::{
ast_id_map::{AstIdMap, AstIdNode},
span_map::{SpanMap, SpanMapRef},
AstId, HirFileId, InFile,
};
use span::{AstIdMap, AstIdNode};
use syntax::ast;
use triomphe::Arc;

Expand Down
10 changes: 8 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ use std::ops::Deref;

use base_db::{CrateId, Edition, FileId};
use hir_expand::{
ast_id_map::FileAstId, name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId,
MacroDefId,
name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId, MacroDefId,
};
use itertools::Itertools;
use la_arena::Arena;
use profile::Count;
use rustc_hash::{FxHashMap, FxHashSet};
use span::FileAstId;
use stdx::format_to;
use syntax::{ast, SmolStr};
use triomphe::Arc;
Expand Down Expand Up @@ -469,6 +469,12 @@ impl DefMap {
CrateRootModuleId { krate: self.krate }
}

/// This is the same as [`Self::crate_root`] for crate def maps, but for block def maps, it
/// returns the root block module.
pub fn root_module_id(&self) -> ModuleId {
self.module_id(Self::ROOT)
}

pub(crate) fn resolve_path(
&self,
db: &dyn DefDatabase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use base_db::{CrateId, Dependency, Edition, FileId};
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_expand::{
ast_id_map::FileAstId,
attrs::{Attr, AttrId},
builtin_attr_macro::{find_builtin_attr, BuiltinAttrExpander},
builtin_derive_macro::find_builtin_derive,
Expand All @@ -23,7 +22,7 @@ use itertools::{izip, Itertools};
use la_arena::Idx;
use limit::Limit;
use rustc_hash::{FxHashMap, FxHashSet};
use span::{ErasedFileAstId, Span, SyntaxContextId};
use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
use stdx::always;
use syntax::{ast, SmolStr};
use triomphe::Arc;
Expand Down
29 changes: 19 additions & 10 deletions src/tools/rust-analyzer/crates/hir-def/src/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Name resolution façade.
use std::{fmt, hash::BuildHasherDefault};
use std::{fmt, hash::BuildHasherDefault, mem};

use base_db::CrateId;
use hir_expand::{
Expand Down Expand Up @@ -809,7 +809,7 @@ fn resolver_for_scope_(
for scope in scope_chain.into_iter().rev() {
if let Some(block) = scopes.block(scope) {
let def_map = db.block_def_map(block);
r = r.push_block_scope(def_map, DefMap::ROOT);
r = r.push_block_scope(def_map);
// FIXME: This adds as many module scopes as there are blocks, but resolving in each
// already traverses all parents, so this is O(n²). I think we could only store the
// innermost module scope instead?
Expand All @@ -835,8 +835,9 @@ impl Resolver {
self.push_scope(Scope::ImplDefScope(impl_def))
}

fn push_block_scope(self, def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
self.push_scope(Scope::BlockScope(ModuleItemMap { def_map, module_id }))
fn push_block_scope(self, def_map: Arc<DefMap>) -> Resolver {
debug_assert!(def_map.block_id().is_some());
self.push_scope(Scope::BlockScope(ModuleItemMap { def_map, module_id: DefMap::ROOT }))
}

fn push_expr_scope(
Expand Down Expand Up @@ -986,19 +987,27 @@ pub trait HasResolver: Copy {
impl HasResolver for ModuleId {
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
let mut def_map = self.def_map(db);
let mut modules: SmallVec<[_; 1]> = smallvec![];
let mut module_id = self.local_id;
let mut modules: SmallVec<[_; 1]> = smallvec![];

if !self.is_block_module() {
return Resolver { scopes: vec![], module_scope: ModuleItemMap { def_map, module_id } };
}

while let Some(parent) = def_map.parent() {
modules.push((def_map, module_id));
def_map = parent.def_map(db);
module_id = parent.local_id;
let block_def_map = mem::replace(&mut def_map, parent.def_map(db));
modules.push(block_def_map);
if !parent.is_block_module() {
module_id = parent.local_id;
break;
}
}
let mut resolver = Resolver {
scopes: Vec::with_capacity(modules.len()),
module_scope: ModuleItemMap { def_map, module_id },
};
for (def_map, module) in modules.into_iter().rev() {
resolver = resolver.push_block_scope(def_map, module);
for def_map in modules.into_iter().rev() {
resolver = resolver.push_block_scope(def_map);
}
resolver
}
Expand Down
Loading