Added FORCED_RETURN lint.

This commit is contained in:
daxpedda 2018-12-05 01:59:09 +01:00
parent 3f24cdf10f
commit d5d6692288
5 changed files with 211 additions and 1 deletions

55
tests/ui/forced_return.rs Normal file
View file

@ -0,0 +1,55 @@
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![warn(clippy::forced_return)]
fn test_end_of_fn() -> bool {
if true {
// no error!
return true;
}
true
}
#[allow(clippy::needless_bool)]
fn test_if_block() -> bool {
if true {
true
} else {
false
}
}
#[allow(clippy::match_bool)]
fn test_match(x: bool) -> bool {
match x {
true => false,
false => {
true
}
}
}
fn test_closure() {
let _ = || {
true
};
let _ = || true;
}
fn main() {
let _ = test_end_of_fn();
let _ = test_if_block();
let _ = test_match(true);
test_closure();
}

View file

@ -0,0 +1,46 @@
error: missing return statement
--> $DIR/forced_return.rs:21:5
|
21 | true
| ^^^^ help: add `return` as shown: `return true`
|
= note: `-D clippy::forced-return` implied by `-D warnings`
error: missing return statement
--> $DIR/forced_return.rs:27:9
|
27 | true
| ^^^^ help: add `return` as shown: `return true`
error: missing return statement
--> $DIR/forced_return.rs:29:9
|
29 | false
| ^^^^^ help: add `return` as shown: `return false`
error: missing return statement
--> $DIR/forced_return.rs:36:17
|
36 | true => false,
| ^^^^^ help: add `return` as shown: `return false`
error: missing return statement
--> $DIR/forced_return.rs:38:13
|
38 | true
| ^^^^ help: add `return` as shown: `return true`
error: missing return statement
--> $DIR/forced_return.rs:45:9
|
45 | true
| ^^^^ help: add `return` as shown: `return true`
error: missing return statement
--> $DIR/forced_return.rs:47:16
|
47 | let _ = || true;
| ^^^^ help: add `return` as shown: `return true`
error: aborting due to 7 previous errors