about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHirochika Matsumoto <matsujika@gmail.com>2020-10-18 17:17:45 +0900
committerHirochika Matsumoto <matsujika@gmail.com>2020-11-18 01:28:37 +0900
commitc5447eb3c167025fcc1b842fabd7bb43a2eb1e9e (patch)
treed4da3646d8aa352530c0795407321c6a9a2cc9cb
parent12474c62ff89ab122c2e6881b00680913fdf1d35 (diff)
downloadrust-c5447eb3c167025fcc1b842fabd7bb43a2eb1e9e.tar.gz
rust-c5447eb3c167025fcc1b842fabd7bb43a2eb1e9e.zip
Make lint skip macros
-rw-r--r--clippy_lints/src/unnecessary_wrap.rs3
-rw-r--r--tests/ui/unnecessary_wrap.rs9
-rw-r--r--tests/ui/unnecessary_wrap.stderr6
3 files changed, 12 insertions, 6 deletions
diff --git a/clippy_lints/src/unnecessary_wrap.rs b/clippy_lints/src/unnecessary_wrap.rs
index 365e9c9984e..7ec523293c8 100644
--- a/clippy_lints/src/unnecessary_wrap.rs
+++ b/clippy_lints/src/unnecessary_wrap.rs
@@ -1,5 +1,5 @@
 use crate::utils::{
-    is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
+    in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
     visitors::find_all_ret_expressions,
 };
 use if_chain::if_chain;
@@ -84,6 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
         let mut suggs = Vec::new();
         let can_sugg = find_all_ret_expressions(cx, &body.value, |ret_expr| {
             if_chain! {
+                if !in_macro(ret_expr.span);
                 if let ExprKind::Call(ref func, ref args) = ret_expr.kind;
                 if let ExprKind::Path(ref qpath) = func.kind;
                 if match_qpath(qpath, path);
diff --git a/tests/ui/unnecessary_wrap.rs b/tests/ui/unnecessary_wrap.rs
index 0ced20b7a56..618c452065b 100644
--- a/tests/ui/unnecessary_wrap.rs
+++ b/tests/ui/unnecessary_wrap.rs
@@ -76,16 +76,21 @@ fn func9(a: bool) -> Result<i32, ()> {
     Err(())
 }
 
+// should not be linted
+fn func10() -> Option<()> {
+    unimplemented!()
+}
+
 struct A;
 
 impl A {
     // should not be linted
-    pub fn func10() -> Option<i32> {
+    pub fn func11() -> Option<i32> {
         Some(1)
     }
 
     // should be linted
-    fn func11() -> Option<i32> {
+    fn func12() -> Option<i32> {
         Some(1)
     }
 }
diff --git a/tests/ui/unnecessary_wrap.stderr b/tests/ui/unnecessary_wrap.stderr
index dbc5748c29e..5f21b74bc76 100644
--- a/tests/ui/unnecessary_wrap.stderr
+++ b/tests/ui/unnecessary_wrap.stderr
@@ -86,16 +86,16 @@ LL |     1
    |
 
 error: this function's return value is unnecessarily wrapped by `Option`
-  --> $DIR/unnecessary_wrap.rs:88:5
+  --> $DIR/unnecessary_wrap.rs:93:5
    |
-LL | /     fn func11() -> Option<i32> {
+LL | /     fn func12() -> Option<i32> {
 LL | |         Some(1)
 LL | |     }
    | |_____^
    |
 help: remove `Option` from the return type...
    |
-LL |     fn func11() -> i32 {
+LL |     fn func12() -> i32 {
    |                    ^^^
 help: ...and change the returning expressions
    |