Skip to content

Commit 44f4510

Browse files
author
Jonas Schievink
committed
Store Import indices for later reconstruction
1 parent b14bf68 commit 44f4510

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

crates/hir_def/src/item_tree.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ pub enum AttrOwner {
291291

292292
Variant(Idx<Variant>),
293293
Field(Idx<Field>),
294-
// FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`.
295294
}
296295

297296
macro_rules! from_attrs {
@@ -483,6 +482,11 @@ pub struct Import {
483482
/// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
484483
/// `Import`s can map to the same `use` item.
485484
pub ast_id: FileAstId<ast::Use>,
485+
/// Index of this `Import` when the containing `Use` is visited via `ModPath::expand_use_item`.
486+
///
487+
/// This can be used to get the `UseTree` this `Import` corresponds to and allows emitting
488+
/// precise diagnostics.
489+
pub index: usize,
486490
}
487491

488492
#[derive(Debug, Clone, Eq, PartialEq)]

crates/hir_def/src/item_tree/lower.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,15 @@ impl Ctx {
482482
ModPath::expand_use_item(
483483
InFile::new(self.file, use_item.clone()),
484484
&self.hygiene,
485-
|path, _tree, is_glob, alias| {
485+
|path, _use_tree, is_glob, alias| {
486486
imports.push(id(tree.imports.alloc(Import {
487487
path,
488488
alias,
489489
visibility,
490490
is_glob,
491491
is_prelude,
492492
ast_id,
493+
index: imports.len(),
493494
})));
494495
},
495496
);

crates/hir_def/src/item_tree/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ fn smoke() {
228228
229229
top-level items:
230230
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
231-
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
231+
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0), index: 0 }
232232
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
233-
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0) }
233+
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<syntax::ast::generated::nodes::Use>(0), index: 1 }
234234
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
235235
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<syntax::ast::generated::nodes::ExternCrate>(1) }
236236
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]

0 commit comments

Comments
 (0)