-use hir::map::DefPathData;
-use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
-use ty::{self, DefIdTree, Ty, TyCtxt};
-use middle::cstore::{ExternCrate, ExternCrateSource};
+use crate::hir::map::DefPathData;
+use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
+use crate::ty::{self, DefIdTree, Ty, TyCtxt};
+use crate::middle::cstore::{ExternCrate, ExternCrateSource};
use syntax::ast;
use syntax::symbol::{keywords, LocalInternedString, Symbol};
})
}
-/// Add the `crate::` prefix to paths where appropriate.
+/// Adds the `crate::` prefix to paths where appropriate.
pub fn with_crate_prefix<F: FnOnce() -> R, R>(f: F) -> R {
SHOULD_PREFIX_WITH_CRATE.with(|flag| {
let old = flag.get();
}
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
- /// Returns a string identifying this def-id. This string is
+ /// Returns a string identifying this `DefId`. This string is
/// suitable for user output. It is relative to the current crate
/// root, unless with_forced_absolute_paths was used.
pub fn item_path_str(self, def_id: DefId) -> String {
let visible_parent = visible_parent_map.get(&cur_def).cloned();
let actual_parent = self.parent(cur_def);
- debug!(
- "try_push_visible_item_path: visible_parent={:?} actual_parent={:?}",
- visible_parent, actual_parent,
- );
let data = cur_def_key.disambiguated_data.data;
+ debug!(
+ "try_push_visible_item_path: data={:?} visible_parent={:?} actual_parent={:?}",
+ data, visible_parent, actual_parent,
+ );
let symbol = match data {
// In order to output a path that could actually be imported (valid and visible),
// we need to handle re-exports correctly.
// the children of the visible parent (as was done when computing
// `visible_parent_map`), looking for the specific child we currently have and then
// have access to the re-exported name.
- DefPathData::Module(module_name) if visible_parent != actual_parent => {
- let mut name: Option<ast::Ident> = None;
- if let Some(visible_parent) = visible_parent {
- for child in self.item_children(visible_parent).iter() {
- if child.def.def_id() == cur_def {
- name = Some(child.ident);
- }
- }
- }
- name.map(|n| n.as_str()).unwrap_or(module_name.as_str())
+ DefPathData::Module(actual_name) |
+ DefPathData::TypeNs(actual_name) if visible_parent != actual_parent => {
+ visible_parent
+ .and_then(|parent| {
+ self.item_children(parent)
+ .iter()
+ .find(|child| child.def.def_id() == cur_def)
+ .map(|child| child.ident.as_str())
+ })
+ .unwrap_or_else(|| actual_name.as_str())
},
_ => {
data.get_opt_name().map(|n| n.as_str()).unwrap_or_else(|| {
data @ DefPathData::Misc |
data @ DefPathData::TypeNs(..) |
data @ DefPathData::Trait(..) |
+ data @ DefPathData::TraitAlias(..) |
data @ DefPathData::AssocTypeInTrait(..) |
data @ DefPathData::AssocTypeInImpl(..) |
data @ DefPathData::AssocExistentialInImpl(..) |
data @ DefPathData::Module(..) |
data @ DefPathData::TypeParam(..) |
data @ DefPathData::LifetimeParam(..) |
+ data @ DefPathData::ConstParam(..) |
data @ DefPathData::EnumVariant(..) |
data @ DefPathData::Field(..) |
data @ DefPathData::AnonConst |
// only occur very early in the compiler pipeline.
let parent_def_id = self.parent_def_id(impl_def_id).unwrap();
self.push_item_path(buffer, parent_def_id, pushed_prelude_crate);
- let node_id = self.hir().as_local_node_id(impl_def_id).unwrap();
- let item = self.hir().expect_item(node_id);
+ let hir_id = self.hir().as_local_hir_id(impl_def_id).unwrap();
+ let item = self.hir().expect_item_by_hir_id(hir_id);
let span_str = self.sess.source_map().span_to_string(item.span);
buffer.push(&format!("<impl at {}>", span_str));
}
- /// Returns the def-id of `def_id`'s parent in the def tree. If
+ /// Returns the `DefId` of `def_id`'s parent in the def tree. If
/// this returns `None`, then `def_id` represents a crate root or
/// inlined root.
pub fn parent_def_id(self, def_id: DefId) -> Option<DefId> {
}
/// As a heuristic, when we see an impl, if we see that the
-/// 'self-type' is a type defined in the same module as the impl,
+/// 'self type' is a type defined in the same module as the impl,
/// we can omit including the path to the impl itself. This
-/// function tries to find a "characteristic def-id" for a
+/// function tries to find a "characteristic `DefId`" for a
/// type. It's just a heuristic so it makes some questionable
/// decisions and we may want to adjust it later.
pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
#[derive(Debug)]
pub enum RootMode {
- /// Try to make a path relative to the local crate. In
+ /// Try to make a path relative to the local crate. In
/// particular, local paths have no prefix, and if the path comes
/// from an extern crate, start with the path to the `extern
/// crate` declaration.