Skip to content

Commit f15a7f3

Browse files
committed
Auto merge of #148471 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@51af7a3. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents e5efc33 + 5873327 commit f15a7f3

File tree

96 files changed

+2984
-1093
lines changed

Some content is hidden

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

96 files changed

+2984
-1093
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ trivias = "trivias"
3333
thir = "thir"
3434
jod = "jod"
3535
tructure = "tructure"
36+
taits = "taits"
3637

3738
[default.extend-identifiers]
3839
anc = "anc"

src/tools/rust-analyzer/Cargo.lock

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,22 @@ dependencies = [
418418
"syn",
419419
]
420420

421+
[[package]]
422+
name = "dhat"
423+
version = "0.3.3"
424+
source = "registry+https://github.com/rust-lang/crates.io-index"
425+
checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827"
426+
dependencies = [
427+
"backtrace",
428+
"lazy_static",
429+
"mintex",
430+
"parking_lot",
431+
"rustc-hash 1.1.0",
432+
"serde",
433+
"serde_json",
434+
"thousands",
435+
]
436+
421437
[[package]]
422438
name = "dirs"
423439
version = "6.0.0"
@@ -1383,6 +1399,12 @@ dependencies = [
13831399
"adler2",
13841400
]
13851401

1402+
[[package]]
1403+
name = "mintex"
1404+
version = "0.1.4"
1405+
source = "registry+https://github.com/rust-lang/crates.io-index"
1406+
checksum = "c505b3e17ed6b70a7ed2e67fbb2c560ee327353556120d6e72f5232b6880d536"
1407+
13861408
[[package]]
13871409
name = "mio"
13881410
version = "1.1.0"
@@ -1452,7 +1474,7 @@ version = "0.50.3"
14521474
source = "registry+https://github.com/rust-lang/crates.io-index"
14531475
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
14541476
dependencies = [
1455-
"windows-sys 0.60.2",
1477+
"windows-sys 0.61.0",
14561478
]
14571479

14581480
[[package]]
@@ -2011,6 +2033,7 @@ dependencies = [
20112033
"cargo_metadata 0.21.0",
20122034
"cfg",
20132035
"crossbeam-channel",
2036+
"dhat",
20142037
"dirs",
20152038
"dissimilar",
20162039
"expect-test",
@@ -2047,6 +2070,7 @@ dependencies = [
20472070
"serde",
20482071
"serde_derive",
20492072
"serde_json",
2073+
"smallvec",
20502074
"stdx",
20512075
"syntax",
20522076
"syntax-bridge",
@@ -2528,6 +2552,12 @@ dependencies = [
25282552
"syn",
25292553
]
25302554

2555+
[[package]]
2556+
name = "thousands"
2557+
version = "0.2.0"
2558+
source = "registry+https://github.com/rust-lang/crates.io-index"
2559+
checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
2560+
25312561
[[package]]
25322562
name = "thread_local"
25332563
version = "1.1.9"

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,13 @@ impl<'a> Ctx<'a> {
370370
});
371371
match &vis {
372372
RawVisibility::Public => RawVisibilityId::PUB,
373-
RawVisibility::Module(path, explicitness) if path.segments().is_empty() => {
374-
match (path.kind, explicitness) {
375-
(PathKind::SELF, VisibilityExplicitness::Explicit) => {
376-
RawVisibilityId::PRIV_EXPLICIT
377-
}
378-
(PathKind::SELF, VisibilityExplicitness::Implicit) => {
379-
RawVisibilityId::PRIV_IMPLICIT
380-
}
381-
(PathKind::Crate, _) => RawVisibilityId::PUB_CRATE,
382-
_ => RawVisibilityId(self.visibilities.insert_full(vis).0 as u32),
383-
}
373+
RawVisibility::PubSelf(VisibilityExplicitness::Explicit) => {
374+
RawVisibilityId::PRIV_EXPLICIT
384375
}
376+
RawVisibility::PubSelf(VisibilityExplicitness::Implicit) => {
377+
RawVisibilityId::PRIV_IMPLICIT
378+
}
379+
RawVisibility::PubCrate => RawVisibilityId::PUB_CRATE,
385380
_ => RawVisibilityId(self.visibilities.insert_full(vis).0 as u32),
386381
}
387382
}
@@ -466,10 +461,7 @@ pub(crate) fn lower_use_tree(
466461
}
467462

468463
fn private_vis() -> RawVisibility {
469-
RawVisibility::Module(
470-
Interned::new(ModPath::from_kind(PathKind::SELF)),
471-
VisibilityExplicitness::Implicit,
472-
)
464+
RawVisibility::PubSelf(VisibilityExplicitness::Implicit)
473465
}
474466

475467
pub(crate) fn visibility_from_ast(
@@ -486,9 +478,11 @@ pub(crate) fn visibility_from_ast(
486478
Some(path) => path,
487479
}
488480
}
489-
ast::VisibilityKind::PubCrate => ModPath::from_kind(PathKind::Crate),
481+
ast::VisibilityKind::PubCrate => return RawVisibility::PubCrate,
490482
ast::VisibilityKind::PubSuper => ModPath::from_kind(PathKind::Super(1)),
491-
ast::VisibilityKind::PubSelf => ModPath::from_kind(PathKind::SELF),
483+
ast::VisibilityKind::PubSelf => {
484+
return RawVisibility::PubSelf(VisibilityExplicitness::Explicit);
485+
}
492486
ast::VisibilityKind::Pub => return RawVisibility::Public,
493487
};
494488
RawVisibility::Module(Interned::new(path), VisibilityExplicitness::Explicit)

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/meta_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ macro_rules! m2 { () => ( ${invalid()} ) }
9898

