From ba43c228b55d9620d3d480246ee2d9295484a336 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 30 Sep 2015 17:18:09 +1300 Subject: [PATCH] Some cleanup of no longer used AST things --- src/librustc_front/lowering.rs | 17 +++-------------- src/librustc_lint/unused.rs | 2 +- src/librustdoc/core.rs | 3 +-- src/librustdoc/test.rs | 3 +-- src/libsyntax/ast.rs | 13 ++----------- src/libsyntax/codemap.rs | 22 ---------------------- src/libsyntax/config.rs | 4 ++-- src/libsyntax/diagnostic.rs | 1 - src/libsyntax/ext/base.rs | 7 ++----- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/fold.rs | 5 ++--- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/visit.rs | 2 +- 14 files changed, 19 insertions(+), 68 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 27ae39acbf4..546b298a92b 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -955,8 +955,8 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // 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::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 { } } -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, diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 9c030d8892a..6eee6872be2 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index f62148c16fa..2ab4e6b9299 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -135,8 +135,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec, 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); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index dec2ed789e0..0dafc89a798 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 02cd648b6d8..34b99ab8cce 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -855,9 +855,8 @@ pub enum Expr_ { /// /// `'label: loop { block }` ExprLoop(P, Option), - /// 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, Vec, MatchSource), + /// A `match` block. + ExprMatch(P, Vec), /// A closure (for example, `move |a, b, c| {a + b + c}`) ExprClosure(CaptureClause, P, P), /// 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, diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index aa4dd1d53c5..a73fd4534c9 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -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()), } } } diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 889a0d7e440..2d266be3242 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -225,10 +225,10 @@ fn fold_expr(cx: &mut Context, expr: P) -> P 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 }, diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 6b4a5538501..2a8cdf138b0 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -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 { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index aaaca8bd4d8..a3df7727598 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -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() { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a20080dcbf0..efea85f9162 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -868,7 +868,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_match(&self, span: Span, arg: P, arms: Vec) -> P { - 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, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 914b08265fe..3c1aa992a3c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1256,10 +1256,9 @@ pub fn noop_fold_expr(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, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f47dfeb1d34..443cea696b6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 405fd9b8cc7..f5f3907a4e6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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")); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 67e4927a52f..091580b9bd8 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); }