Skip to content

Commit b13b041

Browse files
committed
Make lint skip macros
1 parent 3008cd5 commit b13b041

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

clippy_lints/src/unnecessary_wrap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
2+
in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
33
visitors::find_all_ret_expressions,
44
};
55
use if_chain::if_chain;
@@ -84,6 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
8484
let mut suggs = Vec::new();
8585
let can_sugg = find_all_ret_expressions(cx, &body.value, |ret_expr| {
8686
if_chain! {
87+
if !in_macro(ret_expr.span);
8788
if let ExprKind::Call(ref func, ref args) = ret_expr.kind;
8889
if let ExprKind::Path(ref qpath) = func.kind;
8990
if match_qpath(qpath, path);

tests/ui/unnecessary_wrap.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,21 @@ fn func9(a: bool) -> Result<i32, ()> {
7676
Err(())
7777
}
7878

79+
// should not be linted
80+
fn func10() -> Option<()> {
81+
unimplemented!()
82+
}
83+
7984
struct A;
8085

8186
impl A {
8287
// should not be linted
83-
pub fn func10() -> Option<i32> {
88+
pub fn func11() -> Option<i32> {
8489
Some(1)
8590
}
8691

8792
// should be linted
88-
fn func11() -> Option<i32> {
93+
fn func12() -> Option<i32> {
8994
Some(1)
9095
}
9196
}

tests/ui/unnecessary_wrap.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ LL | 1
8686
|
8787

8888
error: this function's return value is unnecessarily wrapped by `Option`
89-
--> $DIR/unnecessary_wrap.rs:88:5
89+
--> $DIR/unnecessary_wrap.rs:93:5
9090
|
91-
LL | / fn func11() -> Option<i32> {
91+
LL | / fn func12() -> Option<i32> {
9292
LL | | Some(1)
9393
LL | | }
9494
| |_____^
9595
|
9696
help: remove `Option` from the return type...
9797
|
98-
LL | fn func11() -> i32 {
98+
LL | fn func12() -> i32 {
9999
| ^^^
100100
help: ...and change the returning expressions
101101
|

0 commit comments

Comments
 (0)