Make lint skip macros

This commit is contained in:
Hirochika Matsumoto 2020-10-18 17:17:45 +09:00
parent 12474c62ff
commit c5447eb3c1
3 changed files with 12 additions and 6 deletions

View file

@ -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);

View file

@ -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)
}
}

View file

@ -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
|