From 8c235d19bcb14518e79a789e546116b1990741cd Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 12 Jun 2017 18:36:36 -0700 Subject: [PATCH] `in_macro` check in `NEEDLESS_RETURN` 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 96b1e4e91857..65fcc6b1d707 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -3,7 +3,8 @@ use syntax::ast; 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 @@ impl ReturnPass { } 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,