1 // Copyright 2012-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.
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.
11 use metadata::cstore::LOCAL_CRATE;
13 use syntax::ast::{CrateNum, NodeId};
16 #[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
17 RustcDecodable, Hash, Copy)]
23 impl fmt::Debug for DefId {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 try!(write!(f, "DefId {{ krate: {}, node: {}",
26 self.krate, self.xxx_node));
28 // Unfortunately, there seems to be no way to attempt to print
29 // a path for a def-id, so I'll just make a best effort for now
30 // and otherwise fallback to just printing the crate/node pair
31 try!(ty::tls::with_opt(|opt_tcx| {
32 if let Some(tcx) = opt_tcx {
33 try!(write!(f, " => {}", tcx.item_path_str(*self)));
44 pub fn xxx_local(id: NodeId) -> DefId {
45 DefId { krate: LOCAL_CRATE, xxx_node: id }
48 pub fn is_local(&self) -> bool {
49 self.krate == LOCAL_CRATE