rustc_hir: Change representation of import paths to support multiple resolutions
This commit is contained in:
parent
6cd4dd3091
commit
1f259ae679
19 changed files with 136 additions and 114 deletions
|
@ -508,7 +508,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let mut resolutions = self.expect_full_res_from_use(id).fuse();
|
||||
// We want to return *something* from this function, so hold onto the first item
|
||||
// for later.
|
||||
let ret_res = self.lower_res(resolutions.next().unwrap_or(Res::Err));
|
||||
let ret_res = smallvec![self.lower_res(resolutions.next().unwrap_or(Res::Err))];
|
||||
|
||||
// Here, we are looping over namespaces, if they exist for the definition
|
||||
// being imported. We only handle type and value namespaces because we
|
||||
|
@ -538,8 +538,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let span = path.span;
|
||||
|
||||
self.with_hir_id_owner(new_node_id, |this| {
|
||||
let res = this.lower_res(res);
|
||||
let path = this.lower_path_extra(res, &path, ParamMode::Explicit);
|
||||
let res = smallvec![this.lower_res(res)];
|
||||
let path = this.lower_use_path(res, &path, ParamMode::Explicit);
|
||||
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
|
||||
if let Some(attrs) = attrs {
|
||||
this.attrs.insert(hir::ItemLocalId::new(0), attrs);
|
||||
|
@ -556,15 +556,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
});
|
||||
}
|
||||
|
||||
let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit);
|
||||
let path = self.lower_use_path(ret_res, &path, ParamMode::Explicit);
|
||||
hir::ItemKind::Use(path, hir::UseKind::Single)
|
||||
}
|
||||
UseTreeKind::Glob => {
|
||||
let path = self.lower_path(
|
||||
id,
|
||||
&Path { segments, span: path.span, tokens: None },
|
||||
ParamMode::Explicit,
|
||||
);
|
||||
let res = self.expect_full_res(id);
|
||||
let res = smallvec![self.lower_res(res)];
|
||||
let path = Path { segments, span: path.span, tokens: None };
|
||||
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
|
||||
hir::ItemKind::Use(path, hir::UseKind::Glob)
|
||||
}
|
||||
UseTreeKind::Nested(ref trees) => {
|
||||
|
@ -635,8 +634,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
|
||||
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
|
||||
let res = self.lower_res(res);
|
||||
let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit);
|
||||
let res = smallvec![self.lower_res(res)];
|
||||
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
|
||||
hir::ItemKind::Use(path, hir::UseKind::ListStem)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_hir::GenericArg;
|
|||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::{BytePos, Span, DUMMY_SP};
|
||||
|
||||
use smallvec::smallvec;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
|
@ -144,13 +144,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
);
|
||||
}
|
||||
|
||||
pub(crate) fn lower_path_extra(
|
||||
pub(crate) fn lower_use_path(
|
||||
&mut self,
|
||||
res: Res,
|
||||
res: SmallVec<[Res; 3]>,
|
||||
p: &Path,
|
||||
param_mode: ParamMode,
|
||||
) -> &'hir hir::Path<'hir> {
|
||||
self.arena.alloc(hir::Path {
|
||||
) -> &'hir hir::UsePath<'hir> {
|
||||
self.arena.alloc(hir::UsePath {
|
||||
res,
|
||||
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
|
||||
self.lower_path_segment(
|
||||
|
@ -165,17 +165,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn lower_path(
|
||||
&mut self,
|
||||
id: NodeId,
|
||||
p: &Path,
|
||||
param_mode: ParamMode,
|
||||
) -> &'hir hir::Path<'hir> {
|
||||
let res = self.expect_full_res(id);
|
||||
let res = self.lower_res(res);
|
||||
self.lower_path_extra(res, p, param_mode)
|
||||
}
|
||||
|
||||
pub(crate) fn lower_path_segment(
|
||||
&mut self,
|
||||
path_span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue