Skip to content

Commit cd2724f

Browse files
committed
syntax: fix fallout of merging ast::ViewItem into ast::Item.
1 parent 4489d26 commit cd2724f

File tree

15 files changed

+209
-401
lines changed

15 files changed

+209
-401
lines changed

src/libsyntax/ast_map/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ pub fn map_crate<'ast, F: FoldOps>(forest: &'ast mut Forest, fold_ops: F) -> Map
883883
let krate = mem::replace(&mut forest.krate, Crate {
884884
module: Mod {
885885
inner: DUMMY_SP,
886-
view_items: vec![],
887886
items: vec![],
888887
},
889888
attrs: vec![],
@@ -1043,6 +1042,8 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10431042
Some(NodeItem(item)) => {
10441043
let path_str = map.path_to_str_with_ident(id, item.ident);
10451044
let item_str = match item.node {
1045+
ItemExternCrate(..) => "extern crate",
1046+
ItemUse(..) => "use",
10461047
ItemStatic(..) => "static",
10471048
ItemConst(..) => "const",
10481049
ItemFn(..) => "fn",

src/libsyntax/ast_util.rs

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -400,37 +400,6 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
400400
visit::walk_mod(self, module)
401401
}
402402

403-
fn visit_view_item(&mut self, view_item: &ViewItem) {
404-
if !self.pass_through_items {
405-
if self.visited_outermost {
406-
return;
407-
} else {
408-
self.visited_outermost = true;
409-
}
410-
}
411-
match view_item.node {
412-
ViewItemExternCrate(_, _, node_id) => {
413-
self.operation.visit_id(node_id)
414-
}
415-
ViewItemUse(ref view_path) => {
416-
match view_path.node {
417-
ViewPathSimple(_, _, node_id) |
418-
ViewPathGlob(_, node_id) => {
419-
self.operation.visit_id(node_id)
420-
}
421-
ViewPathList(_, ref paths, node_id) => {
422-
self.operation.visit_id(node_id);
423-
for path in paths.iter() {
424-
self.operation.visit_id(path.node.id())
425-
}
426-
}
427-
}
428-
}
429-
}
430-
visit::walk_view_item(self, view_item);
431-
self.visited_outermost = false;
432-
}
433-
434403
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
435404
self.operation.visit_id(foreign_item.id);
436405
visit::walk_foreign_item(self, foreign_item)
@@ -446,10 +415,24 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
446415
}
447416

448417
self.operation.visit_id(item.id);
449-
if let ItemEnum(ref enum_definition, _) = item.node {
450-
for variant in enum_definition.variants.iter() {
451-
self.operation.visit_id(variant.node.id)
418+
match item.node {
419+
ItemUse(ref view_path) => {
420+
match view_path.node {
421+
ViewPathSimple(_, _) |
422+
ViewPathGlob(_) => {}
423+
ViewPathList(_, ref paths) => {
424+
for path in paths.iter() {
425+
self.operation.visit_id(path.node.id())
426+
}
427+
}
428+
}
429+
}
430+
ItemEnum(ref enum_definition, _) => {
431+
for variant in enum_definition.variants.iter() {
432+
self.operation.visit_id(variant.node.id)
433+
}
452434
}
435+
_ => {}
453436
}
454437

455438
visit::walk_item(self, item);
@@ -648,37 +631,6 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
648631
}
649632
}
650633

651-
pub trait EachViewItem {
652-
fn each_view_item<F>(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool;
653-
}
654-
655-
struct EachViewItemData<F> where F: FnMut(&ast::ViewItem) -> bool {
656-
callback: F,
657-
}
658-
659-
impl<'v, F> Visitor<'v> for EachViewItemData<F> where F: FnMut(&ast::ViewItem) -> bool {
660-
fn visit_view_item(&mut self, view_item: &ast::ViewItem) {
661-
let _ = (self.callback)(view_item);
662-
}
663-
}
664-
665-
impl EachViewItem for ast::Crate {
666-
fn each_view_item<F>(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool {
667-
let mut visit = EachViewItemData {
668-
callback: f,
669-
};
670-
visit::walk_crate(&mut visit, self);
671-
true
672-
}
673-
}
674-
675-
pub fn view_path_id(p: &ViewPath) -> NodeId {
676-
match p.node {
677-
ViewPathSimple(_, _, id) | ViewPathGlob(_, id)
678-
| ViewPathList(_, _, id) => id
679-
}
680-
}
681-
682634
/// Returns true if the given struct def is tuple-like; i.e. that its fields
683635
/// are unnamed.
684636
pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {

src/libsyntax/config.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,13 @@ pub fn strip_items<F>(krate: ast::Crate, in_cfg: F) -> ast::Crate where
6363
ctxt.fold_crate(krate)
6464
}
6565

66-
fn filter_view_item<F>(cx: &mut Context<F>,
67-
view_item: ast::ViewItem)
68-
-> Option<ast::ViewItem> where
69-
F: FnMut(&[ast::Attribute]) -> bool
70-
{
71-
if view_item_in_cfg(cx, &view_item) {
72-
Some(view_item)
73-
} else {
74-
None
75-
}
76-
}
77-
7866
fn fold_mod<F>(cx: &mut Context<F>,
79-
ast::Mod {inner,
80-
view_items, items}: ast::Mod) -> ast::Mod where
67+
ast::Mod {inner, items}: ast::Mod)
68+
-> ast::Mod where
8169
F: FnMut(&[ast::Attribute]) -> bool
8270
{
8371
ast::Mod {
8472
inner: inner,
85-
view_items: view_items.into_iter().filter_map(|a| {
86-
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
87-
}).collect(),
8873
items: items.into_iter().flat_map(|a| {
8974
cx.fold_item(a).into_iter()
9075
}).collect()
@@ -104,15 +89,12 @@ fn filter_foreign_item<F>(cx: &mut Context<F>,
10489
}
10590

10691
fn fold_foreign_mod<F>(cx: &mut Context<F>,
107-
ast::ForeignMod {abi, view_items, items}: ast::ForeignMod)
92+
ast::ForeignMod {abi, items}: ast::ForeignMod)
10893
-> ast::ForeignMod where
10994
F: FnMut(&[ast::Attribute]) -> bool
11095
{
11196
ast::ForeignMod {
11297
abi: abi,
113-
view_items: view_items.into_iter().filter_map(|a| {
114-
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
115-
}).collect(),
11698
items: items.into_iter()
11799
.filter_map(|a| filter_foreign_item(cx, a))
118100
.collect()
@@ -216,18 +198,14 @@ fn retain_stmt<F>(cx: &mut Context<F>, stmt: &ast::Stmt) -> bool where
216198
fn fold_block<F>(cx: &mut Context<F>, b: P<ast::Block>) -> P<ast::Block> where
217199
F: FnMut(&[ast::Attribute]) -> bool
218200
{
219-
b.map(|ast::Block {id, view_items, stmts, expr, rules, span}| {
201+
b.map(|ast::Block {id, stmts, expr, rules, span}| {
220202
let resulting_stmts: Vec<P<ast::Stmt>> =
221203
stmts.into_iter().filter(|a| retain_stmt(cx, &**a)).collect();
222204
let resulting_stmts = resulting_stmts.into_iter()
223205
.flat_map(|stmt| cx.fold_stmt(stmt).into_iter())
224206
.collect();
225-
let filtered_view_items = view_items.into_iter().filter_map(|a| {
226-
filter_view_item(cx, a).map(|x| cx.fold_view_item(x))
227-
}).collect();
228207
ast::Block {
229208
id: id,
230-
view_items: filtered_view_items,
231209
stmts: resulting_stmts,
232210
expr: expr.map(|x| cx.fold_expr(x)),
233211
rules: rules,
@@ -267,12 +245,6 @@ fn foreign_item_in_cfg<F>(cx: &mut Context<F>, item: &ast::ForeignItem) -> bool
267245
return (cx.in_cfg)(item.attrs.as_slice());
268246
}
269247

270-
fn view_item_in_cfg<F>(cx: &mut Context<F>, item: &ast::ViewItem) -> bool where
271-
F: FnMut(&[ast::Attribute]) -> bool
272-
{
273-
return (cx.in_cfg)(item.attrs.as_slice());
274-
}
275-
276248
fn trait_method_in_cfg<F>(cx: &mut Context<F>, meth: &ast::TraitItem) -> bool where
277249
F: FnMut(&[ast::Attribute]) -> bool
278250
{

src/libsyntax/ext/build.rs

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub trait AstBuilder {
9797
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
9898
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
9999
fn block_all(&self, span: Span,
100-
view_items: Vec<ast::ViewItem>,
101100
stmts: Vec<P<ast::Stmt>>,
102101
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
103102

@@ -242,7 +241,7 @@ pub trait AstBuilder {
242241

243242
fn item_mod(&self, span: Span, inner_span: Span,
244243
name: Ident, attrs: Vec<ast::Attribute>,
245-
vi: Vec<ast::ViewItem> , items: Vec<P<ast::Item>> ) -> P<ast::Item>;
244+
items: Vec<P<ast::Item>>) -> P<ast::Item>;
246245

247246
fn item_static(&self,
248247
span: Span,
@@ -280,15 +279,15 @@ pub trait AstBuilder {
280279
value: ast::Lit_)
281280
-> P<ast::MetaItem>;
282281

283-
fn view_use(&self, sp: Span,
284-
vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem;
285-
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem;
286-
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
287-
ident: ast::Ident, path: ast::Path) -> ast::ViewItem;
288-
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
289-
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem;
290-
fn view_use_glob(&self, sp: Span,
291-
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem;
282+
fn item_use(&self, sp: Span,
283+
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
284+
fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>;
285+
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
286+
ident: ast::Ident, path: ast::Path) -> P<ast::Item>;
287+
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
288+
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>;
289+
fn item_use_glob(&self, sp: Span,
290+
vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item>;
292291
}
293292

294293
impl<'a> AstBuilder for ExtCtxt<'a> {
@@ -519,7 +518,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
519518

520519
fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
521520
expr: Option<P<Expr>>) -> P<ast::Block> {
522-
self.block_all(span, Vec::new(), stmts, expr)
521+
self.block_all(span, stmts, expr)
523522
}
524523

525524
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
@@ -528,15 +527,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
528527
}
529528

530529
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
531-
self.block_all(expr.span, Vec::new(), Vec::new(), Some(expr))
530+
self.block_all(expr.span, Vec::new(), Some(expr))
532531
}
533532
fn block_all(&self,
534533
span: Span,
535-
view_items: Vec<ast::ViewItem>,
536534
stmts: Vec<P<ast::Stmt>>,
537535
expr: Option<P<ast::Expr>>) -> P<ast::Block> {
538536
P(ast::Block {
539-
view_items: view_items,
540537
stmts: stmts,
541538
expr: expr,
542539
id: ast::DUMMY_NODE_ID,
@@ -1031,16 +1028,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
10311028
}
10321029

10331030
fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
1034-
attrs: Vec<ast::Attribute> ,
1035-
vi: Vec<ast::ViewItem> ,
1036-
items: Vec<P<ast::Item>> ) -> P<ast::Item> {
1031+
attrs: Vec<ast::Attribute>,
1032+
items: Vec<P<ast::Item>>) -> P<ast::Item> {
10371033
self.item(
10381034
span,
10391035
name,
10401036
attrs,
10411037
ast::ItemMod(ast::Mod {
10421038
inner: inner_span,
1043-
view_items: vi,
10441039
items: items,
10451040
})
10461041
)
@@ -1101,47 +1096,47 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11011096
P(respan(sp, ast::MetaNameValue(name, respan(sp, value))))
11021097
}
11031098

1104-
fn view_use(&self, sp: Span,
1105-
vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem {
1106-
ast::ViewItem {
1107-
node: ast::ViewItemUse(vp),
1108-
attrs: Vec::new(),
1099+
fn item_use(&self, sp: Span,
1100+
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
1101+
P(ast::Item {
1102+
id: ast::DUMMY_NODE_ID,
1103+
ident: special_idents::invalid,
1104+
attrs: vec![],
1105+
node: ast::ItemUse(vp),
11091106
vis: vis,
11101107
span: sp
1111-
}
1108+
})
11121109
}
11131110

1114-
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem {
1111+
fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> {
11151112
let last = path.segments.last().unwrap().identifier;
1116-
self.view_use_simple_(sp, vis, last, path)
1113+
self.item_use_simple_(sp, vis, last, path)
11171114
}
11181115

1119-
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
1120-
ident: ast::Ident, path: ast::Path) -> ast::ViewItem {
1121-
self.view_use(sp, vis,
1116+
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
1117+
ident: ast::Ident, path: ast::Path) -> P<ast::Item> {
1118+
self.item_use(sp, vis,
11221119
P(respan(sp,
11231120
ast::ViewPathSimple(ident,
1124-
path,
1125-
ast::DUMMY_NODE_ID))))
1121+
path))))
11261122
}
11271123

1128-
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
1129-
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem {
1124+
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
1125+
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
11301126
let imports = imports.iter().map(|id| {
11311127
respan(sp, ast::PathListIdent { name: *id, id: ast::DUMMY_NODE_ID })
11321128
}).collect();
11331129

1134-
self.view_use(sp, vis,
1130+
self.item_use(sp, vis,
11351131
P(respan(sp,
11361132
ast::ViewPathList(self.path(sp, path),
1137-
imports,
1138-
ast::DUMMY_NODE_ID))))
1133+
imports))))
11391134
}
11401135

1141-
fn view_use_glob(&self, sp: Span,
1142-
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem {
1143-
self.view_use(sp, vis,
1136+
fn item_use_glob(&self, sp: Span,
1137+
vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item> {
1138+
self.item_use(sp, vis,
11441139
P(respan(sp,
1145-
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))))
1140+
ast::ViewPathGlob(self.path(sp, path)))))
11461141
}
11471142
}

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ impl<'a> MethodDef<'a> {
10731073
// <delegated expression referring to __self0_vi, et al.>
10741074
// }
10751075
let arm_expr = cx.expr_block(
1076-
cx.block_all(sp, Vec::new(), index_let_stmts, Some(arm_expr)));
1076+
cx.block_all(sp, index_let_stmts, Some(arm_expr)));
10771077

10781078
// Builds arm:
10791079
// _ => { let __self0_vi = ...;

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
212212
// wrap the if-let expr in a block
213213
let span = els.span;
214214
let blk = P(ast::Block {
215-
view_items: vec![],
216215
stmts: vec![],
217216
expr: Some(P(els)),
218217
id: ast::DUMMY_NODE_ID,
@@ -848,8 +847,7 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
848847

849848
// expand the elements of a block.
850849
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
851-
b.map(|Block {id, view_items, stmts, expr, rules, span}| {
852-
let new_view_items = view_items.into_iter().map(|x| fld.fold_view_item(x)).collect();
850+
b.map(|Block {id, stmts, expr, rules, span}| {
853851
let new_stmts = stmts.into_iter().flat_map(|x| {
854852
// perform all pending renames
855853
let renamed_stmt = {
@@ -870,7 +868,6 @@ pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
870868
});
871869
Block {
872870
id: fld.new_id(id),
873-
view_items: new_view_items,
874871
stmts: new_stmts,
875872
expr: new_expr,
876873
rules: rules,

0 commit comments

Comments
 (0)