Skip to content

Commit 906b516

Browse files
author
A.A.Abroskin
committed
change assert_checks to assertions_on_constants
1 parent 9605861 commit 906b516

10 files changed

+51
-60
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ All notable changes to this project will be documented in this file.
616616
[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons
617617
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
618618
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
619+
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
619620
[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
620621
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
621622
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
@@ -679,10 +680,8 @@ All notable changes to this project will be documented in this file.
679680
[`expect_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
680681
[`expl_impl_clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#expl_impl_clone_on_copy
681682
[`explicit_counter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_counter_loop
682-
[`explicit_false`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_false
683683
[`explicit_into_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop
684684
[`explicit_iter_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop
685-
[`explicit_true`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_true
686685
[`explicit_write`]: https://rust-lang.github.io/rust-clippy/master/index.html#explicit_write
687686
[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice
688687
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

1010
<<<<<<< HEAD
11-
[There are 290 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
11+
[There are 291 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1212
||||||| merged common ancestors
1313
[There are 291 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1414
=======
15-
[There are 293 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
15+
[There are 291 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1616
>>>>>>> run ./util/dev update_lints
1717
1818
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:

clippy_lints/src/assert_checks.rs renamed to clippy_lints/src/assertions_on_constants.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,40 @@ use crate::rustc::hir::{Expr, ExprKind};
1111
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1212
use crate::rustc::{declare_tool_lint, lint_array};
1313
use crate::syntax::ast::LitKind;
14-
use crate::utils::{is_direct_expn_of, span_lint};
14+
use crate::utils::{is_direct_expn_of, span_lint, span_lint_and_sugg};
15+
use rustc_errors::Applicability;
1516
use if_chain::if_chain;
1617

17-
/// **What it does:** Check explicit call assert!(true)
18+
/// **What it does:** Check explicit call assert!(true/false)
1819
///
19-
/// **Why is this bad?** Will be optimized out by the compiler
20-
///
21-
/// **Known problems:** None
22-
///
23-
/// **Example:**
24-
/// ```rust
25-
/// assert!(true)
26-
/// ```
27-
declare_clippy_lint! {
28-
pub EXPLICIT_TRUE,
29-
correctness,
30-
"assert!(true) will be optimized out by the compiler"
31-
}
32-
33-
/// **What it does:** Check explicit call assert!(false)
34-
///
35-
/// **Why is this bad?** Should probably be replaced by a panic!() or unreachable!()
20+
/// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a panic!() or unreachable!()
3621
///
3722
/// **Known problems:** None
3823
///
3924
/// **Example:**
4025
/// ```rust
4126
/// assert!(false)
27+
/// // or
28+
/// assert!(true)
29+
/// // or
30+
/// const B: bool = false;
31+
/// assert!(B)
4232
/// ```
4333
declare_clippy_lint! {
44-
pub EXPLICIT_FALSE,
45-
correctness,
46-
"assert!(false) should probably be replaced by a panic!() or unreachable!()"
34+
pub ASSERTIONS_ON_CONSTANTS,
35+
style,
36+
"assert!(true/false) will be optimized out by the compiler/should probably be replaced by a panic!() or unreachable!()"
4737
}
4838

49-
pub struct AssertChecks;
39+
pub struct AssertionsOnConstants;
5040

51-
impl LintPass for AssertChecks {
41+
impl LintPass for AssertionsOnConstants {
5242
fn get_lints(&self) -> LintArray {
53-
lint_array![EXPLICIT_TRUE, EXPLICIT_FALSE]
43+
lint_array![ASSERTIONS_ON_CONSTANTS]
5444
}
5545
}
5646

57-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertChecks {
47+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5848
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
5949
if_chain! {
6050
if is_direct_expn_of(e.span, "assert").is_some();
@@ -63,12 +53,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertChecks {
6353
then {
6454
match inner.node {
6555
LitKind::Bool(true) => {
66-
span_lint(cx, EXPLICIT_TRUE, e.span,
56+
span_lint(cx, ASSERTIONS_ON_CONSTANTS, e.span,
6757
"assert!(true) will be optimized out by the compiler");
6858
},
6959
LitKind::Bool(false) => {
70-
span_lint(cx, EXPLICIT_FALSE, e.span,
71-
"assert!(false) should probably be replaced by a panic!() or unreachable!()");
60+
span_lint_and_sugg(
61+
cx,
62+
ASSERTIONS_ON_CONSTANTS,
63+
e.span,
64+
"assert!(false) should probably be replaced",
65+
"try",
66+
"panic!()".to_string(),
67+
Applicability::MachineApplicable);
7268
},
7369
_ => (),
7470
}

clippy_lints/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod utils;
8888
// begin lints modules, do not remove this comment, it’s used in `update_lints`
8989
pub mod approx_const;
9090
pub mod arithmetic;
91-
pub mod assert_checks;
91+
pub mod assertions_on_constants;
9292
pub mod assign_ops;
9393
pub mod attrs;
9494
pub mod bit_mask;
@@ -487,7 +487,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
487487
reg.register_late_lint_pass(box ptr_offset_with_cast::Pass);
488488
reg.register_late_lint_pass(box redundant_clone::RedundantClone);
489489
reg.register_late_lint_pass(box slow_vector_initialization::Pass);
490-
reg.register_late_lint_pass(box assert_checks::AssertChecks);
490+
reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants);
491491

492492
reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![
493493
arithmetic::FLOAT_ARITHMETIC,
@@ -565,8 +565,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
565565

566566
reg.register_lint_group("clippy::all", Some("clippy"), vec![
567567
approx_const::APPROX_CONSTANT,
568-
assert_checks::EXPLICIT_FALSE,
569-
assert_checks::EXPLICIT_TRUE,
568+
assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
570569
assign_ops::ASSIGN_OP_PATTERN,
571570
assign_ops::MISREFACTORED_ASSIGN_OP,
572571
attrs::DEPRECATED_CFG_ATTR,
@@ -788,6 +787,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
788787
]);
789788

790789
reg.register_lint_group("clippy::style", Some("clippy_style"), vec![
790+
assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
791791
assign_ops::ASSIGN_OP_PATTERN,
792792
attrs::UNKNOWN_CLIPPY_LINTS,
793793
bit_mask::VERBOSE_BIT_MASK,
@@ -944,8 +944,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
944944

945945
reg.register_lint_group("clippy::correctness", Some("clippy_correctness"), vec![
946946
approx_const::APPROX_CONSTANT,
947-
assert_checks::EXPLICIT_FALSE,
948-
assert_checks::EXPLICIT_TRUE,
949947
attrs::DEPRECATED_SEMVER,
950948
attrs::USELESS_ATTRIBUTE,
951949
bit_mask::BAD_BIT_MASK,

tests/ui/assert_checks.stderr

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: assert!(true) will be optimized out by the compiler
2+
--> $DIR/assertions_on_constants.rs:11:5
3+
|
4+
LL | assert!(true);
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
8+
9+
error: assert!(false) should probably be replaced
10+
--> $DIR/assertions_on_constants.rs:12:5
11+
|
12+
LL | assert!(false);
13+
| ^^^^^^^^^^^^^^^ help: try: `panic!()`
14+
15+
error: aborting due to 2 previous errors
16+

tests/ui/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// except according to those terms.
99

1010
#![warn(clippy::inline_always, clippy::deprecated_semver)]
11-
#![allow(clippy::assert_checks::explicit_true)]
11+
#![allow(clippy::assertions_on_constants::assertions_on_constants)]
1212
#[inline(always)]
1313
fn test_attr_lint() {
1414
assert!(true)

tests/ui/empty_line_after_outer_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// except according to those terms.
99

1010
#![warn(clippy::empty_line_after_outer_attr)]
11-
#![allow(clippy::assert_checks::explicit_true)]
11+
#![allow(clippy::assertions_on_constants::assertions_on_constants)]
1212
// This should produce a warning
1313
#[crate_type = "lib"]
1414

tests/ui/panic_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// except according to those terms.
99

1010
#![warn(clippy::panic_params, clippy::unimplemented)]
11-
#![allow(clippy::assert_checks::explicit_true)]
11+
#![allow(clippy::assertions_on_constants::assertions_on_constants)]
1212
fn missing() {
1313
if true {
1414
panic!("{}");

0 commit comments

Comments
 (0)