hir: Stop keeping prefixes for most of use
list stems
And make sure all other imports have non-empty resolution lists.
This commit is contained in:
parent
bf3c6c5bed
commit
f5d6eb30a8
3 changed files with 23 additions and 9 deletions
|
@ -496,8 +496,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let res =
|
let res = self.lower_import_res(id, path.span);
|
||||||
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
|
|
||||||
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
|
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
|
||||||
hir::ItemKind::Use(path, hir::UseKind::Single)
|
hir::ItemKind::Use(path, hir::UseKind::Single)
|
||||||
}
|
}
|
||||||
|
@ -533,7 +532,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
// for that we return the `{}` import (called the
|
// for that we return the `{}` import (called the
|
||||||
// `ListStem`).
|
// `ListStem`).
|
||||||
|
|
||||||
let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
|
let span = prefix.span.to(path.span);
|
||||||
|
let prefix = Path { segments, span, tokens: None };
|
||||||
|
|
||||||
// Add all the nested `PathListItem`s to the HIR.
|
// Add all the nested `PathListItem`s to the HIR.
|
||||||
for &(ref use_tree, id) in trees {
|
for &(ref use_tree, id) in trees {
|
||||||
|
@ -567,9 +567,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let res =
|
let path = if trees.is_empty() && !prefix.segments.is_empty() {
|
||||||
self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
|
// For empty lists we need to lower the prefix so it is checked for things
|
||||||
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
|
// like stability later.
|
||||||
|
let res = self.lower_import_res(id, span);
|
||||||
|
self.lower_use_path(res, &prefix, ParamMode::Explicit)
|
||||||
|
} else {
|
||||||
|
// For non-empty lists we can just drop all the data, the prefix is already
|
||||||
|
// present in HIR as a part of nested imports.
|
||||||
|
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
|
||||||
|
};
|
||||||
hir::ItemKind::Use(path, hir::UseKind::ListStem)
|
hir::ItemKind::Use(path, hir::UseKind::ListStem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||||
use rustc_session::parse::{add_feature_diagnostics, feature_err};
|
use rustc_session::parse::{add_feature_diagnostics, feature_err};
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
|
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
|
||||||
use smallvec::SmallVec;
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
|
@ -749,8 +749,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
|
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
|
fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
|
||||||
self.resolver.get_import_res(id).present_items()
|
let res = self.resolver.get_import_res(id).present_items();
|
||||||
|
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
|
||||||
|
if res.is_empty() {
|
||||||
|
self.dcx().span_delayed_bug(span, "no resolution for an import");
|
||||||
|
return smallvec![Res::Err];
|
||||||
|
}
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
|
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
|
||||||
|
|
|
@ -156,6 +156,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
p: &Path,
|
p: &Path,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
) -> &'hir hir::UsePath<'hir> {
|
) -> &'hir hir::UsePath<'hir> {
|
||||||
|
assert!((1..=3).contains(&res.len()));
|
||||||
self.arena.alloc(hir::UsePath {
|
self.arena.alloc(hir::UsePath {
|
||||||
res,
|
res,
|
||||||
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
|
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue