mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Add support for methods
This commit is contained in:
parent
2f85aa736e
commit
12474c62ff
3 changed files with 37 additions and 2 deletions
|
@ -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,
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue