Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | // file at the top-level directory of this distribution and at |
| 3 | // http://rust-lang.org/COPYRIGHT. |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | // option. This file may not be copied, modified, or distributed |
| 9 | // except according to those terms. |
| 10 | |
Eduard Burtescu | fc363cb | 2016-08-31 11:00:29 | [diff] [blame] | 11 | use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; |
Nicholas Nethercote | 00e48af | 2016-11-08 03:02:55 | [diff] [blame] | 12 | use rustc_data_structures::fx::FxHashMap; |
Niko Matsakis | 2e7df80 | 2016-08-01 23:55:20 | [diff] [blame] | 13 | use std::fmt::Write; |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 14 | use std::hash::{Hash, Hasher}; |
| 15 | use std::collections::hash_map::DefaultHasher; |
Jeffrey Seyfried | ebaaafc | 2016-09-14 09:55:20 | [diff] [blame] | 16 | use syntax::ast; |
Jeffrey Seyfried | d2f8fb0 | 2016-11-16 08:21:52 | [diff] [blame] | 17 | use syntax::symbol::{Symbol, InternedString}; |
Niko Matsakis | 2e7df80 | 2016-08-01 23:55:20 | [diff] [blame] | 18 | use ty::TyCtxt; |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 19 | use util::nodemap::NodeMap; |
| 20 | |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 21 | /// The definition table containing node definitions |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 22 | #[derive(Clone)] |
| 23 | pub struct Definitions { |
| 24 | data: Vec<DefData>, |
Nicholas Nethercote | 00e48af | 2016-11-08 03:02:55 | [diff] [blame] | 25 | key_map: FxHashMap<DefKey, DefIndex>, |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 26 | node_map: NodeMap<DefIndex>, |
| 27 | } |
| 28 | |
| 29 | /// A unique identifier that we can use to lookup a definition |
| 30 | /// precisely. It combines the index of the definition's parent (if |
| 31 | /// any) with a `DisambiguatedDefPathData`. |
| 32 | #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] |
| 33 | pub struct DefKey { |
| 34 | /// Parent path. |
| 35 | pub parent: Option<DefIndex>, |
| 36 | |
| 37 | /// Identifier of this node. |
| 38 | pub disambiguated_data: DisambiguatedDefPathData, |
| 39 | } |
| 40 | |
| 41 | /// Pair of `DefPathData` and an integer disambiguator. The integer is |
| 42 | /// normally 0, but in the event that there are multiple defs with the |
| 43 | /// same `parent` and `data`, we use this field to disambiguate |
| 44 | /// between them. This introduces some artificial ordering dependency |
| 45 | /// but means that if you have (e.g.) two impls for the same type in |
| 46 | /// the same module, they do get distinct def-ids. |
| 47 | #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] |
| 48 | pub struct DisambiguatedDefPathData { |
| 49 | pub data: DefPathData, |
| 50 | pub disambiguator: u32 |
| 51 | } |
| 52 | |
| 53 | /// For each definition, we track the following data. A definition |
| 54 | /// here is defined somewhat circularly as "something with a def-id", |
| 55 | /// but it generally corresponds to things like structs, enums, etc. |
| 56 | /// There are also some rather random cases (like const initializer |
| 57 | /// expressions) that are mostly just leftovers. |
| 58 | #[derive(Clone, Debug)] |
| 59 | pub struct DefData { |
| 60 | pub key: DefKey, |
| 61 | |
| 62 | /// Local ID within the HIR. |
| 63 | pub node_id: ast::NodeId, |
| 64 | } |
| 65 | |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 66 | #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] |
| 67 | pub struct DefPath { |
| 68 | /// the path leading from the crate root to the item |
| 69 | pub data: Vec<DisambiguatedDefPathData>, |
| 70 | |
| 71 | /// what krate root is this path relative to? |
Eduard Burtescu | fc363cb | 2016-08-31 11:00:29 | [diff] [blame] | 72 | pub krate: CrateNum, |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | impl DefPath { |
| 76 | pub fn is_local(&self) -> bool { |
| 77 | self.krate == LOCAL_CRATE |
| 78 | } |
| 79 | |
Eduard Burtescu | fc363cb | 2016-08-31 11:00:29 | [diff] [blame] | 80 | pub fn make<FN>(start_krate: CrateNum, |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 81 | start_index: DefIndex, |
| 82 | mut get_key: FN) -> DefPath |
| 83 | where FN: FnMut(DefIndex) -> DefKey |
| 84 | { |
| 85 | let mut krate = start_krate; |
| 86 | let mut data = vec![]; |
| 87 | let mut index = Some(start_index); |
| 88 | loop { |
Niko Matsakis | b01919a | 2016-05-06 18:52:57 | [diff] [blame] | 89 | debug!("DefPath::make: krate={:?} index={:?}", krate, index); |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 90 | let p = index.unwrap(); |
| 91 | let key = get_key(p); |
Niko Matsakis | b01919a | 2016-05-06 18:52:57 | [diff] [blame] | 92 | debug!("DefPath::make: key={:?}", key); |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 93 | match key.disambiguated_data.data { |
| 94 | DefPathData::CrateRoot => { |
| 95 | assert!(key.parent.is_none()); |
| 96 | break; |
| 97 | } |
| 98 | DefPathData::InlinedRoot(ref p) => { |
| 99 | assert!(key.parent.is_none()); |
| 100 | assert!(!p.def_id.is_local()); |
| 101 | data.extend(p.data.iter().cloned().rev()); |
| 102 | krate = p.def_id.krate; |
| 103 | break; |
| 104 | } |
| 105 | _ => { |
| 106 | data.push(key.disambiguated_data); |
| 107 | index = key.parent; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | data.reverse(); |
| 112 | DefPath { data: data, krate: krate } |
| 113 | } |
Niko Matsakis | 2e7df80 | 2016-08-01 23:55:20 | [diff] [blame] | 114 | |
| 115 | pub fn to_string(&self, tcx: TyCtxt) -> String { |
| 116 | let mut s = String::with_capacity(self.data.len() * 16); |
| 117 | |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame^] | 118 | s.push_str(&tcx.original_crate_name(self.krate).as_str()); |
Niko Matsakis | 2e7df80 | 2016-08-01 23:55:20 | [diff] [blame] | 119 | s.push_str("/"); |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame^] | 120 | s.push_str(&tcx.crate_disambiguator(self.krate).as_str()); |
Niko Matsakis | 2e7df80 | 2016-08-01 23:55:20 | [diff] [blame] | 121 | |
| 122 | for component in &self.data { |
| 123 | write!(s, |
| 124 | "::{}[{}]", |
| 125 | component.data.as_interned_str(), |
| 126 | component.disambiguator) |
| 127 | .unwrap(); |
| 128 | } |
| 129 | |
| 130 | s |
| 131 | } |
Niko Matsakis | 8150494 | 2016-08-06 00:12:20 | [diff] [blame] | 132 | |
| 133 | pub fn deterministic_hash(&self, tcx: TyCtxt) -> u64 { |
Alex Crichton | 10c3134 | 2016-09-29 00:23:36 | [diff] [blame] | 134 | let mut state = DefaultHasher::new(); |
Niko Matsakis | 8150494 | 2016-08-06 00:12:20 | [diff] [blame] | 135 | self.deterministic_hash_to(tcx, &mut state); |
| 136 | state.finish() |
| 137 | } |
| 138 | |
| 139 | pub fn deterministic_hash_to<H: Hasher>(&self, tcx: TyCtxt, state: &mut H) { |
Jeffrey Seyfried | e85a0d7 | 2016-11-16 10:52:37 | [diff] [blame^] | 140 | tcx.original_crate_name(self.krate).as_str().hash(state); |
| 141 | tcx.crate_disambiguator(self.krate).as_str().hash(state); |
Niko Matsakis | 8150494 | 2016-08-06 00:12:20 | [diff] [blame] | 142 | self.data.hash(state); |
| 143 | } |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 144 | } |
| 145 | |
Niko Matsakis | 65c0b7c | 2016-03-16 09:31:51 | [diff] [blame] | 146 | /// Root of an inlined item. We track the `DefPath` of the item within |
| 147 | /// the original crate but also its def-id. This is kind of an |
| 148 | /// augmented version of a `DefPath` that includes a `DefId`. This is |
| 149 | /// all sort of ugly but the hope is that inlined items will be going |
| 150 | /// away soon anyway. |
| 151 | /// |
| 152 | /// Some of the constraints that led to the current approach: |
| 153 | /// |
| 154 | /// - I don't want to have a `DefId` in the main `DefPath` because |
| 155 | /// that gets serialized for incr. comp., and when reloaded the |
| 156 | /// `DefId` is no longer valid. I'd rather maintain the invariant |
| 157 | /// that every `DefId` is valid, and a potentially outdated `DefId` is |
| 158 | /// represented as a `DefPath`. |
| 159 | /// - (We don't serialize def-paths from inlined items, so it's ok to have one here.) |
| 160 | /// - We need to be able to extract the def-id from inline items to |
| 161 | /// make the symbol name. In theory we could retrace it from the |
| 162 | /// data, but the metadata doesn't have the required indices, and I |
| 163 | /// don't want to write the code to create one just for this. |
| 164 | /// - It may be that we don't actually need `data` at all. We'll have |
| 165 | /// to see about that. |
| 166 | #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] |
| 167 | pub struct InlinedRootPath { |
| 168 | pub data: Vec<DisambiguatedDefPathData>, |
| 169 | pub def_id: DefId, |
| 170 | } |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 171 | |
| 172 | #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] |
| 173 | pub enum DefPathData { |
| 174 | // Root: these should only be used for the root nodes, because |
| 175 | // they are treated specially by the `def_path` function. |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 176 | /// The crate root (marker) |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 177 | CrateRoot, |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 178 | /// An inlined root |
Niko Matsakis | 65c0b7c | 2016-03-16 09:31:51 | [diff] [blame] | 179 | InlinedRoot(Box<InlinedRootPath>), |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 180 | |
| 181 | // Catch-all for random DefId things like DUMMY_NODE_ID |
| 182 | Misc, |
| 183 | |
| 184 | // Different kinds of items and item-like things: |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 185 | /// An impl |
Niko Matsakis | 5e26508 | 2016-03-16 09:47:18 | [diff] [blame] | 186 | Impl, |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 187 | /// Something in the type NS |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 188 | TypeNs(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 189 | /// Something in the value NS |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 190 | ValueNs(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 191 | /// A module declaration |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 192 | Module(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 193 | /// A macro rule |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 194 | MacroDef(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 195 | /// A closure expression |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 196 | ClosureExpr, |
| 197 | |
| 198 | // Subportions of items |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 199 | /// A type parameter (generic parameter) |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 200 | TypeParam(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 201 | /// A lifetime definition |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 202 | LifetimeDef(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 203 | /// A variant of a enum |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 204 | EnumVariant(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 205 | /// A struct field |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 206 | Field(InternedString), |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 207 | /// Implicit ctor for a tuple-like struct |
| 208 | StructCtor, |
| 209 | /// Initializer for a const |
| 210 | Initializer, |
| 211 | /// Pattern binding |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 212 | Binding(InternedString), |
Eduard Burtescu | ef11d4e | 2016-07-22 15:56:22 | [diff] [blame] | 213 | /// An `impl Trait` type node. |
| 214 | ImplTrait |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | impl Definitions { |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 218 | /// Create new empty definition map. |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 219 | pub fn new() -> Definitions { |
| 220 | Definitions { |
| 221 | data: vec![], |
Nicholas Nethercote | 00e48af | 2016-11-08 03:02:55 | [diff] [blame] | 222 | key_map: FxHashMap(), |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 223 | node_map: NodeMap(), |
| 224 | } |
| 225 | } |
| 226 | |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 227 | /// Get the number of definitions. |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 228 | pub fn len(&self) -> usize { |
| 229 | self.data.len() |
| 230 | } |
| 231 | |
| 232 | pub fn def_key(&self, index: DefIndex) -> DefKey { |
| 233 | self.data[index.as_usize()].key.clone() |
| 234 | } |
| 235 | |
Niko Matsakis | b01919a | 2016-05-06 18:52:57 | [diff] [blame] | 236 | pub fn def_index_for_def_key(&self, key: DefKey) -> Option<DefIndex> { |
| 237 | self.key_map.get(&key).cloned() |
| 238 | } |
| 239 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 240 | /// Returns the path from the crate root to `index`. The root |
| 241 | /// nodes are not included in the path (i.e., this will be an |
| 242 | /// empty vector for the crate root). For an inlined item, this |
| 243 | /// will be the path of the item in the external crate (but the |
| 244 | /// path will begin with the path to the external crate). |
| 245 | pub fn def_path(&self, index: DefIndex) -> DefPath { |
Niko Matsakis | 7b6270b | 2016-03-16 09:40:14 | [diff] [blame] | 246 | DefPath::make(LOCAL_CRATE, index, |p| self.def_key(p)) |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | pub fn opt_def_index(&self, node: ast::NodeId) -> Option<DefIndex> { |
| 250 | self.node_map.get(&node).cloned() |
| 251 | } |
| 252 | |
| 253 | pub fn opt_local_def_id(&self, node: ast::NodeId) -> Option<DefId> { |
| 254 | self.opt_def_index(node).map(DefId::local) |
| 255 | } |
| 256 | |
Jeffrey Seyfried | 8428447 | 2016-04-24 03:26:10 | [diff] [blame] | 257 | pub fn local_def_id(&self, node: ast::NodeId) -> DefId { |
| 258 | self.opt_local_def_id(node).unwrap() |
| 259 | } |
| 260 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 261 | pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> { |
| 262 | if def_id.krate == LOCAL_CRATE { |
| 263 | assert!(def_id.index.as_usize() < self.data.len()); |
| 264 | Some(self.data[def_id.index.as_usize()].node_id) |
| 265 | } else { |
| 266 | None |
| 267 | } |
| 268 | } |
| 269 | |
Ticki | da55fd7 | 2015-12-21 21:24:15 | [diff] [blame] | 270 | /// Add a definition with a parent definition. |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 271 | pub fn create_def_with_parent(&mut self, |
| 272 | parent: Option<DefIndex>, |
| 273 | node_id: ast::NodeId, |
| 274 | data: DefPathData) |
| 275 | -> DefIndex { |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 276 | debug!("create_def_with_parent(parent={:?}, node_id={:?}, data={:?})", |
| 277 | parent, node_id, data); |
| 278 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 279 | assert!(!self.node_map.contains_key(&node_id), |
| 280 | "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}", |
| 281 | node_id, |
| 282 | data, |
| 283 | self.data[self.node_map[&node_id].as_usize()]); |
| 284 | |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 285 | assert!(parent.is_some() ^ match data { |
| 286 | DefPathData::CrateRoot | DefPathData::InlinedRoot(_) => true, |
| 287 | _ => false, |
| 288 | }); |
| 289 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 290 | // Find a unique DefKey. This basically means incrementing the disambiguator |
| 291 | // until we get no match. |
| 292 | let mut key = DefKey { |
| 293 | parent: parent, |
| 294 | disambiguated_data: DisambiguatedDefPathData { |
| 295 | data: data, |
| 296 | disambiguator: 0 |
| 297 | } |
| 298 | }; |
| 299 | |
| 300 | while self.key_map.contains_key(&key) { |
| 301 | key.disambiguated_data.disambiguator += 1; |
| 302 | } |
| 303 | |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 304 | debug!("create_def_with_parent: after disambiguation, key = {:?}", key); |
| 305 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 306 | // Create the definition. |
| 307 | let index = DefIndex::new(self.data.len()); |
| 308 | self.data.push(DefData { key: key.clone(), node_id: node_id }); |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 309 | debug!("create_def_with_parent: node_map[{:?}] = {:?}", node_id, index); |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 310 | self.node_map.insert(node_id, index); |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 311 | debug!("create_def_with_parent: key_map[{:?}] = {:?}", key, index); |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 312 | self.key_map.insert(key, index); |
| 313 | |
Niko Matsakis | d8263c4 | 2016-03-28 21:39:57 | [diff] [blame] | 314 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 315 | index |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | impl DefPathData { |
Eduard Burtescu | dadbaa4 | 2016-09-17 10:34:55 | [diff] [blame] | 320 | pub fn get_opt_name(&self) -> Option<ast::Name> { |
| 321 | use self::DefPathData::*; |
| 322 | match *self { |
| 323 | TypeNs(ref name) | |
| 324 | ValueNs(ref name) | |
| 325 | Module(ref name) | |
| 326 | MacroDef(ref name) | |
| 327 | TypeParam(ref name) | |
| 328 | LifetimeDef(ref name) | |
| 329 | EnumVariant(ref name) | |
| 330 | Binding(ref name) | |
Jeffrey Seyfried | d2f8fb0 | 2016-11-16 08:21:52 | [diff] [blame] | 331 | Field(ref name) => Some(Symbol::intern(name)), |
Eduard Burtescu | dadbaa4 | 2016-09-17 10:34:55 | [diff] [blame] | 332 | |
| 333 | Impl | |
| 334 | CrateRoot | |
| 335 | InlinedRoot(_) | |
| 336 | Misc | |
| 337 | ClosureExpr | |
| 338 | StructCtor | |
| 339 | Initializer | |
| 340 | ImplTrait => None |
| 341 | } |
| 342 | } |
| 343 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 344 | pub fn as_interned_str(&self) -> InternedString { |
| 345 | use self::DefPathData::*; |
| 346 | match *self { |
Niko Matsakis | 571010b | 2016-08-06 00:10:04 | [diff] [blame] | 347 | TypeNs(ref name) | |
| 348 | ValueNs(ref name) | |
| 349 | Module(ref name) | |
| 350 | MacroDef(ref name) | |
| 351 | TypeParam(ref name) | |
| 352 | LifetimeDef(ref name) | |
| 353 | EnumVariant(ref name) | |
| 354 | Binding(ref name) | |
| 355 | Field(ref name) => { |
| 356 | name.clone() |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 357 | } |
| 358 | |
Niko Matsakis | 5e26508 | 2016-03-16 09:47:18 | [diff] [blame] | 359 | Impl => { |
| 360 | InternedString::new("{{impl}}") |
| 361 | } |
| 362 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 363 | // note that this does not show up in user printouts |
| 364 | CrateRoot => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 365 | InternedString::new("{{root}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | // note that this does not show up in user printouts |
| 369 | InlinedRoot(_) => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 370 | InternedString::new("{{inlined-root}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | Misc => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 374 | InternedString::new("{{?}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 375 | } |
| 376 | |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 377 | ClosureExpr => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 378 | InternedString::new("{{closure}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | StructCtor => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 382 | InternedString::new("{{constructor}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | Initializer => { |
Michael Woerister | 862911d | 2015-11-02 13:46:39 | [diff] [blame] | 386 | InternedString::new("{{initializer}}") |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 387 | } |
Eduard Burtescu | ef11d4e | 2016-07-22 15:56:22 | [diff] [blame] | 388 | |
| 389 | ImplTrait => { |
| 390 | InternedString::new("{{impl-Trait}}") |
| 391 | } |
Niko Matsakis | 01f32ac | 2015-09-17 18:29:59 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | pub fn to_string(&self) -> String { |
| 396 | self.as_interned_str().to_string() |
| 397 | } |
| 398 | } |
| 399 | |