Skip to content

Commit 6ba9acd

Browse files
committed
auto merge of #20963 : nick29581/rust/ast_map, r=eddyb
2 parents f1241f1 + bc3a330 commit 6ba9acd

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

src/librustc/metadata/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a> FileSearch<'a> {
5454

5555
debug!("filesearch: searching lib path");
5656
let tlib_path = make_target_lib_path(self.sysroot,
57-
self.triple);
57+
self.triple);
5858
if !visited_dirs.contains(tlib_path.as_vec()) {
5959
match f(&tlib_path) {
6060
FileMatches => found = true,

src/librustc/session/search_paths.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use std::slice;
1212

13-
#[derive(Clone)]
13+
#[derive(Clone, Show)]
1414
pub struct SearchPaths {
1515
paths: Vec<(PathKind, Path)>,
1616
}
@@ -20,7 +20,7 @@ pub struct Iter<'a> {
2020
iter: slice::Iter<'a, (PathKind, Path)>,
2121
}
2222

23-
#[derive(Eq, PartialEq, Clone, Copy)]
23+
#[derive(Eq, PartialEq, Clone, Copy, Show)]
2424
pub enum PathKind {
2525
Native,
2626
Crate,

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn run_compiler(args: &[String]) {
186186
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
187187
}
188188
Input::Str(_) => {
189-
early_error("can not list metadata for stdin");
189+
early_error("cannot list metadata for stdin");
190190
}
191191
}
192192
return;

src/librustc_trans/trans/monomorphize.rs

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
274274
ast_map::NodeArg(..) |
275275
ast_map::NodeBlock(..) |
276276
ast_map::NodePat(..) |
277+
ast_map::NodeViewItem(..) |
277278
ast_map::NodeLocal(..) => {
278279
ccx.sess().bug(&format!("can't monomorphize a {:?}",
279280
map_node)[])

src/libsyntax/ast.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,19 @@ pub struct ViewItem {
15281528
pub span: Span,
15291529
}
15301530

1531+
impl ViewItem {
1532+
pub fn id(&self) -> NodeId {
1533+
match self.node {
1534+
ViewItemExternCrate(_, _, id) => id,
1535+
ViewItemUse(ref vp) => match vp.node {
1536+
ViewPathSimple(_, _, id) => id,
1537+
ViewPathGlob(_, id) => id,
1538+
ViewPathList(_, _, id) => id,
1539+
}
1540+
}
1541+
}
1542+
}
1543+
15311544
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
15321545
pub enum ViewItem_ {
15331546
/// Ident: name used to refer to this crate in the code

src/libsyntax/ast_map/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
107107
#[derive(Copy, Show)]
108108
pub enum Node<'ast> {
109109
NodeItem(&'ast Item),
110+
NodeViewItem(&'ast ViewItem),
110111
NodeForeignItem(&'ast ForeignItem),
111112
NodeTraitItem(&'ast TraitItem),
112113
NodeImplItem(&'ast ImplItem),
@@ -133,6 +134,7 @@ enum MapEntry<'ast> {
133134

134135
/// All the node types, with a parent ID.
135136
EntryItem(NodeId, &'ast Item),
137+
EntryViewItem(NodeId, &'ast ViewItem),
136138
EntryForeignItem(NodeId, &'ast ForeignItem),
137139
EntryTraitItem(NodeId, &'ast TraitItem),
138140
EntryImplItem(NodeId, &'ast ImplItem),
@@ -167,6 +169,7 @@ impl<'ast> MapEntry<'ast> {
167169
fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
168170
match node {
169171
NodeItem(n) => EntryItem(p, n),
172+
NodeViewItem(n) => EntryViewItem(p, n),
170173
NodeForeignItem(n) => EntryForeignItem(p, n),
171174
NodeTraitItem(n) => EntryTraitItem(p, n),
172175
NodeImplItem(n) => EntryImplItem(p, n),
@@ -185,6 +188,7 @@ impl<'ast> MapEntry<'ast> {
185188
fn parent(self) -> Option<NodeId> {
186189
Some(match self {
187190
EntryItem(id, _) => id,
191+
EntryViewItem(id, _) => id,
188192
EntryForeignItem(id, _) => id,
189193
EntryTraitItem(id, _) => id,
190194
EntryImplItem(id, _) => id,
@@ -204,6 +208,7 @@ impl<'ast> MapEntry<'ast> {
204208
fn to_node(self) -> Option<Node<'ast>> {
205209
Some(match self {
206210
EntryItem(_, n) => NodeItem(n),
211+
EntryViewItem(_, n) => NodeViewItem(n),
207212
EntryForeignItem(_, n) => NodeForeignItem(n),
208213
EntryTraitItem(_, n) => NodeTraitItem(n),
209214
EntryImplItem(_, n) => NodeImplItem(n),
@@ -336,6 +341,13 @@ impl<'ast> Map<'ast> {
336341
}
337342
}
338343

344+
pub fn expect_view_item(&self, id: NodeId) -> &'ast ViewItem {
345+
match self.find(id) {
346+
Some(NodeViewItem(view_item)) => view_item,
347+
_ => panic!("expected view item, found {}", self.node_to_string(id))
348+
}
349+
}
350+
339351
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
340352
match self.find(id) {
341353
Some(NodeItem(i)) => {
@@ -521,6 +533,7 @@ impl<'ast> Map<'ast> {
521533
pub fn opt_span(&self, id: NodeId) -> Option<Span> {
522534
let sp = match self.find(id) {
523535
Some(NodeItem(item)) => item.span,
536+
Some(NodeViewItem(item)) => item.span,
524537
Some(NodeForeignItem(foreign_item)) => foreign_item.span,
525538
Some(NodeTraitItem(trait_method)) => {
526539
match *trait_method {
@@ -813,6 +826,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
813826
self.parent = parent;
814827
}
815828

829+
fn visit_view_item(&mut self, item: &'ast ViewItem) {
830+
self.insert(item.id(), NodeViewItem(item));
831+
visit::walk_view_item(self, item);
832+
}
833+
816834
fn visit_pat(&mut self, pat: &'ast Pat) {
817835
self.insert(pat.id, match pat.node {
818836
// Note: this is at least *potentially* a pattern...
@@ -1018,6 +1036,7 @@ impl<'a> NodePrinter for pprust::State<'a> {
10181036
fn print_node(&mut self, node: &Node) -> IoResult<()> {
10191037
match *node {
10201038
NodeItem(a) => self.print_item(&*a),
1039+
NodeViewItem(a) => self.print_view_item(&*a),
10211040
NodeForeignItem(a) => self.print_foreign_item(&*a),
10221041
NodeTraitItem(a) => self.print_trait_method(&*a),
10231042
NodeImplItem(a) => self.print_impl_item(&*a),
@@ -1060,6 +1079,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10601079
};
10611080
format!("{} {}{}", item_str, path_str, id_str)
10621081
}
1082+
Some(NodeViewItem(item)) => {
1083+
format!("view item {}{}", pprust::view_item_to_string(&*item), id_str)
1084+
}
10631085
Some(NodeForeignItem(item)) => {
10641086
let path_str = map.path_to_str_with_ident(id, item.ident);
10651087
format!("foreign item {}{}", path_str, id_str)

0 commit comments

Comments
 (0)