Skip to content

Commit 024ec1f

Browse files
committed
---
yaml --- r: 233660 b: refs/heads/beta c: afba694 h: refs/heads/master v: v3
1 parent 890acd8 commit 024ec1f

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
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 63ba780fd7ab506bfd0f92d34a39172b412cfbe1
26+
refs/heads/beta: afba69461a7a092753e1458b77fafcb30e016499
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/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/beta/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/beta/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)