use std::io;
use std::result::Result::Err;
-use crate::ty::TyCtxt;
+use crate::ty::query::Providers;
pub mod blocks;
mod collector;
}
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,
pub fn ty_param_name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
- Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => keywords::SelfUpper.name(),
+ Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper,
Node::GenericParam(param) => param.name.ident().name,
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
}
})
}
- 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);
}
}
+ /// 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,
}
}
- /// Returns the name associated with the given NodeId's AST.
+ /// Returns the name associated with the given `NodeId`'s AST.
pub fn name(&self, id: NodeId) -> Name {
let hir_id = self.node_to_hir_id(id);
self.name_by_hir_id(hir_id)
}
}
-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)
+ }
+ };
}