Skip to content

Commit 2f8327e

Browse files
committed
---
yaml --- r: 232661 b: refs/heads/try c: afba694 h: refs/heads/master i: 232659: eed1e64 v: v3
1 parent fd9aa20 commit 2f8327e

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 63ba780fd7ab506bfd0f92d34a39172b412cfbe1
4+
refs/heads/try: afba69461a7a092753e1458b77fafcb30e016499
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub mod middle {
118118
pub mod dataflow;
119119
pub mod dead;
120120
pub mod def;
121+
pub mod def_id;
121122
pub mod dependency_format;
122123
pub mod effect;
123124
pub mod entry;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.
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+
11+
use syntax::ast::{CrateNum, NodeId};
12+
use std::cell::Cell;
13+
use std::fmt;
14+
15+
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
16+
RustcDecodable, Hash, Copy)]
17+
pub struct DefId {
18+
pub krate: CrateNum,
19+
pub node: NodeId,
20+
}
21+
22+
fn default_def_id_debug(_: DefId, _: &mut fmt::Formatter) -> fmt::Result { Ok(()) }
23+
24+
thread_local!(pub static DEF_ID_DEBUG: Cell<fn(DefId, &mut fmt::Formatter) -> fmt::Result> =
25+
Cell::new(default_def_id_debug));
26+
27+
impl fmt::Debug for DefId {
28+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29+
try!(write!(f, "DefId {{ krate: {}, node: {} }}",
30+
self.krate, self.node));
31+
DEF_ID_DEBUG.with(|def_id_debug| def_id_debug.get()(*self, f))
32+
}
33+
}
34+
35+
impl DefId {
36+
pub fn local(id: NodeId) -> DefId {
37+
DefId { krate: LOCAL_CRATE, node: id }
38+
}
39+
40+
/// Read the node id, asserting that this def-id is krate-local.
41+
pub fn local_id(&self) -> NodeId {
42+
assert_eq!(self.krate, LOCAL_CRATE);
43+
self.node
44+
}
45+
46+
pub fn is_local(&self) -> bool {
47+
self.krate == LOCAL_CRATE
48+
}
49+
}
50+
51+
52+
/// Item definitions in the currently-compiled crate would have the CrateNum
53+
/// LOCAL_CRATE in their DefId.
54+
pub const LOCAL_CRATE: CrateNum = 0;
55+

branches/try/src/libsyntax/ast.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
6565
use print::pprust;
6666
use ptr::P;
6767

68-
use std::cell::Cell;
6968
use std::fmt;
7069
use std::rc::Rc;
7170
use serialize::{Encodable, Decodable, Encoder, Decoder};
@@ -371,37 +370,7 @@ pub type CrateNum = u32;
371370

372371
pub type NodeId = u32;
373372

374-
#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
375-
RustcDecodable, Hash, Copy)]
376-
pub struct DefId {
377-
pub krate: CrateNum,
378-
pub node: NodeId,
379-
}
380-
381-
fn default_def_id_debug(_: DefId, _: &mut fmt::Formatter) -> fmt::Result { Ok(()) }
382-
383-
thread_local!(pub static DEF_ID_DEBUG: Cell<fn(DefId, &mut fmt::Formatter) -> fmt::Result> =
384-
Cell::new(default_def_id_debug));
385-
386-
impl fmt::Debug for DefId {
387-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
388-
try!(write!(f, "DefId {{ krate: {}, node: {} }}",
389-
self.krate, self.node));
390-
DEF_ID_DEBUG.with(|def_id_debug| def_id_debug.get()(*self, f))
391-
}
392-
}
393-
394-
impl DefId {
395-
/// Read the node id, asserting that this def-id is krate-local.
396-
pub fn local_id(&self) -> NodeId {
397-
assert_eq!(self.krate, LOCAL_CRATE);
398-
self.node
399-
}
400-
}
401-
402-
/// Item definitions in the currently-compiled crate would have the CrateNum
403-
/// LOCAL_CRATE in their DefId.
404-
pub const LOCAL_CRATE: CrateNum = 0;
373+
/// Node id used to represent the root of the crate.
405374
pub const CRATE_NODE_ID: NodeId = 0;
406375

407376
/// When parsing and doing expansions, we initially give all AST nodes this AST

branches/try/src/libsyntax/ast_util.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ pub fn path_name_i(idents: &[Ident]) -> String {
2828
idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
2929
}
3030

31-
pub fn local_def(id: NodeId) -> DefId {
32-
ast::DefId { krate: LOCAL_CRATE, node: id }
33-
}
34-
35-
pub fn is_local(did: ast::DefId) -> bool { did.krate == LOCAL_CRATE }
36-
3731
pub fn stmt_id(s: &Stmt) -> NodeId {
3832
match s.node {
3933
StmtDecl(_, id) => id,

0 commit comments

Comments
 (0)