Skip to content

Commit

Permalink
Auto merge of #31583 - petrochenkov:indi_ast, r=Manishearth
Browse files Browse the repository at this point in the history
cc #31487
plugin-[breaking-change]

The AST part of #30087

r? @Manishearth
  • Loading branch information
bors committed Feb 12, 2016
2 parents 9257e89 + 77cc576 commit c7640aa
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 254 deletions.
4 changes: 2 additions & 2 deletions src/librustc_driver/pretty.rs
Expand Up @@ -614,7 +614,7 @@ impl fold::Folder for ReplaceBodyWithLoop {
}
}

fn fold_trait_item(&mut self, i: P<ast::TraitItem>) -> SmallVector<P<ast::TraitItem>> {
fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem> {
match i.node {
ast::TraitItemKind::Const(..) => {
self.within_static_or_const = true;
Expand All @@ -626,7 +626,7 @@ impl fold::Folder for ReplaceBodyWithLoop {
}
}

fn fold_impl_item(&mut self, i: P<ast::ImplItem>) -> SmallVector<P<ast::ImplItem>> {
fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector<ast::ImplItem> {
match i.node {
ast::ImplItemKind::Const(..) => {
self.within_static_or_const = true;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -561,7 +561,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
type_parameters: &ast::Generics,
trait_ref: &Option<ast::TraitRef>,
typ: &ast::Ty,
impl_items: &[P<ast::ImplItem>]) {
impl_items: &[ast::ImplItem]) {
let mut has_self_ref = false;
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
down_cast_data!(impl_data, ImplData, self, item.span);
Expand Down Expand Up @@ -602,7 +602,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
item: &ast::Item,
generics: &ast::Generics,
trait_refs: &ast::TyParamBounds,
methods: &[P<ast::TraitItem>]) {
methods: &[ast::TraitItem]) {
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
let val = self.span.snippet(item.span);
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait);
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/ast.rs
Expand Up @@ -287,7 +287,7 @@ impl PathParameters {
}
}

pub fn bindings(&self) -> Vec<&P<TypeBinding>> {
pub fn bindings(&self) -> Vec<&TypeBinding> {
match *self {
PathParameters::AngleBracketed(ref data) => {
data.bindings.iter().collect()
Expand All @@ -308,7 +308,7 @@ pub struct AngleBracketedParameterData {
pub types: P<[P<Ty>]>,
/// Bindings (equality constraints) on associated types, if present.
/// e.g., `Foo<A=Bar>`.
pub bindings: P<[P<TypeBinding>]>,
pub bindings: P<[TypeBinding]>,
}

impl AngleBracketedParameterData {
Expand Down Expand Up @@ -508,7 +508,7 @@ impl PartialEq for MetaItemKind {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Block {
/// Statements in a block
pub stmts: Vec<P<Stmt>>,
pub stmts: Vec<Stmt>,
/// An expression at the end of the block
/// without a semicolon, if any
pub expr: Option<P<Expr>>,
Expand Down Expand Up @@ -1716,12 +1716,12 @@ pub struct Mod {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ForeignMod {
pub abi: Abi,
pub items: Vec<P<ForeignItem>>,
pub items: Vec<ForeignItem>,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct EnumDef {
pub variants: Vec<P<Variant>>,
pub variants: Vec<Variant>,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down Expand Up @@ -1988,7 +1988,7 @@ pub enum ItemKind {
Trait(Unsafety,
Generics,
TyParamBounds,
Vec<P<TraitItem>>),
Vec<TraitItem>),

// Default trait implementations
///
Expand All @@ -2000,7 +2000,7 @@ pub enum ItemKind {
Generics,
Option<TraitRef>, // (optional) trait this impl implements
P<Ty>, // self
Vec<P<ImplItem>>),
Vec<ImplItem>),
/// A macro invocation (which includes macro definition)
Mac(Mac),
}
Expand Down
31 changes: 14 additions & 17 deletions src/libsyntax/config.rs
Expand Up @@ -72,7 +72,7 @@ impl<'a, F> fold::Folder for Context<'a, F> where F: FnMut(&[ast::Attribute]) ->
fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
fold_opt_expr(self, expr)
}
fn fold_stmt(&mut self, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>> {
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
fold_stmt(self, stmt)
}
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
Expand All @@ -95,8 +95,8 @@ pub fn strip_items<'a, F>(diagnostic: &'a Handler,
}

fn filter_foreign_item<F>(cx: &mut Context<F>,
item: P<ast::ForeignItem>)
-> Option<P<ast::ForeignItem>> where
item: ast::ForeignItem)
-> Option<ast::ForeignItem> where
F: FnMut(&[ast::Attribute]) -> bool
{
if foreign_item_in_cfg(cx, &item) {
Expand Down Expand Up @@ -153,18 +153,15 @@ fn fold_item_kind<F>(cx: &mut Context<F>, item: ast::ItemKind) -> ast::ItemKind
if !(cx.in_cfg)(&v.node.attrs) {
None
} else {
Some(v.map(|Spanned {node: ast::Variant_ {name, attrs, data,
disr_expr}, span}| {
Spanned {
node: ast::Variant_ {
name: name,
attrs: attrs,
data: fold_struct(cx, data),
disr_expr: disr_expr,
},
span: span
}
}))
Some(Spanned {
node: ast::Variant_ {
name: v.node.name,
attrs: v.node.attrs,
data: fold_struct(cx, v.node.data),
disr_expr: v.node.disr_expr,
},
span: v.span
})
}
});
ast::ItemKind::Enum(ast::EnumDef {
Expand Down Expand Up @@ -225,11 +222,11 @@ fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr> where
})
}

fn fold_stmt<F>(cx: &mut Context<F>, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>>
fn fold_stmt<F>(cx: &mut Context<F>, stmt: ast::Stmt) -> SmallVector<ast::Stmt>
where F: FnMut(&[ast::Attribute]) -> bool
{
if stmt_in_cfg(cx, &stmt) {
stmt.and_then(|s| fold::noop_fold_stmt(s, cx))
fold::noop_fold_stmt(stmt, cx)
} else {
SmallVector::zero()
}
Expand Down
32 changes: 16 additions & 16 deletions src/libsyntax/ext/base.rs
Expand Up @@ -82,16 +82,16 @@ impl Annotatable {
}
}

pub fn expect_trait_item(self) -> P<ast::TraitItem> {
pub fn expect_trait_item(self) -> ast::TraitItem {
match self {
Annotatable::TraitItem(i) => i,
Annotatable::TraitItem(i) => i.unwrap(),
_ => panic!("expected Item")
}
}

pub fn expect_impl_item(self) -> P<ast::ImplItem> {
pub fn expect_impl_item(self) -> ast::ImplItem {
match self {
Annotatable::ImplItem(i) => i,
Annotatable::ImplItem(i) => i.unwrap(),
_ => panic!("expected Item")
}
}
Expand Down Expand Up @@ -204,8 +204,8 @@ impl<F> IdentMacroExpander for F
macro_rules! make_stmts_default {
($me:expr) => {
$me.make_expr().map(|e| {
SmallVector::one(P(codemap::respan(
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID))))
SmallVector::one(codemap::respan(
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID)))
})
}
}
Expand All @@ -223,7 +223,7 @@ pub trait MacResult {
}

/// Create zero or more impl items.
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<P<ast::ImplItem>>> {
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
None
}

Expand All @@ -236,7 +236,7 @@ pub trait MacResult {
///
/// By default this attempts to create an expression statement,
/// returning None if that fails.
fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
make_stmts_default!(self)
}

Expand Down Expand Up @@ -273,8 +273,8 @@ make_MacEager! {
expr: P<ast::Expr>,
pat: P<ast::Pat>,
items: SmallVector<P<ast::Item>>,
impl_items: SmallVector<P<ast::ImplItem>>,
stmts: SmallVector<P<ast::Stmt>>,
impl_items: SmallVector<ast::ImplItem>,
stmts: SmallVector<ast::Stmt>,
ty: P<ast::Ty>,
}

Expand All @@ -287,11 +287,11 @@ impl MacResult for MacEager {
self.items
}

fn make_impl_items(self: Box<Self>) -> Option<SmallVector<P<ast::ImplItem>>> {
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
self.impl_items
}

fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
match self.stmts.as_ref().map_or(0, |s| s.len()) {
0 => make_stmts_default!(self),
_ => self.stmts,
Expand Down Expand Up @@ -391,19 +391,19 @@ impl MacResult for DummyResult {
}
}

fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::ImplItem>>> {
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<ast::ImplItem>> {
if self.expr_only {
None
} else {
Some(SmallVector::zero())
}
}

fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
Some(SmallVector::one(P(
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<ast::Stmt>> {
Some(SmallVector::one(
codemap::respan(self.span,
ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
ast::DUMMY_NODE_ID)))))
ast::DUMMY_NODE_ID))))
}
}

Expand Down

0 comments on commit c7640aa

Please sign in to comment.