rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
This commit is contained in:
parent
1f259ae679
commit
b32a4edb20
25 changed files with 79 additions and 198 deletions
|
@ -2517,10 +2517,7 @@ pub struct Variant {
|
|||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub enum UseTreeKind {
|
||||
/// `use prefix` or `use prefix as rename`
|
||||
///
|
||||
/// The extra `NodeId`s are for HIR lowering, when additional statements are created for each
|
||||
/// namespace.
|
||||
Simple(Option<Ident>, NodeId, NodeId),
|
||||
Simple(Option<Ident>),
|
||||
/// `use prefix::{...}`
|
||||
Nested(Vec<(UseTree, NodeId)>),
|
||||
/// `use prefix::*`
|
||||
|
@ -2539,8 +2536,8 @@ pub struct UseTree {
|
|||
impl UseTree {
|
||||
pub fn ident(&self) -> Ident {
|
||||
match self.kind {
|
||||
UseTreeKind::Simple(Some(rename), ..) => rename,
|
||||
UseTreeKind::Simple(None, ..) => {
|
||||
UseTreeKind::Simple(Some(rename)) => rename,
|
||||
UseTreeKind::Simple(None) => {
|
||||
self.prefix.segments.last().expect("empty prefix in a simple import").ident
|
||||
}
|
||||
_ => panic!("`UseTree::ident` can only be used on a simple import"),
|
||||
|
|
|
@ -410,11 +410,7 @@ pub fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
|
|||
let UseTree { prefix, kind, span } = use_tree;
|
||||
vis.visit_path(prefix);
|
||||
match kind {
|
||||
UseTreeKind::Simple(rename, id1, id2) => {
|
||||
visit_opt(rename, |rename| vis.visit_ident(rename));
|
||||
vis.visit_id(id1);
|
||||
vis.visit_id(id2);
|
||||
}
|
||||
UseTreeKind::Simple(rename) => visit_opt(rename, |rename| vis.visit_ident(rename)),
|
||||
UseTreeKind::Nested(items) => {
|
||||
for (tree, id) in items {
|
||||
vis.visit_use_tree(tree);
|
||||
|
|
|
@ -439,7 +439,7 @@ pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
|
|||
pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) {
|
||||
visitor.visit_path(&use_tree.prefix, id);
|
||||
match &use_tree.kind {
|
||||
UseTreeKind::Simple(rename, ..) => {
|
||||
UseTreeKind::Simple(rename) => {
|
||||
// The extra IDs are handled during HIR lowering.
|
||||
if let &Some(rename) = rename {
|
||||
visitor.visit_ident(rename);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue