Store Import indices for later reconstruction

This commit is contained in:
Jonas Schievink 2020-09-16 12:35:09 +02:00
parent b14bf68ce6
commit 44f4510caa
3 changed files with 9 additions and 4 deletions

View file

@ -291,7 +291,6 @@ pub enum AttrOwner {
Variant(Idx<Variant>),
Field(Idx<Field>),
// FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`.
}
macro_rules! from_attrs {
@ -483,6 +482,11 @@ pub struct Import {
/// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
/// `Import`s can map to the same `use` item.
pub ast_id: FileAstId<ast::Use>,
/// Index of this `Import` when the containing `Use` is visited via `ModPath::expand_use_item`.
///
/// This can be used to get the `UseTree` this `Import` corresponds to and allows emitting
/// precise diagnostics.
pub index: usize,
}
#[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -482,7 +482,7 @@ impl Ctx {
ModPath::expand_use_item(
InFile::new(self.file, use_item.clone()),
&self.hygiene,
|path, _tree, is_glob, alias| {
|path, _use_tree, is_glob, alias| {
imports.push(id(tree.imports.alloc(Import {
path,
alias,
@ -490,6 +490,7 @@ impl Ctx {
is_glob,
is_prelude,
ast_id,
index: imports.len(),
})));
},
);

View file

@ -228,9 +228,9 @@ fn smoke() {
top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
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) }
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 }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
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) }
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 }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
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) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]