Skip to content

Commit 1090205

Browse files
committed
Auto merge of rust-lang#121931 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents a09d91b + 964e769 commit 1090205

File tree

121 files changed

+3264
-1267
lines changed

Some content is hidden

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

121 files changed

+3264
-1267
lines changed

src/tools/rust-analyzer/.github/ISSUE_TEMPLATE/bug_report.md

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ Otherwise please try to provide information which will help us to fix the issue
2323
**rustc version**: (eg. output of `rustc -V`)
2424

2525
**relevant settings**: (eg. client settings, or environment variables like `CARGO`, `RUSTC`, `RUSTUP_HOME` or `CARGO_HOME`)
26+
27+
**repository link (if public, optional)**: (eg. [rust-analyzer](https://github.com/rust-lang/rust-analyzer))
28+
29+
**code snippet to reproduce**:
30+
```rust
31+
// add your code here
32+
33+
```

src/tools/rust-analyzer/.typos.toml

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
[default.extend-identifiers]
2-
AnserStyle = "AnserStyle"
3-
datas = "datas"
4-
impl_froms = "impl_froms"
5-
selfs = "selfs"
1+
[files]
2+
extend-exclude = [
3+
"*.rast",
4+
"bench_data/",
5+
"crates/parser/test_data/lexer/err/",
6+
"crates/project-model/test_data/",
7+
]
8+
ignore-hidden = false
9+
10+
[default]
11+
extend-ignore-re = [
12+
# ignore string which contains $0, which is used widely in tests
13+
".*\\$0.*",
14+
# ignore generated content like `boxed....nner()`, `Defaul...efault`
15+
"\\w*\\.{3,4}\\w*",
16+
'"flate2"',
17+
"raison d'être",
18+
]
619

720
[default.extend-words]
821
anser = "anser"
922
ba = "ba"
1023
fo = "fo"
1124
ket = "ket"
1225
makro = "makro"
13-
raison = "raison"
1426
trivias = "trivias"
15-
TOOD = "TOOD"
1627

17-
[default]
18-
extend-ignore-re = [
19-
# ignore string which contains $x (x is a num), which use widely in test
20-
".*\\$\\d.*",
21-
# ignore generated content like `boxed....nner()`, `Defaul...efault`
22-
"\\w*\\.{3,4}\\w*",
23-
]
24-
25-
[files]
26-
extend-exclude = [
27-
"*.json",
28-
"*.rast",
29-
"crates/parser/test_data/lexer/err/*",
30-
"bench_data/*",
31-
]
28+
[default.extend-identifiers]
29+
datas = "datas"
30+
impl_froms = "impl_froms"
31+
selfs = "selfs"

src/tools/rust-analyzer/Cargo.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ dependencies = [
636636
"arrayvec",
637637
"cfg",
638638
"cov-mark",
639-
"crossbeam-channel",
640639
"dot",
641640
"either",
642641
"expect-test",
@@ -713,6 +712,7 @@ dependencies = [
713712
"arrayvec",
714713
"base-db",
715714
"cov-mark",
715+
"crossbeam-channel",
716716
"either",
717717
"expect-test",
718718
"fst",
@@ -951,7 +951,6 @@ dependencies = [
951951
"anyhow",
952952
"crossbeam-channel",
953953
"hir-expand",
954-
"ide",
955954
"ide-db",
956955
"itertools",
957956
"proc-macro-api",
@@ -1856,7 +1855,9 @@ dependencies = [
18561855
name = "span"
18571856
version = "0.0.0"
18581857
dependencies = [
1858+
"hashbrown",
18591859
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1860+
"rustc-hash",
18601861
"salsa",
18611862
"stdx",
18621863
"syntax",

src/tools/rust-analyzer/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
44
resolver = "2"
55

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

31+
[profile.dev-rel]
32+
inherits = "release"
33+
debug = 2
34+
3135
[patch.'crates-io']
3236
# rowan = { path = "../rowan" }
3337

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl CrateGraph {
570570
.arena
571571
.iter_mut()
572572
.take(m)
573-
.find_map(|(id, data)| merge((id, data), (topo, &crate_data)).then_some(id));
573+
.find_map(|(id, data)| merge((id, data), (topo, crate_data)).then_some(id));
574574

575575
let new_id =
576576
if let Some(res) = res { res } else { self.arena.alloc(crate_data.clone()) };

src/tools/rust-analyzer/crates/flycheck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl CommandHandle {
494494
let (sender, receiver) = unbounded();
495495
let actor = CargoActor::new(sender, stdout, stderr);
496496
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
497-
.name("CargoHandle".to_owned())
497+
.name("CommandHandle".to_owned())
498498
.spawn(move || actor.run())
499499
.expect("failed to spawn thread");
500500
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::mem;
66
use base_db::CrateId;
77
use either::Either;
88
use hir_expand::{
9-
ast_id_map::AstIdMap,
109
name::{name, AsName, Name},
1110
ExpandError, InFile,
1211
};
1312
use intern::Interned;
1413
use profile::Count;
1514
use rustc_hash::FxHashMap;
1615
use smallvec::SmallVec;
16+
use span::AstIdMap;
1717
use syntax::{
1818
ast::{
1919
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,

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

+34
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,40 @@ pub mod cov_mark {
298298
);
299299
}
300300

301+
#[test]
302+
fn macro_exported_in_block_mod() {
303+
check_at(
304+
r#"
305+
#[macro_export]
306+
macro_rules! foo {
307+
() => { pub struct FooWorks; };
308+
}
309+
macro_rules! bar {
310+
() => { pub struct BarWorks; };
311+
}
312+
fn main() {
313+
mod module {
314+
foo!();
315+
bar!();
316+
$0
317+
}
318+
}
319+
"#,
320+
expect![[r#"
321+
block scope
322+
module: t
323+
324+
block scope::module
325+
BarWorks: t v
326+
FooWorks: t v
327+
328+
crate
329+
foo: m
330+
main: v
331+
"#]],
332+
);
333+
}
334+
301335
#[test]
302336
fn macro_resolve_legacy() {
303337
check_at(

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ impl ChildBySource for DefWithBodyId {
189189
VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id)
190190
}
191191

192-
for (_, def_map) in body.blocks(db) {
192+
for (block, def_map) in body.blocks(db) {
193193
// All block expressions are merged into the same map, because they logically all add
194194
// inner items to the containing `DefWithBodyId`.
195195
def_map[DefMap::ROOT].scope.child_by_source_to(db, res, file_id);
196+
res[keys::BLOCK].insert(block.lookup(db).ast_id.to_node(db.upcast()), block);
196197
}
197198
}
198199
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ use syntax::{ast, AstNode, AstPtr};
88

99
use crate::{
1010
dyn_map::{DynMap, Policy},
11-
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
12-
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
13-
TypeOrConstParamId, UnionId, UseId,
11+
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
12+
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
13+
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
1414
};
1515

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

18+
pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
1819
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
1920
pub const CONST: Key<ast::Const, ConstId> = Key::new();
2021
pub const STATIC: Key<ast::Static, StaticId> = Key::new();

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,13 @@ use std::{
4747
use ast::{AstNode, StructKind};
4848
use base_db::CrateId;
4949
use either::Either;
50-
use hir_expand::{
51-
ast_id_map::{AstIdNode, FileAstId},
52-
attrs::RawAttrs,
53-
name::Name,
54-
ExpandTo, HirFileId, InFile,
55-
};
50+
use hir_expand::{attrs::RawAttrs, name::Name, ExpandTo, HirFileId, InFile};
5651
use intern::Interned;
5752
use la_arena::{Arena, Idx, IdxRange, RawIdx};
5853
use profile::Count;
5954
use rustc_hash::FxHashMap;
6055
use smallvec::SmallVec;
61-
use span::Span;
56+
use span::{AstIdNode, FileAstId, Span};
6257
use stdx::never;
6358
use syntax::{ast, match_ast, SyntaxKind};
6459
use triomphe::Arc;

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
33
use std::collections::hash_map::Entry;
44

5-
use hir_expand::{
6-
ast_id_map::AstIdMap, mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId,
7-
};
5+
use hir_expand::{mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId};
86
use la_arena::Arena;
7+
use span::AstIdMap;
98
use syntax::{
109
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
1110
AstNode,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ use base_db::{
7676
CrateId, Edition,
7777
};
7878
use hir_expand::{
79-
ast_id_map::{AstIdNode, FileAstId},
8079
builtin_attr_macro::BuiltinAttrExpander,
8180
builtin_derive_macro::BuiltinDeriveExpander,
8281
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
@@ -91,7 +90,7 @@ use hir_expand::{
9190
use item_tree::ExternBlock;
9291
use la_arena::Idx;
9392
use nameres::DefMap;
94-
use span::{FileId, Span};
93+
use span::{AstIdNode, FileAstId, FileId, Span};
9594
use stdx::impl_from;
9695
use syntax::{ast, AstNode};
9796

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
use std::cell::OnceCell;
33

44
use hir_expand::{
5-
ast_id_map::{AstIdMap, AstIdNode},
65
span_map::{SpanMap, SpanMapRef},
76
AstId, HirFileId, InFile,
87
};
8+
use span::{AstIdMap, AstIdNode};
99
use syntax::ast;
1010
use triomphe::Arc;
1111

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ use std::ops::Deref;
6161

6262
use base_db::{CrateId, Edition, FileId};
6363
use hir_expand::{
64-
ast_id_map::FileAstId, name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId,
65-
MacroDefId,
64+
name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId, MacroDefId,
6665
};
6766
use itertools::Itertools;
6867
use la_arena::Arena;
6968
use profile::Count;
7069
use rustc_hash::{FxHashMap, FxHashSet};
70+
use span::FileAstId;
7171
use stdx::format_to;
7272
use syntax::{ast, SmolStr};
7373
use triomphe::Arc;
@@ -469,6 +469,12 @@ impl DefMap {
469469
CrateRootModuleId { krate: self.krate }
470470
}
471471

472+
/// This is the same as [`Self::crate_root`] for crate def maps, but for block def maps, it
473+
/// returns the root block module.
474+
pub fn root_module_id(&self) -> ModuleId {
475+
self.module_id(Self::ROOT)
476+
}
477+
472478
pub(crate) fn resolve_path(
473479
&self,
474480
db: &dyn DefDatabase,

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use base_db::{CrateId, Dependency, Edition, FileId};
99
use cfg::{CfgExpr, CfgOptions};
1010
use either::Either;
1111
use hir_expand::{
12-
ast_id_map::FileAstId,
1312
attrs::{Attr, AttrId},
1413
builtin_attr_macro::{find_builtin_attr, BuiltinAttrExpander},
1514
builtin_derive_macro::find_builtin_derive,
@@ -23,7 +22,7 @@ use itertools::{izip, Itertools};
2322
use la_arena::Idx;
2423
use limit::Limit;
2524
use rustc_hash::{FxHashMap, FxHashSet};
26-
use span::{ErasedFileAstId, Span, SyntaxContextId};
25+
use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
2726
use stdx::always;
2827
use syntax::{ast, SmolStr};
2928
use triomphe::Arc;

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Name resolution façade.
2-
use std::{fmt, hash::BuildHasherDefault};
2+
use std::{fmt, hash::BuildHasherDefault, mem};
33

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

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

842843
fn push_expr_scope(
@@ -986,19 +987,27 @@ pub trait HasResolver: Copy {
986987
impl HasResolver for ModuleId {
987988
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
988989
let mut def_map = self.def_map(db);
989-
let mut modules: SmallVec<[_; 1]> = smallvec![];
990990
let mut module_id = self.local_id;
991+
let mut modules: SmallVec<[_; 1]> = smallvec![];
992+
993+
if !self.is_block_module() {
994+
return Resolver { scopes: vec![], module_scope: ModuleItemMap { def_map, module_id } };
995+
}
996+
991997
while let Some(parent) = def_map.parent() {
992-
modules.push((def_map, module_id));
993-
def_map = parent.def_map(db);
994-
module_id = parent.local_id;
998+
let block_def_map = mem::replace(&mut def_map, parent.def_map(db));
999+
modules.push(block_def_map);
1000+
if !parent.is_block_module() {
1001+
module_id = parent.local_id;
1002+
break;
1003+
}
9951004
}
9961005
let mut resolver = Resolver {
9971006
scopes: Vec::with_capacity(modules.len()),
9981007
module_scope: ModuleItemMap { def_map, module_id },
9991008
};
1000-
for (def_map, module) in modules.into_iter().rev() {
1001-
resolver = resolver.push_block_scope(def_map, module);
1009+
for def_map in modules.into_iter().rev() {
1010+
resolver = resolver.push_block_scope(def_map);
10021011
}
10031012
resolver
10041013
}

0 commit comments

Comments
 (0)