diff options
| author | Kiet Tran <ktt3ja@gmail.com> | 2013-12-08 02:55:27 -0500 |
|---|---|---|
| committer | Kiet Tran <ktt3ja@gmail.com> | 2013-12-08 02:55:27 -0500 |
| commit | c06dd0e0afb4b78ab4e482a7488adcf1c865bd19 (patch) | |
| tree | 4850d80648a57d527feda65f921bdf47940111f8 /src/libsyntax | |
| parent | 49b751dda19af57a2545a67879dd217e601b84c6 (diff) | |
| download | rust-c06dd0e0afb4b78ab4e482a7488adcf1c865bd19.tar.gz rust-c06dd0e0afb4b78ab4e482a7488adcf1c865bd19.zip | |
Add dead-code warning pass
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 42 | ||||
| -rw-r--r-- | src/libsyntax/ext/format.rs | 7 |
2 files changed, 9 insertions, 40 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4bb35457182..a6e45c7e1bb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{P, Block, Crate, DeclLocal, Expr_, ExprMac, SyntaxContext}; +use ast::{P, Block, Crate, DeclLocal, ExprMac, SyntaxContext}; use ast::{Local, Ident, mac_invoc_tt}; use ast::{item_mac, Mrk, Stmt, StmtDecl, StmtMac, StmtExpr, StmtSemi}; use ast::{token_tree}; @@ -21,7 +21,6 @@ use codemap; use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use ext::base::*; use fold::*; -use opt_vec; use parse; use parse::{parse_item_from_source_str}; use parse::token; @@ -140,29 +139,6 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, let span = e.span; - fn mk_expr(_: @ExtCtxt, span: Span, node: Expr_) - -> @ast::Expr { - @ast::Expr { - id: ast::DUMMY_NODE_ID, - node: node, - span: span, - } - } - - fn mk_simple_path(ident: ast::Ident, span: Span) -> ast::Path { - ast::Path { - span: span, - global: false, - segments: ~[ - ast::PathSegment { - identifier: ident, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, - } - ], - } - } - // to: // // { @@ -714,14 +690,6 @@ pub fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold { } as @ast_fold } -// perform a bunch of renames -fn apply_pending_renames(folder : @ast_fold, stmt : ast::Stmt) -> @ast::Stmt { - folder.fold_stmt(&stmt) - .expect_one("renaming of stmt did not produce one stmt") -} - - - pub fn new_span(cx: @ExtCtxt, sp: Span) -> Span { /* this discards information in the case of macro-defining macros */ Span { @@ -739,6 +707,7 @@ pub fn std_macros() -> @str { @r#"mod __std_macros { #[macro_escape]; #[doc(hidden)]; + #[allow(dead_code)]; macro_rules! ignore (($($x:tt)*) => (())) @@ -900,6 +869,7 @@ pub fn std_macros() -> @str { mod $c { #[allow(unused_imports)]; #[allow(non_uppercase_statics)]; + #[allow(dead_code)]; use super::*; @@ -979,12 +949,6 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess, injector.fold_crate(c) } -struct NoOpFolder { - contents: (), -} - -impl ast_fold for NoOpFolder {} - pub struct MacroExpander { extsbox: @mut SyntaxEnv, cx: @ExtCtxt, diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index f6fb521ff7c..9193a9cee17 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -331,7 +331,12 @@ impl Context { let unnamed = self.ecx.meta_word(self.fmtsp, @"address_insignificant"); let unnamed = self.ecx.attribute(self.fmtsp, unnamed); - return ~[unnamed]; + // Do not warn format string as dead code + let dead_code = self.ecx.meta_word(self.fmtsp, @"dead_code"); + let allow_dead_code = self.ecx.meta_list(self.fmtsp, + @"allow", ~[dead_code]); + let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code); + return ~[unnamed, allow_dead_code]; } /// Translate a `parse::Piece` to a static `rt::Piece` |
