Some cleanup of no longer used AST things

This commit is contained in:
Nick Cameron 2015-09-30 17:18:09 +13:00
parent 21205f4f9e
commit ba43c228b5
14 changed files with 19 additions and 68 deletions

View File

@ -955,8 +955,8 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
// might be `if let`.
ExprIf(ref cond, ref blk, ref else_opt) => {
let else_opt = else_opt.as_ref().map(|els| match els.node {
let _old_cached = CachedIdSetter::new(lctx, e.id);
ExprIfLet(..) => {
let _old_cached = CachedIdSetter::new(lctx, e.id);
// wrap the if-let expr in a block
let span = els.span;
let blk = P(hir::Block {
@ -984,10 +984,10 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
hir::ExprLoop(lower_block(lctx, body),
opt_ident)
}
ExprMatch(ref expr, ref arms, ref source) => {
ExprMatch(ref expr, ref arms) => {
hir::ExprMatch(lower_expr(lctx, expr),
arms.iter().map(|x| lower_arm(lctx, x)).collect(),
lower_match_source(lctx, source))
hir::MatchSource::Normal)
}
ExprClosure(capture_clause, ref decl, ref body) => {
hir::ExprClosure(lower_capture_clause(lctx, capture_clause),
@ -1310,17 +1310,6 @@ pub fn lower_stmt(_lctx: &LoweringContext, s: &Stmt) -> P<hir::Stmt> {
}
}
pub fn lower_match_source(_lctx: &LoweringContext, m: &MatchSource) -> hir::MatchSource {
match *m {
MatchSource::Normal => hir::MatchSource::Normal,
MatchSource::IfLetDesugar { contains_else_clause } => {
hir::MatchSource::IfLetDesugar { contains_else_clause: contains_else_clause }
}
MatchSource::WhileLetDesugar => hir::MatchSource::WhileLetDesugar,
MatchSource::ForLoopDesugar => hir::MatchSource::ForLoopDesugar,
}
}
pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureClause) -> hir::CaptureClause {
match c {
CaptureByValue => hir::CaptureByValue,

View File

@ -366,7 +366,7 @@ impl EarlyLintPass for UnusedParens {
ast::ExprIfLet(_, ref cond, _, _) => (cond, "`if let` head expression", true),
ast::ExprWhileLet(_, ref cond, _, _) => (cond, "`while let` head expression", true),
ast::ExprForLoop(_, ref cond, _, _) => (cond, "`for` head expression", true),
ast::ExprMatch(ref head, _, _) => (head, "`match` head expression", true),
ast::ExprMatch(ref head, _) => (head, "`match` head expression", true),
ast::ExprRet(Some(ref value)) => (value, "`return` value", false),
ast::ExprAssign(_, ref value) => (value, "assigned value", false),
ast::ExprAssignOp(_, _, ref value) => (value, "assigned value", false),

View File

@ -135,8 +135,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
let krate = driver::assign_node_ids(&sess, krate);
// Lower ast -> hir.
let foo = &42;
let lcx = LoweringContext::new(foo, &sess, &krate);
let lcx = LoweringContext::new(&sess, &krate);
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
let arenas = ty::CtxtArenas::new();
let hir_map = driver::make_map(&sess, &mut hir_forest);

View File

@ -83,8 +83,7 @@ pub fn run(input: &str,
"rustdoc-test", None)
.expect("phase_2_configure_and_expand aborted in rustdoc!");
let krate = driver::assign_node_ids(&sess, krate);
let foo = &42;
let lcx = LoweringContext::new(foo, &sess, &krate);
let lcx = LoweringContext::new(&sess, &krate);
let krate = lower_crate(&lcx, &krate);
let opts = scrape_test_config(&krate);

View File

@ -855,9 +855,8 @@ pub enum Expr_ {
///
/// `'label: loop { block }`
ExprLoop(P<Block>, Option<Ident>),
/// A `match` block, with a source that indicates whether or not it is
/// the result of a desugaring, and if so, which kind.
ExprMatch(P<Expr>, Vec<Arm>, MatchSource),
/// A `match` block.
ExprMatch(P<Expr>, Vec<Arm>),
/// A closure (for example, `move |a, b, c| {a + b + c}`)
ExprClosure(CaptureClause, P<FnDecl>, P<Block>),
/// A block (`{ ... }`)
@ -936,14 +935,6 @@ pub struct QSelf {
pub position: usize
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum MatchSource {
Normal,
IfLetDesugar { contains_else_clause: bool },
WhileLetDesugar,
ForLoopDesugar,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum CaptureClause {
CaptureByValue,

View File

@ -29,7 +29,6 @@ use std::io::{self, Read};
use serialize::{Encodable, Decodable, Encoder, Decoder};
use parse::token::intern;
use ast::Name;
// _____________________________________________________________________________
@ -269,28 +268,8 @@ pub enum ExpnFormat {
MacroAttribute(Name),
/// e.g. `format!()`
MacroBang(Name),
/// Syntax sugar expansion performed by the compiler (libsyntax::expand).
CompilerExpansion(CompilerExpansionFormat),
}
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
pub enum CompilerExpansionFormat {
IfLet,
PlacementIn,
WhileLet,
ForLoop,
}
impl CompilerExpansionFormat {
pub fn name(self) -> &'static str {
match self {
CompilerExpansionFormat::IfLet => "if let expansion",
CompilerExpansionFormat::PlacementIn => "placement-in expansion",
CompilerExpansionFormat::WhileLet => "while let expansion",
CompilerExpansionFormat::ForLoop => "for loop expansion",
}
}
}
#[derive(Clone, Hash, Debug)]
pub struct NameAndSpan {
/// The format with which the macro was invoked.
@ -310,7 +289,6 @@ impl NameAndSpan {
match self.format {
ExpnFormat::MacroAttribute(s) => s,
ExpnFormat::MacroBang(s) => s,
ExpnFormat::CompilerExpansion(ce) => intern(ce.name()),
}
}
}

View File

@ -225,10 +225,10 @@ fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr> where
fold::noop_fold_expr(ast::Expr {
id: id,
node: match node {
ast::ExprMatch(m, arms, source) => {
ast::ExprMatch(m, arms) => {
ast::ExprMatch(m, arms.into_iter()
.filter(|a| (cx.in_cfg)(&a.attrs))
.collect(), source)
.collect())
}
_ => node
},

View File

@ -737,7 +737,6 @@ impl EmitterWriter {
let (pre, post) = match ei.callee.format {
codemap::MacroAttribute(..) => ("#[", "]"),
codemap::MacroBang(..) => ("", "!"),
codemap::CompilerExpansion(..) => ("", ""),
};
// Don't print recursive invocations
if ei.call_site != last_span {

View File

@ -13,7 +13,7 @@ pub use self::SyntaxExtension::*;
use ast;
use ast::Name;
use codemap;
use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION, CompilerExpansion};
use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION};
use ext;
use ext::expand;
use ext::tt::macro_rules;
@ -651,10 +651,7 @@ impl<'a> ExtCtxt<'a> {
return None;
}
expn_id = i.call_site.expn_id;
match i.callee.format {
CompilerExpansion(..) => (),
_ => last_macro = Some(i.call_site),
}
last_macro = Some(i.call_site);
return Some(());
})
}).is_none() {

View File

@ -868,7 +868,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
self.expr(span, ast::ExprMatch(arg, arms, ast::MatchSource::Normal))
self.expr(span, ast::ExprMatch(arg, arms))
}
fn expr_if(&self, span: Span, cond: P<ast::Expr>,

View File

@ -1256,10 +1256,9 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
ExprLoop(folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
}
ExprMatch(expr, arms, source) => {
ExprMatch(expr, arms) => {
ExprMatch(folder.fold_expr(expr),
arms.move_map(|x| folder.fold_arm(x)),
source)
arms.move_map(|x| folder.fold_arm(x)))
}
ExprClosure(capture_clause, decl, body) => {
ExprClosure(capture_clause,

View File

@ -37,7 +37,7 @@ use ast::{LifetimeDef, Lit, Lit_};
use ast::{LitBool, LitChar, LitByte, LitByteStr};
use ast::{LitStr, LitInt, Local};
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
use ast::{MutImmutable, MutMutable, Mac_, MatchSource};
use ast::{MutImmutable, MutMutable, Mac_};
use ast::{MutTy, BiMul, Mutability};
use ast::{MethodImplItem, NamedField, UnNeg, NoReturn, UnNot};
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange};
@ -2927,7 +2927,7 @@ impl<'a> Parser<'a> {
}
let hi = self.span.hi;
try!(self.bump());
return Ok(self.mk_expr(lo, hi, ExprMatch(discriminant, arms, MatchSource::Normal)));
return Ok(self.mk_expr(lo, hi, ExprMatch(discriminant, arms)));
}
pub fn parse_arm_nopanic(&mut self) -> PResult<Arm> {

View File

@ -2045,7 +2045,7 @@ impl<'a> State<'a> {
try!(space(&mut self.s));
try!(self.print_block(&**blk));
}
ast::ExprMatch(ref expr, ref arms, _) => {
ast::ExprMatch(ref expr, ref arms) => {
try!(self.cbox(indent_unit));
try!(self.ibox(4));
try!(self.word_nbsp("match"));

View File

@ -731,7 +731,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
visitor.visit_block(block);
walk_opt_ident(visitor, expression.span, opt_ident)
}
ExprMatch(ref subexpression, ref arms, _) => {
ExprMatch(ref subexpression, ref arms) => {
visitor.visit_expr(subexpression);
walk_list!(visitor, visit_arm, arms);
}