new lint legacy_numeric_constants
This commit is contained in:
parent
9d6f41691e
commit
0c392d918a
22 changed files with 921 additions and 37 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(
|
||||
clippy::cast_lossless,
|
||||
clippy::legacy_numeric_constants,
|
||||
unused,
|
||||
// Int::max_value will be deprecated in the future
|
||||
deprecated,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(
|
||||
clippy::cast_lossless,
|
||||
clippy::legacy_numeric_constants,
|
||||
unused,
|
||||
// Int::max_value will be deprecated in the future
|
||||
deprecated,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:14:13
|
||||
--> tests/ui/checked_conversions.rs:15:13
|
||||
|
|
||||
LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
|
||||
|
|
@ -8,97 +8,97 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::checked_conversions)]`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:15:13
|
||||
--> tests/ui/checked_conversions.rs:16:13
|
||||
|
|
||||
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:19:13
|
||||
--> tests/ui/checked_conversions.rs:20:13
|
||||
|
|
||||
LL | let _ = value <= i64::from(u16::max_value()) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:20:13
|
||||
--> tests/ui/checked_conversions.rs:21:13
|
||||
|
|
||||
LL | let _ = value <= i64::from(u16::MAX) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:24:13
|
||||
--> tests/ui/checked_conversions.rs:25:13
|
||||
|
|
||||
LL | let _ = value <= (u8::max_value() as isize) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:25:13
|
||||
--> tests/ui/checked_conversions.rs:26:13
|
||||
|
|
||||
LL | let _ = value <= (u8::MAX as isize) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:31:13
|
||||
--> tests/ui/checked_conversions.rs:32:13
|
||||
|
|
||||
LL | let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:32:13
|
||||
--> tests/ui/checked_conversions.rs:33:13
|
||||
|
|
||||
LL | let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:36:13
|
||||
--> tests/ui/checked_conversions.rs:37:13
|
||||
|
|
||||
LL | let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:37:13
|
||||
--> tests/ui/checked_conversions.rs:38:13
|
||||
|
|
||||
LL | let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:43:13
|
||||
--> tests/ui/checked_conversions.rs:44:13
|
||||
|
|
||||
LL | let _ = value <= i32::max_value() as u32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:44:13
|
||||
--> tests/ui/checked_conversions.rs:45:13
|
||||
|
|
||||
LL | let _ = value <= i32::MAX as u32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:48:13
|
||||
--> tests/ui/checked_conversions.rs:49:13
|
||||
|
|
||||
LL | let _ = value <= isize::max_value() as usize && value as i32 == 5;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:49:13
|
||||
--> tests/ui/checked_conversions.rs:50:13
|
||||
|
|
||||
LL | let _ = value <= isize::MAX as usize && value as i32 == 5;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:53:13
|
||||
--> tests/ui/checked_conversions.rs:54:13
|
||||
|
|
||||
LL | let _ = value <= u16::max_value() as u32 && value as i32 == 5;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:54:13
|
||||
--> tests/ui/checked_conversions.rs:55:13
|
||||
|
|
||||
LL | let _ = value <= u16::MAX as u32 && value as i32 == 5;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
|
||||
|
||||
error: checked cast can be simplified
|
||||
--> tests/ui/checked_conversions.rs:87:13
|
||||
--> tests/ui/checked_conversions.rs:88:13
|
||||
|
|
||||
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
|
||||
|
|
|
|||
118
tests/ui/legacy_numeric_constants.fixed
Normal file
118
tests/ui/legacy_numeric_constants.fixed
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::no_effect, deprecated, unused)]
|
||||
#![allow(clippy::legacy_numeric_constants)] // For imports.
|
||||
#![feature(lint_reasons)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macros;
|
||||
|
||||
pub mod a {
|
||||
pub use std::u128;
|
||||
}
|
||||
|
||||
macro_rules! b {
|
||||
() => {
|
||||
mod b {
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn b() {
|
||||
let x = u64::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
use std::u32::MAX;
|
||||
use std::u8::MIN;
|
||||
use std::{f64, u32};
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn main() {
|
||||
f32::EPSILON;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
usize::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
i32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
::std::primitive::u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
std::primitive::i32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u128::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u32::MAX;
|
||||
u128::MAX;
|
||||
f32::EPSILON;
|
||||
::std::primitive::u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
b!();
|
||||
|
||||
[(0, "", i128::MAX)];
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn ext() {
|
||||
external! {
|
||||
::std::primitive::u8::MIN;
|
||||
::std::u8::MIN;
|
||||
::std::primitive::u8::min_value();
|
||||
use std::u64;
|
||||
use std::u8::MIN;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::legacy_numeric_constants)]
|
||||
fn allow() {
|
||||
::std::primitive::u8::MIN;
|
||||
::std::u8::MIN;
|
||||
::std::primitive::u8::min_value();
|
||||
use std::u64;
|
||||
use std::u8::MIN;
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
#[clippy::msrv = "1.42.0"]
|
||||
fn msrv_too_low() {
|
||||
std::u32::MAX;
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
#[clippy::msrv = "1.43.0"]
|
||||
fn msrv_juust_right() {
|
||||
u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
}
|
||||
118
tests/ui/legacy_numeric_constants.rs
Normal file
118
tests/ui/legacy_numeric_constants.rs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::no_effect, deprecated, unused)]
|
||||
#![allow(clippy::legacy_numeric_constants)] // For imports.
|
||||
#![feature(lint_reasons)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macros;
|
||||
|
||||
pub mod a {
|
||||
pub use std::u128;
|
||||
}
|
||||
|
||||
macro_rules! b {
|
||||
() => {
|
||||
mod b {
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn b() {
|
||||
let x = std::u64::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
use std::u32::MAX;
|
||||
use std::u8::MIN;
|
||||
use std::{f64, u32};
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn main() {
|
||||
std::f32::EPSILON;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
std::u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
std::usize::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
std::u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
core::u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
i32::max_value();
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::max_value();
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
u8::min_value();
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
::std::u8::MIN;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
::std::primitive::u8::min_value();
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
std::primitive::i32::max_value();
|
||||
//~^ ERROR: usage of a legacy numeric method
|
||||
//~| HELP: use the associated constant instead
|
||||
self::a::u128::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
u32::MAX;
|
||||
u128::MAX;
|
||||
f32::EPSILON;
|
||||
::std::primitive::u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
b!();
|
||||
|
||||
[(0, "", std::i128::MAX)];
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
//~| HELP: use the associated constant instead
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
fn ext() {
|
||||
external! {
|
||||
::std::primitive::u8::MIN;
|
||||
::std::u8::MIN;
|
||||
::std::primitive::u8::min_value();
|
||||
use std::u64;
|
||||
use std::u8::MIN;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::legacy_numeric_constants)]
|
||||
fn allow() {
|
||||
::std::primitive::u8::MIN;
|
||||
::std::u8::MIN;
|
||||
::std::primitive::u8::min_value();
|
||||
use std::u64;
|
||||
use std::u8::MIN;
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
#[clippy::msrv = "1.42.0"]
|
||||
fn msrv_too_low() {
|
||||
std::u32::MAX;
|
||||
}
|
||||
|
||||
#[warn(clippy::legacy_numeric_constants)]
|
||||
#[clippy::msrv = "1.43.0"]
|
||||
fn msrv_juust_right() {
|
||||
std::u32::MAX;
|
||||
//~^ ERROR: usage of a legacy numeric constant
|
||||
}
|
||||
184
tests/ui/legacy_numeric_constants.stderr
Normal file
184
tests/ui/legacy_numeric_constants.stderr
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:32:5
|
||||
|
|
||||
LL | std::f32::EPSILON;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::legacy-numeric-constants` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]`
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | f32::EPSILON;
|
||||
| ~~~~~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:35:5
|
||||
|
|
||||
LL | std::u8::MIN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u8::MIN;
|
||||
| ~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:38:5
|
||||
|
|
||||
LL | std::usize::MIN;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | usize::MIN;
|
||||
| ~~~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:41:5
|
||||
|
|
||||
LL | std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u32::MAX;
|
||||
| ~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:44:5
|
||||
|
|
||||
LL | core::u32::MAX;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u32::MAX;
|
||||
| ~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:47:5
|
||||
|
|
||||
LL | MAX;
|
||||
| ^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u32::MAX;
|
||||
| ~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric method
|
||||
--> tests/ui/legacy_numeric_constants.rs:50:10
|
||||
|
|
||||
LL | i32::max_value();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | i32::MAX;
|
||||
| ~~~
|
||||
|
||||
error: usage of a legacy numeric method
|
||||
--> tests/ui/legacy_numeric_constants.rs:53:9
|
||||
|
|
||||
LL | u8::max_value();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u8::MAX;
|
||||
| ~~~
|
||||
|
||||
error: usage of a legacy numeric method
|
||||
--> tests/ui/legacy_numeric_constants.rs:56:9
|
||||
|
|
||||
LL | u8::min_value();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u8::MIN;
|
||||
| ~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:59:5
|
||||
|
|
||||
LL | ::std::u8::MIN;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u8::MIN;
|
||||
| ~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric method
|
||||
--> tests/ui/legacy_numeric_constants.rs:62:27
|
||||
|
|
||||
LL | ::std::primitive::u8::min_value();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | ::std::primitive::u8::MIN;
|
||||
| ~~~
|
||||
|
||||
error: usage of a legacy numeric method
|
||||
--> tests/ui/legacy_numeric_constants.rs:65:26
|
||||
|
|
||||
LL | std::primitive::i32::max_value();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | std::primitive::i32::MAX;
|
||||
| ~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:68:5
|
||||
|
|
||||
LL | self::a::u128::MAX;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u128::MAX;
|
||||
| ~~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:18:25
|
||||
|
|
||||
LL | let x = std::u64::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
...
|
||||
LL | b!();
|
||||
| ---- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | let x = u64::MAX;
|
||||
| ~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:82:14
|
||||
|
|
||||
LL | [(0, "", std::i128::MAX)];
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | [(0, "", i128::MAX)];
|
||||
| ~~~~~~~~~
|
||||
|
||||
error: usage of a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants.rs:116:5
|
||||
|
|
||||
LL | std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
help: use the associated constant instead
|
||||
|
|
||||
LL | u32::MAX;
|
||||
| ~~~~~~~~
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
79
tests/ui/legacy_numeric_constants_unfixable.rs
Normal file
79
tests/ui/legacy_numeric_constants_unfixable.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//@no-rustfix
|
||||
//@aux-build:proc_macros.rs
|
||||
#![allow(clippy::no_effect, deprecated, unused)]
|
||||
#![warn(clippy::legacy_numeric_constants)]
|
||||
#![feature(lint_reasons)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macros;
|
||||
|
||||
use std::u128 as _;
|
||||
//~^ ERROR: importing legacy numeric constants
|
||||
//~| HELP: remove this import
|
||||
pub mod a {
|
||||
pub use std::{mem, u128};
|
||||
//~^ ERROR: importing legacy numeric constants
|
||||
//~| HELP: remove this import
|
||||
}
|
||||
|
||||
macro_rules! b {
|
||||
() => {
|
||||
mod b {
|
||||
use std::u32;
|
||||
//~^ ERROR: importing legacy numeric constants
|
||||
//~| HELP: remove this import
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use std::u32::MAX;
|
||||
//~^ ERROR: importing a legacy numeric constant
|
||||
//~| HELP: remove this import and use the associated constant `u32::MAX`
|
||||
use std::u8::MIN;
|
||||
//~^ ERROR: importing a legacy numeric constant
|
||||
//~| HELP: remove this import and use the associated constant `u8::MIN`
|
||||
f64::MAX;
|
||||
use std::u32;
|
||||
//~^ ERROR: importing legacy numeric constants
|
||||
//~| HELP: remove this import
|
||||
u32::MAX;
|
||||
use std::f32::MIN_POSITIVE;
|
||||
//~^ ERROR: importing a legacy numeric constant
|
||||
//~| HELP: remove this import and use the associated constant `f32::MIN_POSITIVE`
|
||||
use std::f64;
|
||||
use std::i16::*;
|
||||
//~^ ERROR: importing legacy numeric constants
|
||||
//~| HELP: remove this import and use associated constants `i16::<CONST>`
|
||||
u128::MAX;
|
||||
f32::EPSILON;
|
||||
f64::EPSILON;
|
||||
::std::primitive::u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
u8::MIN;
|
||||
std::f32::consts::E;
|
||||
f64::consts::E;
|
||||
b!();
|
||||
}
|
||||
|
||||
fn ext() {
|
||||
external! {
|
||||
::std::primitive::u8::MIN;
|
||||
::std::u8::MIN;
|
||||
::std::primitive::u8::min_value();
|
||||
use std::u64;
|
||||
use std::u8::MIN;
|
||||
}
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.42.0"]
|
||||
fn msrv_too_low() {
|
||||
use std::u32::MAX;
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.43.0"]
|
||||
fn msrv_juust_right() {
|
||||
use std::u32::MAX;
|
||||
//~^ ERROR: importing a legacy numeric constant
|
||||
}
|
||||
83
tests/ui/legacy_numeric_constants_unfixable.stderr
Normal file
83
tests/ui/legacy_numeric_constants_unfixable.stderr
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
error: importing legacy numeric constants
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:10:5
|
||||
|
|
||||
LL | use std::u128 as _;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: remove this import
|
||||
= note: `-D clippy::legacy-numeric-constants` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]`
|
||||
|
||||
error: importing legacy numeric constants
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:14:24
|
||||
|
|
||||
LL | pub use std::{mem, u128};
|
||||
| ^^^^
|
||||
|
|
||||
= help: remove this import
|
||||
= note: then `u128::<CONST>` will resolve to the respective associated constant
|
||||
|
||||
error: importing a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:30:9
|
||||
|
|
||||
LL | use std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: remove this import and use the associated constant `u32::MAX` from the primitive type instead
|
||||
|
||||
error: importing a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:33:9
|
||||
|
|
||||
LL | use std::u8::MIN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: remove this import and use the associated constant `u8::MIN` from the primitive type instead
|
||||
|
||||
error: importing legacy numeric constants
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:37:9
|
||||
|
|
||||
LL | use std::u32;
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: remove this import
|
||||
= note: then `u32::<CONST>` will resolve to the respective associated constant
|
||||
|
||||
error: importing a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:41:9
|
||||
|
|
||||
LL | use std::f32::MIN_POSITIVE;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: remove this import and use the associated constant `f32::MIN_POSITIVE` from the primitive type instead
|
||||
|
||||
error: importing legacy numeric constants
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:45:9
|
||||
|
|
||||
LL | use std::i16::*;
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: remove this import and use associated constants `i16::<CONST>` from the primitive type instead
|
||||
|
||||
error: importing legacy numeric constants
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:22:17
|
||||
|
|
||||
LL | use std::u32;
|
||||
| ^^^^^^^^
|
||||
...
|
||||
LL | b!();
|
||||
| ---- in this macro invocation
|
||||
|
|
||||
= help: remove this import
|
||||
= note: then `u32::<CONST>` will resolve to the respective associated constant
|
||||
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: importing a legacy numeric constant
|
||||
--> tests/ui/legacy_numeric_constants_unfixable.rs:77:9
|
||||
|
|
||||
LL | use std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: remove this import and use the associated constant `u32::MAX` from the primitive type instead
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(unused_imports)]
|
||||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i128, i32, u128, u32};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(unused_imports)]
|
||||
#![allow(clippy::legacy_numeric_constants, unused_imports)]
|
||||
|
||||
use std::{i128, i32, u128, u32};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(clippy::legacy_numeric_constants)]
|
||||
#![warn(clippy::suspicious_arithmetic_impl)]
|
||||
use std::ops::{
|
||||
Add, AddAssign, BitAnd, BitOr, BitOrAssign, BitXor, Div, DivAssign, Mul, MulAssign, Rem, Shl, Shr, Sub,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: suspicious use of `-` in `Add` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:13:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:14:20
|
||||
|
|
||||
LL | Foo(self.0 - other.0)
|
||||
| ^
|
||||
|
|
@ -8,7 +8,7 @@ LL | Foo(self.0 - other.0)
|
|||
= help: to override `-D warnings` add `#[allow(clippy::suspicious_arithmetic_impl)]`
|
||||
|
||||
error: suspicious use of `-` in `AddAssign` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:21:23
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:22:23
|
||||
|
|
||||
LL | *self = *self - other;
|
||||
| ^
|
||||
|
|
@ -17,43 +17,43 @@ LL | *self = *self - other;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::suspicious_op_assign_impl)]`
|
||||
|
||||
error: suspicious use of `/` in `MulAssign` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:36:16
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:37:16
|
||||
|
|
||||
LL | self.0 /= other.0;
|
||||
| ^^
|
||||
|
||||
error: suspicious use of `/` in `Rem` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:75:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:76:20
|
||||
|
|
||||
LL | Foo(self.0 / other.0)
|
||||
| ^
|
||||
|
||||
error: suspicious use of `|` in `BitAnd` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:84:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:85:20
|
||||
|
|
||||
LL | Foo(self.0 | other.0)
|
||||
| ^
|
||||
|
||||
error: suspicious use of `^` in `BitOr` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:93:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:94:20
|
||||
|
|
||||
LL | Foo(self.0 ^ other.0)
|
||||
| ^
|
||||
|
||||
error: suspicious use of `&` in `BitXor` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:102:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:103:20
|
||||
|
|
||||
LL | Foo(self.0 & other.0)
|
||||
| ^
|
||||
|
||||
error: suspicious use of `>>` in `Shl` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:111:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:112:20
|
||||
|
|
||||
LL | Foo(self.0 >> other.0)
|
||||
| ^^
|
||||
|
||||
error: suspicious use of `<<` in `Shr` impl
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:120:20
|
||||
--> tests/ui/suspicious_arithmetic_impl.rs:121:20
|
||||
|
|
||||
LL | Foo(self.0 << other.0)
|
||||
| ^^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue