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
|
@ -39,6 +39,7 @@ macro_rules! arena_types {
|
|||
[] param: rustc_hir::Param<'tcx>,
|
||||
[] pat: rustc_hir::Pat<'tcx>,
|
||||
[] path: rustc_hir::Path<'tcx>,
|
||||
[] use_path: rustc_hir::UsePath<'tcx>,
|
||||
[] path_segment: rustc_hir::PathSegment<'tcx>,
|
||||
[] poly_trait_ref: rustc_hir::PolyTraitRef<'tcx>,
|
||||
[] qpath: rustc_hir::QPath<'tcx>,
|
||||
|
|
|
@ -183,14 +183,17 @@ impl Lifetime {
|
|||
/// `std::cmp::PartialEq`. It's represented as a sequence of identifiers,
|
||||
/// along with a bunch of supporting information.
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct Path<'hir> {
|
||||
pub struct Path<'hir, R = Res> {
|
||||
pub span: Span,
|
||||
/// The resolution for the path.
|
||||
pub res: Res,
|
||||
pub res: R,
|
||||
/// The segments in the path: the things separated by `::`.
|
||||
pub segments: &'hir [PathSegment<'hir>],
|
||||
}
|
||||
|
||||
/// Up to three resolutions for type, value and macro namespaces.
|
||||
pub type UsePath<'hir> = Path<'hir, SmallVec<[Res; 3]>>;
|
||||
|
||||
impl Path<'_> {
|
||||
pub fn is_global(&self) -> bool {
|
||||
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
|
||||
|
@ -3068,7 +3071,7 @@ pub enum ItemKind<'hir> {
|
|||
/// or just
|
||||
///
|
||||
/// `use foo::bar::baz;` (with `as baz` implicitly on the right).
|
||||
Use(&'hir Path<'hir>, UseKind),
|
||||
Use(&'hir UsePath<'hir>, UseKind),
|
||||
|
||||
/// A `static` item.
|
||||
Static(&'hir Ty<'hir>, Mutability, BodyId),
|
||||
|
|
|
@ -367,7 +367,7 @@ pub trait Visitor<'v>: Sized {
|
|||
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, _: Span, id: HirId) {
|
||||
walk_fn(self, fk, fd, b, id)
|
||||
}
|
||||
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
|
||||
fn visit_use(&mut self, path: &'v UsePath<'v>, hir_id: HirId) {
|
||||
walk_use(self, path, hir_id)
|
||||
}
|
||||
fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) {
|
||||
|
@ -938,9 +938,12 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
|
||||
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v UsePath<'v>, hir_id: HirId) {
|
||||
visitor.visit_id(hir_id);
|
||||
visitor.visit_path(path, hir_id);
|
||||
let UsePath { segments, ref res, span } = *path;
|
||||
for &res in res {
|
||||
visitor.visit_path(&Path { segments, res, span }, hir_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue