Add support for methods

This commit is contained in:
Hirochika Matsumoto 2020-10-18 16:53:18 +09:00
parent 2f85aa736e
commit 12474c62ff
3 changed files with 37 additions and 2 deletions

View file

@ -64,7 +64,11 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
hir_id: HirId,
) {
match fn_kind {
FnKind::ItemFn(.., visibility, _) if visibility.node.is_pub() => return,
FnKind::ItemFn(.., visibility, _) | FnKind::Method(.., Some(visibility), _) => {
if visibility.node.is_pub() {
return;
}
},
FnKind::Closure(..) => return,
_ => (),
}

View file

@ -76,6 +76,20 @@ fn func9(a: bool) -> Result<i32, ()> {
Err(())
}
struct A;
impl A {
// should not be linted
pub fn func10() -> Option<i32> {
Some(1)
}
// should be linted
fn func11() -> Option<i32> {
Some(1)
}
}
fn main() {
// method calls are not linted
func1(true, true);

View file

@ -85,5 +85,22 @@ help: ...and change the returning expressions
LL | 1
|
error: aborting due to 4 previous errors
error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wrap.rs:88:5
|
LL | / fn func11() -> Option<i32> {
LL | | Some(1)
LL | | }
| |_____^
|
help: remove `Option` from the return type...
|
LL | fn func11() -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | 1
|
error: aborting due to 5 previous errors