diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-21 11:56:00 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-21 11:56:00 -0800 |
| commit | df1cddf20a2a4ece854e5d8592ad3155a3313fd2 (patch) | |
| tree | 50bdd6498e1378cbeb48e80e35157152920e9c56 /src/libsyntax/ext | |
| parent | 886c6f3534e6f03916eeff2ea8b235e85dd04b42 (diff) | |
| parent | 2d17a33878f1af0aa500a4e1ff6aa5c8689ab249 (diff) | |
| download | rust-df1cddf20a2a4ece854e5d8592ad3155a3313fd2.tar.gz rust-df1cddf20a2a4ece854e5d8592ad3155a3313fd2.zip | |
rollup merge of #20179: eddyb/blind-items
Conflicts: src/librustc/diagnostics.rs src/librustdoc/clean/mod.rs src/librustdoc/html/format.rs src/libsyntax/parse/parser.rs
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/build.rs | 77 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 28 |
4 files changed, 48 insertions, 64 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 8773c0f2f79..92619cf42e4 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -97,7 +97,6 @@ pub trait AstBuilder { expr: Option<P<ast::Expr>>) -> P<ast::Block>; fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>; fn block_all(&self, span: Span, - view_items: Vec<ast::ViewItem>, stmts: Vec<P<ast::Stmt>>, expr: Option<P<ast::Expr>>) -> P<ast::Block>; @@ -242,7 +241,7 @@ pub trait AstBuilder { fn item_mod(&self, span: Span, inner_span: Span, name: Ident, attrs: Vec<ast::Attribute>, - vi: Vec<ast::ViewItem> , items: Vec<P<ast::Item>> ) -> P<ast::Item>; + items: Vec<P<ast::Item>>) -> P<ast::Item>; fn item_static(&self, span: Span, @@ -280,15 +279,15 @@ pub trait AstBuilder { value: ast::Lit_) -> P<ast::MetaItem>; - fn view_use(&self, sp: Span, - vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem; - fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem; - fn view_use_simple_(&self, sp: Span, vis: ast::Visibility, - ident: ast::Ident, path: ast::Path) -> ast::ViewItem; - fn view_use_list(&self, sp: Span, vis: ast::Visibility, - path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem; - fn view_use_glob(&self, sp: Span, - vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem; + fn item_use(&self, sp: Span, + vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>; + fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>; + fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, + ident: ast::Ident, path: ast::Path) -> P<ast::Item>; + fn item_use_list(&self, sp: Span, vis: ast::Visibility, + path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>; + fn item_use_glob(&self, sp: Span, + vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item>; } impl<'a> AstBuilder for ExtCtxt<'a> { @@ -519,7 +518,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>, expr: Option<P<Expr>>) -> P<ast::Block> { - self.block_all(span, Vec::new(), stmts, expr) + self.block_all(span, stmts, expr) } fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> { @@ -528,15 +527,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { - self.block_all(expr.span, Vec::new(), Vec::new(), Some(expr)) + self.block_all(expr.span, Vec::new(), Some(expr)) } fn block_all(&self, span: Span, - view_items: Vec<ast::ViewItem>, stmts: Vec<P<ast::Stmt>>, expr: Option<P<ast::Expr>>) -> P<ast::Block> { P(ast::Block { - view_items: view_items, stmts: stmts, expr: expr, id: ast::DUMMY_NODE_ID, @@ -1031,16 +1028,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn item_mod(&self, span: Span, inner_span: Span, name: Ident, - attrs: Vec<ast::Attribute> , - vi: Vec<ast::ViewItem> , - items: Vec<P<ast::Item>> ) -> P<ast::Item> { + attrs: Vec<ast::Attribute>, + items: Vec<P<ast::Item>>) -> P<ast::Item> { self.item( span, name, attrs, ast::ItemMod(ast::Mod { inner: inner_span, - view_items: vi, items: items, }) ) @@ -1101,47 +1096,47 @@ impl<'a> AstBuilder for ExtCtxt<'a> { P(respan(sp, ast::MetaNameValue(name, respan(sp, value)))) } - fn view_use(&self, sp: Span, - vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem { - ast::ViewItem { - node: ast::ViewItemUse(vp), - attrs: Vec::new(), + fn item_use(&self, sp: Span, + vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> { + P(ast::Item { + id: ast::DUMMY_NODE_ID, + ident: special_idents::invalid, + attrs: vec![], + node: ast::ItemUse(vp), vis: vis, span: sp - } + }) } - fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem { + fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> { let last = path.segments.last().unwrap().identifier; - self.view_use_simple_(sp, vis, last, path) + self.item_use_simple_(sp, vis, last, path) } - fn view_use_simple_(&self, sp: Span, vis: ast::Visibility, - ident: ast::Ident, path: ast::Path) -> ast::ViewItem { - self.view_use(sp, vis, + fn item_use_simple_(&self, sp: Span, vis: ast::Visibility, + ident: ast::Ident, path: ast::Path) -> P<ast::Item> { + self.item_use(sp, vis, P(respan(sp, ast::ViewPathSimple(ident, - path, - ast::DUMMY_NODE_ID)))) + path)))) } - fn view_use_list(&self, sp: Span, vis: ast::Visibility, - path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem { + fn item_use_list(&self, sp: Span, vis: ast::Visibility, + path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> { let imports = imports.iter().map(|id| { respan(sp, ast::PathListIdent { name: *id, id: ast::DUMMY_NODE_ID }) }).collect(); - self.view_use(sp, vis, + self.item_use(sp, vis, P(respan(sp, ast::ViewPathList(self.path(sp, path), - imports, - ast::DUMMY_NODE_ID)))) + imports)))) } - fn view_use_glob(&self, sp: Span, - vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem { - self.view_use(sp, vis, + fn item_use_glob(&self, sp: Span, + vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item> { + self.item_use(sp, vis, P(respan(sp, - ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID)))) + ast::ViewPathGlob(self.path(sp, path))))) } } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 583f316289f..272b0464010 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1073,7 +1073,7 @@ impl<'a> MethodDef<'a> { // <delegated expression referring to __self0_vi, et al.> // } let arm_expr = cx.expr_block( - cx.block_all(sp, Vec::new(), index_let_stmts, Some(arm_expr))); + cx.block_all(sp, index_let_stmts, Some(arm_expr))); // Builds arm: // _ => { let __self0_vi = ...; diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9aa602b39b4..629991799e7 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -206,7 +206,6 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { // wrap the if-let expr in a block let span = els.span; let blk = P(ast::Block { - view_items: vec![], stmts: vec![], expr: Some(P(els)), id: ast::DUMMY_NODE_ID, @@ -799,8 +798,7 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> { // expand the elements of a block. pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> { - b.map(|Block {id, view_items, stmts, expr, rules, span}| { - let new_view_items = view_items.into_iter().map(|x| fld.fold_view_item(x)).collect(); + b.map(|Block {id, stmts, expr, rules, span}| { let new_stmts = stmts.into_iter().flat_map(|x| { // perform all pending renames let renamed_stmt = { @@ -821,7 +819,6 @@ pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> { }); Block { id: fld.new_id(id), - view_items: new_view_items, stmts: new_stmts, expr: new_expr, rules: rules, diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 5339c3d77c6..7e345a2d078 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -352,18 +352,11 @@ pub mod rt { impl<'a> ExtParseUtils for ExtCtxt<'a> { fn parse_item(&self, s: String) -> P<ast::Item> { - let res = parse::parse_item_from_source_str( + parse::parse_item_from_source_str( "<quote expansion>".to_string(), s, self.cfg(), - self.parse_sess()); - match res { - Some(ast) => ast, - None => { - error!("parse error"); - panic!() - } - } + self.parse_sess()).expect("parse error") } fn parse_stmt(&self, s: String) -> P<ast::Stmt> { @@ -767,7 +760,6 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) vector.extend(mk_tts(cx, &tts[]).into_iter()); let block = cx.expr_block( cx.block_all(sp, - Vec::new(), vector, Some(cx.expr_ident(sp, id_ext("tt"))))); @@ -778,18 +770,18 @@ fn expand_wrapper(cx: &ExtCtxt, sp: Span, cx_expr: P<ast::Expr>, expr: P<ast::Expr>) -> P<ast::Expr> { - let uses = [ - &["syntax", "ext", "quote", "rt"], - ].iter().map(|path| { - let path = path.iter().map(|s| s.to_string()).collect(); - cx.view_use_glob(sp, ast::Inherited, ids_ext(path)) - }).collect(); - // Explicitly borrow to avoid moving from the invoker (#16992) let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr)); let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow); - cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr))) + let stmts = [ + &["syntax", "ext", "quote", "rt"], + ].iter().map(|path| { + let path = path.iter().map(|s| s.to_string()).collect(); + cx.stmt_item(sp, cx.item_use_glob(sp, ast::Inherited, ids_ext(path))) + }).chain(Some(stmt_let_ext_cx).into_iter()).collect(); + + cx.expr_block(cx.block_all(sp, stmts, Some(expr))) } fn expand_parse_call(cx: &ExtCtxt, |
