Skip to content

Commit 2a9e6fb

Browse files
authored
Merge pull request #19016 from Veykril/push-moqnsytyrupu
fix: Fix `ItemScope` not recording glob imports
2 parents a365f73 + 99b0ab5 commit 2a9e6fb

File tree

11 files changed

+234
-208
lines changed

11 files changed

+234
-208
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn outer() {
475475
476476
block scope::tests
477477
name: _
478-
outer: v
478+
outer: vg
479479
480480
crate
481481
outer: v

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

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl ImportMap {
168168
match import {
169169
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
170170
ImportOrExternCrate::Import(id) => Some(id.import.into()),
171+
ImportOrExternCrate::Glob(id) => Some(id.into()),
171172
}
172173
} else {
173174
match item {

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

+112-84
Large diffs are not rendered by default.

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use triomphe::Arc;
2828
use crate::{
2929
attr::Attrs,
3030
db::DefDatabase,
31-
item_scope::{ImportId, ImportOrExternCrate, ImportType, PerNsGlobImports},
31+
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ImportType, PerNsGlobImports},
3232
item_tree::{
3333
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
3434
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
@@ -527,7 +527,10 @@ impl DefCollector<'_> {
527527
// FIXME: This should specifically look for a glob import somehow and record that here
528528
self.def_map.prelude = Some((
529529
m,
530-
import.and_then(ImportOrExternCrate::into_import).map(|it| it.import),
530+
import
531+
.and_then(ImportOrExternCrate::into_import)
532+
.and_then(ImportOrGlob::into_import)
533+
.map(|it| it.import),
531534
));
532535
}
533536
types => {

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ mod a {
103103
c: t
104104
105105
crate::a::b::c
106-
A: v
107-
b: t
106+
A: vg
107+
b: tg
108108
"#]],
109109
);
110110
}
@@ -256,8 +256,8 @@ pub enum Foo { Bar, Baz }
256256
"#,
257257
expect![[r#"
258258
crate
259-
Bar: t v
260-
Baz: t v
259+
Bar: tg vg
260+
Baz: tg vg
261261
"#]],
262262
);
263263
}
@@ -421,10 +421,10 @@ pub struct NotExported;
421421
"#,
422422
expect![[r#"
423423
crate
424-
Exported: t v
425-
PublicItem: t v
426-
allowed_reexport: t
427-
exported: t
424+
Exported: tg vg
425+
PublicItem: tg vg
426+
allowed_reexport: tg
427+
exported: tg
428428
not_allowed_reexport1: _
429429
not_allowed_reexport2: _
430430
"#]],
@@ -692,7 +692,7 @@ mod b {
692692
b: t
693693
694694
crate::a
695-
T: t v
695+
T: t vg
696696
697697
crate::b
698698
T: v

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

+37-37
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub struct Baz;
1818
"#,
1919
expect![[r#"
2020
crate
21-
Baz: t v
22-
Foo: t v
23-
bar: t
21+
Baz: tg vg
22+
Foo: tg vg
23+
bar: tg
2424
foo: t
2525
2626
crate::foo
@@ -53,20 +53,20 @@ pub use super::*;
5353
"#,
5454
expect![[r#"
5555
crate
56-
Baz: t v
57-
Foo: t v
58-
bar: t
56+
Baz: tg vg
57+
Foo: tg vg
58+
bar: tg
5959
foo: t
6060
6161
crate::foo
62-
Baz: t v
62+
Baz: tg vg
6363
Foo: t v
6464
bar: t
6565
6666
crate::foo::bar
6767
Baz: t v
68-
Foo: t v
69-
bar: t
68+
Foo: tg vg
69+
bar: tg
7070
"#]],
7171
);
7272
}
@@ -91,20 +91,20 @@ pub use super::*;
9191
",
9292
expect![[r#"
9393
crate
94-
Baz: t v
95-
bar: t
94+
Baz: tg vg
95+
bar: tg
9696
foo: t
9797
9898
crate::foo
99-
Baz: t v
99+
Baz: tg vg
100100
PrivateStructFoo: t v
101101
bar: t
102102
103103
crate::foo::bar
104104
Baz: t v
105105
PrivateStructBar: t v
106-
PrivateStructFoo: t v
107-
bar: t
106+
PrivateStructFoo: tg vg
107+
bar: tg
108108
"#]],
109109
);
110110
}
@@ -130,9 +130,9 @@ pub(crate) struct PubCrateStruct;
130130
",
131131
expect![[r#"
132132
crate
133-
Foo: t
134-
PubCrateStruct: t v
135-
bar: t
133+
Foo: tg
134+
PubCrateStruct: tg vg
135+
bar: tg
136136
foo: t
137137
138138
crate::foo
@@ -160,7 +160,7 @@ pub struct Baz;
160160
"#,
161161
expect![[r#"
162162
crate
163-
Baz: t v
163+
Baz: tg vg
164164
"#]],
165165
);
166166
}
@@ -178,7 +178,7 @@ struct Foo;
178178
"#,
179179
expect![[r#"
180180
crate
181-
Baz: t v
181+
Baz: tg vg
182182
"#]],
183183
);
184184
}
@@ -193,8 +193,8 @@ use self::Foo::*;
193193
"#,
194194
expect![[r#"
195195
crate
196-
Bar: t v
197-
Baz: t v
196+
Bar: tg vg
197+
Baz: tg vg
198198
Foo: t
199199
"#]],
200200
);
@@ -210,8 +210,8 @@ use self::Foo::{*};
210210
"#,
211211
expect![[r#"
212212
crate
213-
Bar: t v
214-
Baz: t v
213+
Bar: tg vg
214+
Baz: tg vg
215215
Foo: t
216216
"#]],
217217
);
@@ -359,7 +359,7 @@ use event::Event;
359359
event: t
360360
361361
crate::event
362-
Event: t v
362+
Event: t vg
363363
serenity: t
364364
365365
crate::event::serenity
@@ -388,10 +388,10 @@ use reexport::*;
388388
"#,
389389
expect![[r#"
390390
crate
391-
Trait: t
391+
Trait: tg
392392
defs: t
393-
function: v
394-
makro: m
393+
function: vg
394+
makro: mg
395395
reexport: t
396396
397397
crate::defs
@@ -400,10 +400,10 @@ use reexport::*;
400400
makro: m
401401
402402
crate::reexport
403-
Trait: t
404-
function: v
403+
Trait: tg
404+
function: vg
405405
inner: t
406-
makro: m
406+
makro: mg
407407
408408
crate::reexport::inner
409409
Trait: ti
@@ -442,12 +442,12 @@ mod glob_target {
442442
ShouldBePrivate: t v
443443
444444
crate::outer
445-
ShouldBePrivate: t v
445+
ShouldBePrivate: tg vg
446446
inner_superglob: t
447447
448448
crate::outer::inner_superglob
449-
ShouldBePrivate: t v
450-
inner_superglob: t
449+
ShouldBePrivate: tg vg
450+
inner_superglob: tg
451451
"#]],
452452
);
453453
}
@@ -473,20 +473,20 @@ use reexport_2::*;
473473
"#,
474474
expect![[r#"
475475
crate
476-
Placeholder: t v
476+
Placeholder: tg vg
477477
libs: t
478-
reexport_1: t
478+
reexport_1: tg
479479
reexport_2: t
480480
481481
crate::libs
482482
Placeholder: t v
483483
484484
crate::reexport_2
485-
Placeholder: t v
485+
Placeholder: tg vg
486486
reexport_1: t
487487
488488
crate::reexport_2::reexport_1
489-
Placeholder: t v
489+
Placeholder: tg vg
490490
"#]],
491491
);
492492
}

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ macro_rules! structs {
9797
bar: t
9898
9999
crate::bar
100-
Bar: t
101-
Foo: t
102-
bar: t
100+
Bar: tg
101+
Foo: tg
102+
bar: tg
103103
"#]],
104104
);
105105
}
@@ -130,9 +130,9 @@ macro_rules! structs {
130130
bar: t
131131
132132
crate::bar
133-
Bar: t
134-
Foo: t
135-
bar: t
133+
Bar: tg
134+
Foo: tg
135+
bar: tg
136136
"#]],
137137
);
138138
}
@@ -169,9 +169,9 @@ macro_rules! inner {
169169
bar: t
170170
171171
crate::bar
172-
Bar: t
173-
Foo: t
174-
bar: t
172+
Bar: tg
173+
Foo: tg
174+
bar: tg
175175
"#]],
176176
);
177177
}
@@ -794,7 +794,7 @@ pub trait Clone {}
794794
"#,
795795
expect![[r#"
796796
crate
797-
Clone: t m
797+
Clone: tg mg
798798
"#]],
799799
);
800800
}
@@ -1075,9 +1075,9 @@ macro_rules! mbe {
10751075
"#,
10761076
expect![[r#"
10771077
crate
1078-
DummyTrait: m
1079-
attribute_macro: m
1080-
function_like_macro: m
1078+
DummyTrait: mg
1079+
attribute_macro: mg
1080+
function_like_macro: mg
10811081
"#]],
10821082
);
10831083
}

0 commit comments

Comments
 (0)