]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/map/mod.rs
rustc: async fn drop order lowering in HIR
[rust.git] / src / librustc / hir / map / mod.rs
index e5ca97b82ab4826f5533a35eddea2469d4a8c040..2d3de5af9927fe76786ce01b712be051a5135771 100644 (file)
@@ -26,7 +26,7 @@
 
 use std::io;
 use std::result::Result::Err;
-use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
 
 pub mod blocks;
 mod collector;
@@ -337,17 +337,17 @@ fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
             }
             Node::TraitItem(item) => {
                 match item.node {
-                    TraitItemKind::Const(..) => DefKind::AssociatedConst,
+                    TraitItemKind::Const(..) => DefKind::AssocConst,
                     TraitItemKind::Method(..) => DefKind::Method,
-                    TraitItemKind::Type(..) => DefKind::AssociatedTy,
+                    TraitItemKind::Type(..) => DefKind::AssocTy,
                 }
             }
             Node::ImplItem(item) => {
                 match item.node {
-                    ImplItemKind::Const(..) => DefKind::AssociatedConst,
+                    ImplItemKind::Const(..) => DefKind::AssocConst,
                     ImplItemKind::Method(..) => DefKind::Method,
-                    ImplItemKind::Type(..) => DefKind::AssociatedTy,
-                    ImplItemKind::Existential(..) => DefKind::AssociatedExistential,
+                    ImplItemKind::Type(..) => DefKind::AssocTy,
+                    ImplItemKind::Existential(..) => DefKind::AssocExistential,
                 }
             }
             Node::Variant(_) => DefKind::Variant,
@@ -373,6 +373,7 @@ fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
             Node::Pat(_) |
             Node::Binding(_) |
             Node::Local(_) |
+            Node::Arm(_) |
             Node::Lifetime(_) |
             Node::Visibility(_) |
             Node::Block(_) |
@@ -627,10 +628,6 @@ pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
         })
     }
 
-    pub fn get_generics_span(&self, id: DefId) -> Option<Span> {
-        self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP)
-    }
-
     /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
     pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
         let hir_id = self.node_to_hir_id(id);
@@ -702,6 +699,19 @@ pub fn is_argument(&self, id: NodeId) -> bool {
         }
     }
 
+    /// Returns the `HirId` of this pattern, or, if this is an `async fn` desugaring, the `HirId`
+    /// of the original pattern that the user wrote.
+    pub fn original_pat_of_argument(&self, arg: &'hir Arg) -> &'hir Pat {
+        match &arg.source {
+            ArgSource::Normal => &*arg.pat,
+            ArgSource::AsyncFn(hir_id) => match self.find_by_hir_id(*hir_id) {
+                Some(Node::Pat(pat)) | Some(Node::Binding(pat)) => &pat,
+                Some(Node::Local(local)) => &*local.pat,
+                x => bug!("ArgSource::AsyncFn HirId not a pattern/binding/local: {:?}", x),
+            },
+        }
+    }
+
     pub fn is_const_scope(&self, hir_id: HirId) -> bool {
         self.walk_parent_nodes(hir_id, |node| match *node {
             Node::Item(Item { node: ItemKind::Const(_, _), .. }) => true,
@@ -1000,6 +1010,7 @@ pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] {
             Some(Node::Field(ref f)) => Some(&f.attrs[..]),
             Some(Node::Expr(ref e)) => Some(&*e.attrs),
             Some(Node::Stmt(ref s)) => Some(s.node.attrs()),
+            Some(Node::Arm(ref a)) => Some(&*a.attrs),
             Some(Node::GenericParam(param)) => Some(&param.attrs[..]),
             // Unit/tuple structs/variants take the attributes straight from
             // the struct/variant definition.
@@ -1073,6 +1084,7 @@ pub fn span_by_hir_id(&self, hir_id: HirId) -> Span {
             Some(Node::TraitRef(tr)) => tr.path.span,
             Some(Node::Binding(pat)) => pat.span,
             Some(Node::Pat(pat)) => pat.span,
+            Some(Node::Arm(arm)) => arm.span,
             Some(Node::Block(block)) => block.span,
             Some(Node::Ctor(..)) => match self.find_by_hir_id(
                 self.get_parent_node_by_hir_id(hir_id))
@@ -1288,6 +1300,7 @@ pub fn print_node(&mut self, node: Node<'_>) -> io::Result<()> {
             Node::TraitRef(a)     => self.print_trait_ref(&a),
             Node::Binding(a)      |
             Node::Pat(a)          => self.print_pat(&a),
+            Node::Arm(a)          => self.print_arm(&a),
             Node::Block(a)        => {
                 use syntax::print::pprust::PrintState;
 
@@ -1417,6 +1430,9 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
         Some(Node::Pat(_)) => {
             format!("pat {}{}", map.hir_to_pretty_string(id), id_str)
         }
+        Some(Node::Arm(_)) => {
+            format!("arm {}{}", map.hir_to_pretty_string(id), id_str)
+        }
         Some(Node::Block(_)) => {
             format!("block {}{}", map.hir_to_pretty_string(id), id_str)
         }
@@ -1443,11 +1459,13 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
     }
 }
 
-pub fn def_kind(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option<DefKind> {
-    if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
-        tcx.hir().def_kind(node_id)
-    } else {
-        bug!("Calling local def_kind query provider for upstream DefId: {:?}",
-             def_id)
-    }
+pub fn provide(providers: &mut Providers<'_>) {
+    providers.def_kind = |tcx, def_id| {
+        if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
+            tcx.hir().def_kind(node_id)
+        } else {
+            bug!("Calling local def_kind query provider for upstream DefId: {:?}",
+                def_id)
+        }
+    };
 }