about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-11-09 10:02:39 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-11-09 10:42:58 -0800
commit5d55533f93c8cd8ab189d5da919ec9b2b456ae35 (patch)
treebcd7c6665e6ab6fe2736512e6a379f57a37fe92d /src/libsyntax
parent00aa3cbecc6723898a04467050891c26a7fdb758 (diff)
downloadrust-5d55533f93c8cd8ab189d5da919ec9b2b456ae35.tar.gz
rust-5d55533f93c8cd8ab189d5da919ec9b2b456ae35.zip
syntax: Use `let _` in #[derive(Debug)]
This should help avoid triggering the unused_results lint which can frequently
be turned on.

Closes #29710
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/deriving/debug.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/libsyntax/ext/deriving/debug.rs b/src/libsyntax/ext/deriving/debug.rs
index 8a180e6c093..2b2e5309883 100644
--- a/src/libsyntax/ext/deriving/debug.rs
+++ b/src/libsyntax/ext/deriving/debug.rs
@@ -9,8 +9,8 @@
 // except according to those terms.
 
 use ast;
-use ast::{MetaItem, Expr,};
-use codemap::Span;
+use ast::{MetaItem, Expr};
+use codemap::{Span, respan};
 use ext::base::{ExtCtxt, Annotatable};
 use ext::build::AstBuilder;
 use ext::deriving::generic::*;
@@ -97,7 +97,10 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
                                                    builder_expr.clone(),
                                                    token::str_to_ident("field"),
                                                    vec![field]);
-                    stmts.push(cx.stmt_expr(expr));
+
+                    // Use `let _ = expr;` to avoid triggering the
+                    // unused_results lint.
+                    stmts.push(stmt_let_undescore(cx, span, expr));
                 }
             } else {
                 // normal struct/struct variant
@@ -119,7 +122,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
                                                    builder_expr.clone(),
                                                    token::str_to_ident("field"),
                                                    vec![name, field]);
-                    stmts.push(cx.stmt_expr(expr));
+                    stmts.push(stmt_let_undescore(cx, span, expr));
                 }
             }
             stmts
@@ -135,3 +138,17 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
     let block = cx.block(span, stmts, Some(expr));
     cx.expr_block(block)
 }
+
+fn stmt_let_undescore(cx: &mut ExtCtxt,
+                      sp: Span,
+                      expr: P<ast::Expr>) -> P<ast::Stmt> {
+    let local = P(ast::Local {
+        pat: cx.pat_wild(sp),
+        ty: None,
+        init: Some(expr),
+        id: ast::DUMMY_NODE_ID,
+        span: sp,
+    });
+    let decl = respan(sp, ast::DeclLocal(local));
+    P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
+}