Skip to content

Commit

Permalink
Fix ItemScope not recording glob imports
Browse files Browse the repository at this point in the history
This caused us other code to incorrectly assume in dealing with a declaration when in fact it was dealing with a glob imported definition
  • Loading branch information
Veykril committed Jan 24, 2025
1 parent c78cc2b commit 3b88a2f
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 208 deletions.
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn outer() {
block scope::tests
name: _
outer: v
outer: vg
crate
outer: v
Expand Down
1 change: 1 addition & 0 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl ImportMap {
match import {
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
ImportOrExternCrate::Import(id) => Some(id.import.into()),
ImportOrExternCrate::Glob(id) => Some(id.into()),
}
} else {
match item {
Expand Down
196 changes: 112 additions & 84 deletions crates/hir-def/src/item_scope.rs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use triomphe::Arc;
use crate::{
attr::Attrs,
db::DefDatabase,
item_scope::{ImportId, ImportOrExternCrate, ImportType, PerNsGlobImports},
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ImportType, PerNsGlobImports},
item_tree::{
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
Expand Down Expand Up @@ -527,7 +527,10 @@ impl DefCollector<'_> {
// FIXME: This should specifically look for a glob import somehow and record that here
self.def_map.prelude = Some((
m,
import.and_then(ImportOrExternCrate::into_import).map(|it| it.import),
import
.and_then(ImportOrExternCrate::into_import)
.and_then(ImportOrGlob::into_import)
.map(|it| it.import),
));
}
types => {
Expand Down
18 changes: 9 additions & 9 deletions crates/hir-def/src/nameres/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ mod a {
c: t
crate::a::b::c
A: v
b: t
A: vg
b: tg
"#]],
);
}
Expand Down Expand Up @@ -256,8 +256,8 @@ pub enum Foo { Bar, Baz }
"#,
expect![[r#"
crate
Bar: t v
Baz: t v
Bar: tg vg
Baz: tg vg
"#]],
);
}
Expand Down Expand Up @@ -421,10 +421,10 @@ pub struct NotExported;
"#,
expect![[r#"
crate
Exported: t v
PublicItem: t v
allowed_reexport: t
exported: t
Exported: tg vg
PublicItem: tg vg
allowed_reexport: tg
exported: tg
not_allowed_reexport1: _
not_allowed_reexport2: _
"#]],
Expand Down Expand Up @@ -692,7 +692,7 @@ mod b {
b: t
crate::a
T: t v
T: t vg
crate::b
T: v
Expand Down
74 changes: 37 additions & 37 deletions crates/hir-def/src/nameres/tests/globs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub struct Baz;
"#,
expect![[r#"
crate
Baz: t v
Foo: t v
bar: t
Baz: tg vg
Foo: tg vg
bar: tg
foo: t
crate::foo
Expand Down Expand Up @@ -53,20 +53,20 @@ pub use super::*;
"#,
expect![[r#"
crate
Baz: t v
Foo: t v
bar: t
Baz: tg vg
Foo: tg vg
bar: tg
foo: t
crate::foo
Baz: t v
Baz: tg vg
Foo: t v
bar: t
crate::foo::bar
Baz: t v
Foo: t v
bar: t
Foo: tg vg
bar: tg
"#]],
);
}
Expand All @@ -91,20 +91,20 @@ pub use super::*;
",
expect![[r#"
crate
Baz: t v
bar: t
Baz: tg vg
bar: tg
foo: t
crate::foo
Baz: t v
Baz: tg vg
PrivateStructFoo: t v
bar: t
crate::foo::bar
Baz: t v
PrivateStructBar: t v
PrivateStructFoo: t v
bar: t
PrivateStructFoo: tg vg
bar: tg
"#]],
);
}
Expand All @@ -130,9 +130,9 @@ pub(crate) struct PubCrateStruct;
",
expect![[r#"
crate
Foo: t
PubCrateStruct: t v
bar: t
Foo: tg
PubCrateStruct: tg vg
bar: tg
foo: t
crate::foo
Expand Down Expand Up @@ -160,7 +160,7 @@ pub struct Baz;
"#,
expect![[r#"
crate
Baz: t v
Baz: tg vg
"#]],
);
}
Expand All @@ -178,7 +178,7 @@ struct Foo;
"#,
expect![[r#"
crate
Baz: t v
Baz: tg vg
"#]],
);
}
Expand All @@ -193,8 +193,8 @@ use self::Foo::*;
"#,
expect![[r#"
crate
Bar: t v
Baz: t v
Bar: tg vg
Baz: tg vg
Foo: t
"#]],
);
Expand All @@ -210,8 +210,8 @@ use self::Foo::{*};
"#,
expect![[r#"
crate
Bar: t v
Baz: t v
Bar: tg vg
Baz: tg vg
Foo: t
"#]],
);
Expand Down Expand Up @@ -359,7 +359,7 @@ use event::Event;
event: t
crate::event
Event: t v
Event: t vg
serenity: t
crate::event::serenity
Expand Down Expand Up @@ -388,10 +388,10 @@ use reexport::*;
"#,
expect![[r#"
crate
Trait: t
Trait: tg
defs: t
function: v
makro: m
function: vg
makro: mg
reexport: t
crate::defs
Expand All @@ -400,10 +400,10 @@ use reexport::*;
makro: m
crate::reexport
Trait: t
function: v
Trait: tg
function: vg
inner: t
makro: m
makro: mg
crate::reexport::inner
Trait: ti
Expand Down Expand Up @@ -442,12 +442,12 @@ mod glob_target {
ShouldBePrivate: t v
crate::outer
ShouldBePrivate: t v
ShouldBePrivate: tg vg
inner_superglob: t
crate::outer::inner_superglob
ShouldBePrivate: t v
inner_superglob: t
ShouldBePrivate: tg vg
inner_superglob: tg
"#]],
);
}
Expand All @@ -473,20 +473,20 @@ use reexport_2::*;
"#,
expect![[r#"
crate
Placeholder: t v
Placeholder: tg vg
libs: t
reexport_1: t
reexport_1: tg
reexport_2: t
crate::libs
Placeholder: t v
crate::reexport_2
Placeholder: t v
Placeholder: tg vg
reexport_1: t
crate::reexport_2::reexport_1
Placeholder: t v
Placeholder: tg vg
"#]],
);
}
26 changes: 13 additions & 13 deletions crates/hir-def/src/nameres/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ macro_rules! structs {
bar: t
crate::bar
Bar: t
Foo: t
bar: t
Bar: tg
Foo: tg
bar: tg
"#]],
);
}
Expand Down Expand Up @@ -130,9 +130,9 @@ macro_rules! structs {
bar: t
crate::bar
Bar: t
Foo: t
bar: t
Bar: tg
Foo: tg
bar: tg
"#]],
);
}
Expand Down Expand Up @@ -169,9 +169,9 @@ macro_rules! inner {
bar: t
crate::bar
Bar: t
Foo: t
bar: t
Bar: tg
Foo: tg
bar: tg
"#]],
);
}
Expand Down Expand Up @@ -794,7 +794,7 @@ pub trait Clone {}
"#,
expect![[r#"
crate
Clone: t m
Clone: tg mg
"#]],
);
}
Expand Down Expand Up @@ -1075,9 +1075,9 @@ macro_rules! mbe {
"#,
expect![[r#"
crate
DummyTrait: m
attribute_macro: m
function_like_macro: m
DummyTrait: mg
attribute_macro: mg
function_like_macro: mg
"#]],
);
}
Expand Down
Loading

0 comments on commit 3b88a2f

Please sign in to comment.