2015-09-17 13:29:59 -05:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-12-14 10:27:39 -06:00
|
|
|
//! For each definition, we track the following data. A definition
|
|
|
|
//! here is defined somewhat circularly as "something with a def-id",
|
|
|
|
//! but it generally corresponds to things like structs, enums, etc.
|
|
|
|
//! There are also some rather random cases (like const initializer
|
|
|
|
//! expressions) that are mostly just leftovers.
|
|
|
|
|
2016-08-31 06:00:29 -05:00
|
|
|
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
|
2016-11-07 21:02:55 -06:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2016-12-13 17:45:03 -06:00
|
|
|
use rustc_data_structures::stable_hasher::StableHasher;
|
2016-12-14 10:27:39 -06:00
|
|
|
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
2016-08-01 18:55:20 -05:00
|
|
|
use std::fmt::Write;
|
2016-09-28 19:23:36 -05:00
|
|
|
use std::hash::{Hash, Hasher};
|
2016-09-14 04:55:20 -05:00
|
|
|
use syntax::ast;
|
2016-11-16 02:21:52 -06:00
|
|
|
use syntax::symbol::{Symbol, InternedString};
|
2016-08-01 18:55:20 -05:00
|
|
|
use ty::TyCtxt;
|
2015-09-17 13:29:59 -05:00
|
|
|
use util::nodemap::NodeMap;
|
|
|
|
|
2016-12-16 18:12:37 -06:00
|
|
|
/// The DefPathTable maps DefIndexes to DefKeys and vice versa.
|
|
|
|
/// Internally the DefPathTable holds a tree of DefKeys, where each DefKey
|
|
|
|
/// stores the DefIndex of its parent.
|
|
|
|
/// There is one DefPathTable for each crate.
|
2016-12-14 10:27:39 -06:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DefPathTable {
|
|
|
|
index_to_key: Vec<DefKey>,
|
|
|
|
key_to_index: FxHashMap<DefKey, DefIndex>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DefPathTable {
|
|
|
|
fn insert(&mut self, key: DefKey) -> DefIndex {
|
|
|
|
let index = DefIndex::new(self.index_to_key.len());
|
|
|
|
debug!("DefPathTable::insert() - {:?} <-> {:?}", key, index);
|
|
|
|
self.index_to_key.push(key.clone());
|
|
|
|
self.key_to_index.insert(key, index);
|
|
|
|
index
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn def_key(&self, index: DefIndex) -> DefKey {
|
|
|
|
self.index_to_key[index.as_usize()].clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn def_index_for_def_key(&self, key: &DefKey) -> Option<DefIndex> {
|
|
|
|
self.key_to_index.get(key).cloned()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn contains_key(&self, key: &DefKey) -> bool {
|
|
|
|
self.key_to_index.contains_key(key)
|
|
|
|
}
|
2016-12-16 16:24:27 -06:00
|
|
|
|
|
|
|
pub fn retrace_path(&self,
|
|
|
|
path_data: &[DisambiguatedDefPathData])
|
|
|
|
-> Option<DefIndex> {
|
|
|
|
let root_key = DefKey {
|
|
|
|
parent: None,
|
|
|
|
disambiguated_data: DisambiguatedDefPathData {
|
|
|
|
data: DefPathData::CrateRoot,
|
|
|
|
disambiguator: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let root_index = self.key_to_index
|
|
|
|
.get(&root_key)
|
|
|
|
.expect("no root key?")
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
debug!("retrace_path: root_index={:?}", root_index);
|
|
|
|
|
|
|
|
let mut index = root_index;
|
|
|
|
for data in path_data {
|
|
|
|
let key = DefKey { parent: Some(index), disambiguated_data: data.clone() };
|
|
|
|
debug!("retrace_path: key={:?}", key);
|
|
|
|
match self.key_to_index.get(&key) {
|
|
|
|
Some(&i) => index = i,
|
|
|
|
None => return None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(index)
|
|
|
|
}
|
2016-12-14 10:27:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Encodable for DefPathTable {
|
|
|
|
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
|
|
|
self.index_to_key.encode(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Decodable for DefPathTable {
|
|
|
|
fn decode<D: Decoder>(d: &mut D) -> Result<DefPathTable, D::Error> {
|
|
|
|
let index_to_key: Vec<DefKey> = Decodable::decode(d)?;
|
|
|
|
let key_to_index = index_to_key.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(index, key)| (key.clone(), DefIndex::new(index)))
|
|
|
|
.collect();
|
|
|
|
Ok(DefPathTable {
|
|
|
|
index_to_key: index_to_key,
|
|
|
|
key_to_index: key_to_index,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 16:48:52 -06:00
|
|
|
|
|
|
|
|
2016-12-16 18:12:37 -06:00
|
|
|
/// The definition table containing node definitions.
|
|
|
|
/// It holds the DefPathTable for local DefIds/DefPaths and it also stores a
|
|
|
|
/// mapping from NodeIds to local DefIds.
|
2015-09-17 13:29:59 -05:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Definitions {
|
2016-12-14 10:27:39 -06:00
|
|
|
table: DefPathTable,
|
2016-12-13 16:48:52 -06:00
|
|
|
node_to_def_index: NodeMap<DefIndex>,
|
|
|
|
def_index_to_node: Vec<ast::NodeId>,
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A unique identifier that we can use to lookup a definition
|
|
|
|
/// precisely. It combines the index of the definition's parent (if
|
|
|
|
/// any) with a `DisambiguatedDefPathData`.
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct DefKey {
|
|
|
|
/// Parent path.
|
|
|
|
pub parent: Option<DefIndex>,
|
|
|
|
|
|
|
|
/// Identifier of this node.
|
|
|
|
pub disambiguated_data: DisambiguatedDefPathData,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pair of `DefPathData` and an integer disambiguator. The integer is
|
|
|
|
/// normally 0, but in the event that there are multiple defs with the
|
|
|
|
/// same `parent` and `data`, we use this field to disambiguate
|
|
|
|
/// between them. This introduces some artificial ordering dependency
|
|
|
|
/// but means that if you have (e.g.) two impls for the same type in
|
|
|
|
/// the same module, they do get distinct def-ids.
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct DisambiguatedDefPathData {
|
|
|
|
pub data: DefPathData,
|
|
|
|
pub disambiguator: u32
|
|
|
|
}
|
|
|
|
|
2016-03-16 04:40:14 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct DefPath {
|
|
|
|
/// the path leading from the crate root to the item
|
|
|
|
pub data: Vec<DisambiguatedDefPathData>,
|
|
|
|
|
|
|
|
/// what krate root is this path relative to?
|
2016-08-31 06:00:29 -05:00
|
|
|
pub krate: CrateNum,
|
2016-03-16 04:40:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DefPath {
|
|
|
|
pub fn is_local(&self) -> bool {
|
|
|
|
self.krate == LOCAL_CRATE
|
|
|
|
}
|
|
|
|
|
2016-12-16 11:48:54 -06:00
|
|
|
pub fn make<FN>(krate: CrateNum,
|
2016-03-16 04:40:14 -05:00
|
|
|
start_index: DefIndex,
|
|
|
|
mut get_key: FN) -> DefPath
|
|
|
|
where FN: FnMut(DefIndex) -> DefKey
|
|
|
|
{
|
|
|
|
let mut data = vec![];
|
|
|
|
let mut index = Some(start_index);
|
|
|
|
loop {
|
2016-05-06 13:52:57 -05:00
|
|
|
debug!("DefPath::make: krate={:?} index={:?}", krate, index);
|
2016-03-16 04:40:14 -05:00
|
|
|
let p = index.unwrap();
|
|
|
|
let key = get_key(p);
|
2016-05-06 13:52:57 -05:00
|
|
|
debug!("DefPath::make: key={:?}", key);
|
2016-03-16 04:40:14 -05:00
|
|
|
match key.disambiguated_data.data {
|
|
|
|
DefPathData::CrateRoot => {
|
|
|
|
assert!(key.parent.is_none());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
data.push(key.disambiguated_data);
|
|
|
|
index = key.parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.reverse();
|
|
|
|
DefPath { data: data, krate: krate }
|
|
|
|
}
|
2016-08-01 18:55:20 -05:00
|
|
|
|
|
|
|
pub fn to_string(&self, tcx: TyCtxt) -> String {
|
|
|
|
let mut s = String::with_capacity(self.data.len() * 16);
|
|
|
|
|
2016-11-16 04:52:37 -06:00
|
|
|
s.push_str(&tcx.original_crate_name(self.krate).as_str());
|
2016-08-01 18:55:20 -05:00
|
|
|
s.push_str("/");
|
2016-11-16 04:52:37 -06:00
|
|
|
s.push_str(&tcx.crate_disambiguator(self.krate).as_str());
|
2016-08-01 18:55:20 -05:00
|
|
|
|
|
|
|
for component in &self.data {
|
|
|
|
write!(s,
|
|
|
|
"::{}[{}]",
|
|
|
|
component.data.as_interned_str(),
|
|
|
|
component.disambiguator)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
2016-08-05 19:12:20 -05:00
|
|
|
|
|
|
|
pub fn deterministic_hash(&self, tcx: TyCtxt) -> u64 {
|
2016-12-13 17:45:03 -06:00
|
|
|
debug!("deterministic_hash({:?})", self);
|
|
|
|
let mut state = StableHasher::new();
|
2016-08-05 19:12:20 -05:00
|
|
|
self.deterministic_hash_to(tcx, &mut state);
|
|
|
|
state.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deterministic_hash_to<H: Hasher>(&self, tcx: TyCtxt, state: &mut H) {
|
2016-11-16 04:52:37 -06:00
|
|
|
tcx.original_crate_name(self.krate).as_str().hash(state);
|
|
|
|
tcx.crate_disambiguator(self.krate).as_str().hash(state);
|
2016-08-05 19:12:20 -05:00
|
|
|
self.data.hash(state);
|
|
|
|
}
|
2016-03-16 04:40:14 -05:00
|
|
|
}
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum DefPathData {
|
|
|
|
// Root: these should only be used for the root nodes, because
|
|
|
|
// they are treated specially by the `def_path` function.
|
2015-12-21 15:24:15 -06:00
|
|
|
/// The crate root (marker)
|
2015-09-17 13:29:59 -05:00
|
|
|
CrateRoot,
|
2016-12-16 11:51:36 -06:00
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
// Catch-all for random DefId things like DUMMY_NODE_ID
|
|
|
|
Misc,
|
|
|
|
|
|
|
|
// Different kinds of items and item-like things:
|
2015-12-21 15:24:15 -06:00
|
|
|
/// An impl
|
2016-03-16 04:47:18 -05:00
|
|
|
Impl,
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Something in the type NS
|
2016-08-05 19:10:04 -05:00
|
|
|
TypeNs(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Something in the value NS
|
2016-08-05 19:10:04 -05:00
|
|
|
ValueNs(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A module declaration
|
2016-08-05 19:10:04 -05:00
|
|
|
Module(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A macro rule
|
2016-08-05 19:10:04 -05:00
|
|
|
MacroDef(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A closure expression
|
2015-09-17 13:29:59 -05:00
|
|
|
ClosureExpr,
|
|
|
|
|
|
|
|
// Subportions of items
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A type parameter (generic parameter)
|
2016-08-05 19:10:04 -05:00
|
|
|
TypeParam(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A lifetime definition
|
2016-08-05 19:10:04 -05:00
|
|
|
LifetimeDef(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A variant of a enum
|
2016-08-05 19:10:04 -05:00
|
|
|
EnumVariant(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// A struct field
|
2016-08-05 19:10:04 -05:00
|
|
|
Field(InternedString),
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Implicit ctor for a tuple-like struct
|
|
|
|
StructCtor,
|
|
|
|
/// Initializer for a const
|
|
|
|
Initializer,
|
|
|
|
/// Pattern binding
|
2016-08-05 19:10:04 -05:00
|
|
|
Binding(InternedString),
|
2016-07-22 10:56:22 -05:00
|
|
|
/// An `impl Trait` type node.
|
|
|
|
ImplTrait
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Definitions {
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Create new empty definition map.
|
2015-09-17 13:29:59 -05:00
|
|
|
pub fn new() -> Definitions {
|
|
|
|
Definitions {
|
2016-12-14 10:27:39 -06:00
|
|
|
table: DefPathTable {
|
|
|
|
index_to_key: vec![],
|
|
|
|
key_to_index: FxHashMap(),
|
|
|
|
},
|
2016-12-13 16:48:52 -06:00
|
|
|
node_to_def_index: NodeMap(),
|
|
|
|
def_index_to_node: vec![],
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 11:51:36 -06:00
|
|
|
pub fn def_path_table(&self) -> &DefPathTable {
|
|
|
|
&self.table
|
|
|
|
}
|
|
|
|
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Get the number of definitions.
|
2015-09-17 13:29:59 -05:00
|
|
|
pub fn len(&self) -> usize {
|
2016-12-14 10:27:39 -06:00
|
|
|
self.def_index_to_node.len()
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn def_key(&self, index: DefIndex) -> DefKey {
|
2016-12-14 10:27:39 -06:00
|
|
|
self.table.def_key(index)
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
2016-05-06 13:52:57 -05:00
|
|
|
pub fn def_index_for_def_key(&self, key: DefKey) -> Option<DefIndex> {
|
2016-12-14 10:27:39 -06:00
|
|
|
self.table.def_index_for_def_key(&key)
|
2016-05-06 13:52:57 -05:00
|
|
|
}
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
/// Returns the path from the crate root to `index`. The root
|
|
|
|
/// nodes are not included in the path (i.e., this will be an
|
|
|
|
/// empty vector for the crate root). For an inlined item, this
|
|
|
|
/// will be the path of the item in the external crate (but the
|
|
|
|
/// path will begin with the path to the external crate).
|
|
|
|
pub fn def_path(&self, index: DefIndex) -> DefPath {
|
2016-03-16 04:40:14 -05:00
|
|
|
DefPath::make(LOCAL_CRATE, index, |p| self.def_key(p))
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn opt_def_index(&self, node: ast::NodeId) -> Option<DefIndex> {
|
2016-12-13 16:48:52 -06:00
|
|
|
self.node_to_def_index.get(&node).cloned()
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn opt_local_def_id(&self, node: ast::NodeId) -> Option<DefId> {
|
|
|
|
self.opt_def_index(node).map(DefId::local)
|
|
|
|
}
|
|
|
|
|
2016-04-23 22:26:10 -05:00
|
|
|
pub fn local_def_id(&self, node: ast::NodeId) -> DefId {
|
|
|
|
self.opt_local_def_id(node).unwrap()
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
|
|
|
|
if def_id.krate == LOCAL_CRATE {
|
2016-12-14 10:27:39 -06:00
|
|
|
assert!(def_id.index.as_usize() < self.def_index_to_node.len());
|
2016-12-13 16:48:52 -06:00
|
|
|
Some(self.def_index_to_node[def_id.index.as_usize()])
|
2015-09-17 13:29:59 -05:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 15:24:15 -06:00
|
|
|
/// Add a definition with a parent definition.
|
2015-09-17 13:29:59 -05:00
|
|
|
pub fn create_def_with_parent(&mut self,
|
|
|
|
parent: Option<DefIndex>,
|
|
|
|
node_id: ast::NodeId,
|
|
|
|
data: DefPathData)
|
|
|
|
-> DefIndex {
|
2016-03-28 16:39:57 -05:00
|
|
|
debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})",
|
|
|
|
parent, node_id, data);
|
|
|
|
|
2016-12-13 16:48:52 -06:00
|
|
|
assert!(!self.node_to_def_index.contains_key(&node_id),
|
2015-09-17 13:29:59 -05:00
|
|
|
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
|
|
|
node_id,
|
|
|
|
data,
|
2016-12-14 10:27:39 -06:00
|
|
|
self.table.def_key(self.node_to_def_index[&node_id]));
|
2015-09-17 13:29:59 -05:00
|
|
|
|
2016-12-21 04:32:59 -06:00
|
|
|
assert_eq!(parent.is_some(), data != DefPathData::CrateRoot);
|
2016-03-28 16:39:57 -05:00
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
// Find a unique DefKey. This basically means incrementing the disambiguator
|
|
|
|
// until we get no match.
|
|
|
|
let mut key = DefKey {
|
|
|
|
parent: parent,
|
|
|
|
disambiguated_data: DisambiguatedDefPathData {
|
|
|
|
data: data,
|
|
|
|
disambiguator: 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-14 10:27:39 -06:00
|
|
|
while self.table.contains_key(&key) {
|
2015-09-17 13:29:59 -05:00
|
|
|
key.disambiguated_data.disambiguator += 1;
|
|
|
|
}
|
|
|
|
|
2016-03-28 16:39:57 -05:00
|
|
|
debug!("create_def_with_parent: after disambiguation, key = {:?}", key);
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
// Create the definition.
|
2016-12-14 10:27:39 -06:00
|
|
|
let index = self.table.insert(key);
|
|
|
|
debug!("create_def_with_parent: def_index_to_node[{:?} <-> {:?}", index, node_id);
|
2016-12-13 16:48:52 -06:00
|
|
|
self.node_to_def_index.insert(node_id, index);
|
2016-12-14 10:27:39 -06:00
|
|
|
assert_eq!(index.as_usize(), self.def_index_to_node.len());
|
|
|
|
self.def_index_to_node.push(node_id);
|
2016-03-28 16:39:57 -05:00
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DefPathData {
|
2016-09-17 05:34:55 -05:00
|
|
|
pub fn get_opt_name(&self) -> Option<ast::Name> {
|
|
|
|
use self::DefPathData::*;
|
|
|
|
match *self {
|
|
|
|
TypeNs(ref name) |
|
|
|
|
ValueNs(ref name) |
|
|
|
|
Module(ref name) |
|
|
|
|
MacroDef(ref name) |
|
|
|
|
TypeParam(ref name) |
|
|
|
|
LifetimeDef(ref name) |
|
|
|
|
EnumVariant(ref name) |
|
|
|
|
Binding(ref name) |
|
2016-11-16 02:21:52 -06:00
|
|
|
Field(ref name) => Some(Symbol::intern(name)),
|
2016-09-17 05:34:55 -05:00
|
|
|
|
|
|
|
Impl |
|
|
|
|
CrateRoot |
|
|
|
|
Misc |
|
|
|
|
ClosureExpr |
|
|
|
|
StructCtor |
|
|
|
|
Initializer |
|
|
|
|
ImplTrait => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
pub fn as_interned_str(&self) -> InternedString {
|
|
|
|
use self::DefPathData::*;
|
2016-11-17 08:04:20 -06:00
|
|
|
let s = match *self {
|
2016-08-05 19:10:04 -05:00
|
|
|
TypeNs(ref name) |
|
|
|
|
ValueNs(ref name) |
|
|
|
|
Module(ref name) |
|
|
|
|
MacroDef(ref name) |
|
|
|
|
TypeParam(ref name) |
|
|
|
|
LifetimeDef(ref name) |
|
|
|
|
EnumVariant(ref name) |
|
|
|
|
Binding(ref name) |
|
|
|
|
Field(ref name) => {
|
2016-11-17 08:04:20 -06:00
|
|
|
return name.clone();
|
2016-03-16 04:47:18 -05:00
|
|
|
}
|
|
|
|
|
2015-09-17 13:29:59 -05:00
|
|
|
// note that this does not show up in user printouts
|
2016-11-17 08:04:20 -06:00
|
|
|
CrateRoot => "{{root}}",
|
2015-09-17 13:29:59 -05:00
|
|
|
|
2016-11-17 08:04:20 -06:00
|
|
|
Impl => "{{impl}}",
|
|
|
|
Misc => "{{?}}",
|
|
|
|
ClosureExpr => "{{closure}}",
|
|
|
|
StructCtor => "{{constructor}}",
|
|
|
|
Initializer => "{{initializer}}",
|
|
|
|
ImplTrait => "{{impl-Trait}}",
|
|
|
|
};
|
2016-07-22 10:56:22 -05:00
|
|
|
|
2016-11-17 08:04:20 -06:00
|
|
|
Symbol::intern(s).as_str()
|
2015-09-17 13:29:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_string(&self) -> String {
|
|
|
|
self.as_interned_str().to_string()
|
|
|
|
}
|
|
|
|
}
|