9999
#[test]
100100
fn test_rustc_issue_57597() {
101-
// <https://github.com/rust-lang/rust/blob/HEAD/tests/ui/issues/issue-57597.rs>
101+
// <https://github.com/rust-lang/rust/blob/ec2cc76/tests/ui/macros/issue-57597.rs>
102102
check(
103103
r#"
104104
macro_rules! m0 { ($($($i:ident)?)+) => {}; }

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,9 @@ fn resolver_for_scope_<'db>(
10751075
if let Some(block) = scopes.block(scope) {
10761076
let def_map = block_def_map(db, block);
10771077
let local_def_map = block.lookup(db).module.only_local_def_map(db);
1078-
r = r.push_block_scope(def_map, local_def_map);
1078+
// Using `DefMap::ROOT` is okay here since inside modules other than the root,
1079+
// there can't directly be expressions.
1080+
r = r.push_block_scope(def_map, local_def_map, DefMap::ROOT);
10791081
// FIXME: This adds as many module scopes as there are blocks, but resolving in each
10801082
// already traverses all parents, so this is O(n²). I think we could only store the
10811083
// innermost module scope instead?
@@ -1108,12 +1110,9 @@ impl<'db> Resolver<'db> {
11081110
self,
11091111
def_map: &'db DefMap,
11101112
local_def_map: &'db LocalDefMap,
1113+
module_id: LocalModuleId,
11111114
) -> Resolver<'db> {
1112-
self.push_scope(Scope::BlockScope(ModuleItemMap {
1113-
def_map,
1114-
local_def_map,
1115-
module_id: DefMap::ROOT,
1116-
}))
1115+
self.push_scope(Scope::BlockScope(ModuleItemMap { def_map, local_def_map, module_id }))
11171116
}
11181117

11191118
fn push_expr_scope(
@@ -1273,7 +1272,7 @@ impl HasResolver for ModuleId {
12731272
let (mut def_map, local_def_map) = self.local_def_map(db);
12741273
let mut module_id = self.local_id;
12751274

1276-
if !self.is_block_module() {
1275+
if !self.is_within_block() {
12771276
return Resolver {
12781277
scopes: vec![],
12791278
module_scope: ModuleItemMap { def_map, local_def_map, module_id },
@@ -1283,18 +1282,18 @@ impl HasResolver for ModuleId {
12831282
let mut modules: SmallVec<[_; 1]> = smallvec![];
12841283
while let Some(parent) = def_map.parent() {
12851284
let block_def_map = mem::replace(&mut def_map, parent.def_map(db));
1286-
modules.push(block_def_map);
1287-
if !parent.is_block_module() {
1288-
module_id = parent.local_id;
1285+
let block_module_id = mem::replace(&mut module_id, parent.local_id);
1286+
modules.push((block_def_map, block_module_id));
1287+
if !parent.is_within_block() {
12891288
break;
12901289
}
12911290
}
12921291
let mut resolver = Resolver {
12931292
scopes: Vec::with_capacity(modules.len()),
12941293
module_scope: ModuleItemMap { def_map, local_def_map, module_id },
12951294
};
1296-
for def_map in modules.into_iter().rev() {
1297-
resolver = resolver.push_block_scope(def_map, local_def_map);
1295+
for (def_map, module_id) in modules.into_iter().rev() {
1296+
resolver = resolver.push_block_scope(def_map, local_def_map, module_id);
12981297
}
12991298
resolver
13001299
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,21 @@ pub(crate) fn field_visibilities_query(
289289

290290
pub fn visibility_from_ast(
291291
db: &dyn DefDatabase,
292-
has_resolver: impl HasResolver,
292+
has_resolver: impl HasResolver + HasModule,
293293
ast_vis: InFile<Option<ast::Visibility>>,
294294
) -> Visibility {
295295
let mut span_map = None;
296296
let raw_vis = crate::item_tree::visibility_from_ast(db, ast_vis.value, &mut |range| {
297297
span_map.get_or_insert_with(|| db.span_map(ast_vis.file_id)).span_for_range(range).ctx
298298
});
299-
if raw_vis == RawVisibility::Public {
300-
return Visibility::Public;
299+
match raw_vis {
300+
RawVisibility::PubSelf(explicitness) => {
301+
Visibility::Module(has_resolver.module(db), explicitness)
302+
}
303+
RawVisibility::PubCrate => Visibility::PubCrate(has_resolver.krate(db)),
304+
RawVisibility::Public => Visibility::Public,
305+
RawVisibility::Module(..) => Visibility::resolve(db, &has_resolver.resolver(db), &raw_vis),
301306
}
302-
303-
Visibility::resolve(db, &has_resolver.resolver(db), &raw_vis)
304307
}
305308

306309
/// Resolve visibility of a type alias.

src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn autoderef<'db>(
3838
env: Arc<TraitEnvironment<'db>>,
3939
ty: Canonical<'db, Ty<'db>>,
4040
) -> impl Iterator<Item = Ty<'db>> + use<'db> {
41-
let mut table = InferenceTable::new(db, env);
41+
let mut table = InferenceTable::new(db, env, None);
4242
let ty = table.instantiate_canonical(ty);
4343
let mut autoderef = Autoderef::new_no_tracking(&mut table, ty);
4444
let mut v = Vec::new();

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,9 +2078,10 @@ pub fn write_visibility<'db>(
20782078
if vis_id == module_id {
20792079
// pub(self) or omitted
20802080
Ok(())
2081-
} else if root_module_id == vis_id {
2081+
} else if root_module_id == vis_id && !root_module_id.is_within_block() {
20822082
write!(f, "pub(crate) ")
2083-
} else if module_id.containing_module(f.db) == Some(vis_id) {
2083+
} else if module_id.containing_module(f.db) == Some(vis_id) && !vis_id.is_block_module()
2084+
{
20842085
write!(f, "pub(super) ")
20852086
} else {
20862087
write!(f, "pub(in ...) ")

0 commit comments

Comments
 (0)