Do not trigger let_and_return lint on macros

This commit is contained in:
Yuki Okushi 2020-01-07 05:26:20 +09:00
parent e8642c7a29
commit 2213989a01
2 changed files with 24 additions and 1 deletions

View File

@ -8,7 +8,7 @@ use rustc_span::BytePos;
use syntax::ast;
use syntax::visit::FnKind;
use crate::utils::{match_path_ast, snippet_opt, span_lint_and_then};
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then};
declare_clippy_lint! {
/// **What it does:** Checks for return statements at the end of a block.
@ -205,6 +205,7 @@ impl Return {
if !in_external_macro(cx.sess(), initexpr.span);
if !in_external_macro(cx.sess(), retexpr.span);
if !in_external_macro(cx.sess(), local.span);
if !in_macro(local.span);
then {
span_lint_and_then(
cx,

View File

@ -45,4 +45,26 @@ fn test_nowarn_5(x: i16) -> u16 {
x
}
// False positive example
trait Decode {
fn decode<D: std::io::Read>(d: D) -> Result<Self, ()>
where
Self: Sized;
}
macro_rules! tuple_encode {
($($x:ident),*) => (
impl<$($x: Decode),*> Decode for ($($x),*) {
#[inline]
#[allow(non_snake_case)]
fn decode<D: std::io::Read>(mut d: D) -> Result<Self, ()> {
// Shouldn't trigger lint
Ok(($({let $x = Decode::decode(&mut d)?; $x }),*))
}
}
);
}
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
fn main() {}