]> git.lizzy.rs Git - rust.git/commitdiff
`in_macro` check in `NEEDLESS_RETURN`
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 13 Jun 2017 01:36:36 +0000 (18:36 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Tue, 13 Jun 2017 02:06:37 +0000 (19:06 -0700)
This allows you to define a macro like `try!(...)` that embeds an
early exit without emitting the "needless_return" warning.

Closes #1271.

clippy_lints/src/returns.rs

index 96b1e4e91857f9184bd13f75b5d955b35aa0657c..65fcc6b1d70756de7b979acddd8bce5ec90303b6 100644 (file)
@@ -3,7 +3,8 @@
 use syntax::codemap::{Span, Spanned};
 use syntax::visit::FnKind;
 
-use utils::{span_note_and_lint, span_lint_and_then, snippet_opt, match_path_ast, in_external_macro};
+use utils::{span_note_and_lint, span_lint_and_then, snippet_opt, match_path_ast, in_macro,
+            in_external_macro};
 
 /// **What it does:** Checks for return statements at the end of a block.
 ///
@@ -89,7 +90,7 @@ fn check_final_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr, span: Option
     }
 
     fn emit_return_lint(&mut self, cx: &EarlyContext, ret_span: Span, inner_span: Span) {
-        if in_external_macro(cx, inner_span) {
+        if in_external_macro(cx, inner_span) || in_macro(inner_span) {
             return;
         }
         span_lint_and_then(cx,