about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-toml/absolute_paths/absolute_paths.rs2
-rw-r--r--tests/ui/checked_conversions.fixed1
-rw-r--r--tests/ui/checked_conversions.rs1
-rw-r--r--tests/ui/checked_conversions.stderr34
-rw-r--r--tests/ui/legacy_numeric_constants.fixed117
-rw-r--r--tests/ui/legacy_numeric_constants.rs117
-rw-r--r--tests/ui/legacy_numeric_constants.stderr184
-rw-r--r--tests/ui/legacy_numeric_constants_unfixable.rs78
-rw-r--r--tests/ui/legacy_numeric_constants_unfixable.stderr83
-rw-r--r--tests/ui/manual_saturating_arithmetic.fixed2
-rw-r--r--tests/ui/manual_saturating_arithmetic.rs2
-rw-r--r--tests/ui/suspicious_arithmetic_impl.rs1
-rw-r--r--tests/ui/suspicious_arithmetic_impl.stderr18
13 files changed, 611 insertions, 29 deletions
diff --git a/tests/ui-toml/absolute_paths/absolute_paths.rs b/tests/ui-toml/absolute_paths/absolute_paths.rs
index 0e6a54452ee..a828701bcee 100644
--- a/tests/ui-toml/absolute_paths/absolute_paths.rs
+++ b/tests/ui-toml/absolute_paths/absolute_paths.rs
@@ -3,7 +3,7 @@
 //@revisions: allow_crates disallow_crates
 //@[allow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates
 //@[disallow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/disallow_crates
-#![allow(clippy::no_effect, unused)]
+#![allow(clippy::no_effect, clippy::legacy_numeric_constants, unused)]
 #![warn(clippy::absolute_paths)]
 #![feature(decl_macro)]
 
diff --git a/tests/ui/checked_conversions.fixed b/tests/ui/checked_conversions.fixed
index 0e05a27429b..1e8da331614 100644
--- a/tests/ui/checked_conversions.fixed
+++ b/tests/ui/checked_conversions.fixed
@@ -1,5 +1,6 @@
 #![allow(
     clippy::cast_lossless,
+    clippy::legacy_numeric_constants,
     unused,
     // Int::max_value will be deprecated in the future
     deprecated,
diff --git a/tests/ui/checked_conversions.rs b/tests/ui/checked_conversions.rs
index ac782699265..67a9adc049e 100644
--- a/tests/ui/checked_conversions.rs
+++ b/tests/ui/checked_conversions.rs
@@ -1,5 +1,6 @@
 #![allow(
     clippy::cast_lossless,
+    clippy::legacy_numeric_constants,
     unused,
     // Int::max_value will be deprecated in the future
     deprecated,
diff --git a/tests/ui/checked_conversions.stderr b/tests/ui/checked_conversions.stderr
index 223e379cce9..453cd7fcf01 100644
--- a/tests/ui/checked_conversions.stderr
+++ b/tests/ui/checked_conversions.stderr
@@ -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()`
diff --git a/tests/ui/legacy_numeric_constants.fixed b/tests/ui/legacy_numeric_constants.fixed
new file mode 100644
index 00000000000..a6ef8f8c119
--- /dev/null
+++ b/tests/ui/legacy_numeric_constants.fixed
@@ -0,0 +1,117 @@
+//@aux-build:proc_macros.rs
+#![allow(clippy::no_effect, deprecated, unused)]
+#![allow(clippy::legacy_numeric_constants)] // For imports.
+
+#[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
+}
diff --git a/tests/ui/legacy_numeric_constants.rs b/tests/ui/legacy_numeric_constants.rs
new file mode 100644
index 00000000000..cd633545372
--- /dev/null
+++ b/tests/ui/legacy_numeric_constants.rs
@@ -0,0 +1,117 @@
+//@aux-build:proc_macros.rs
+#![allow(clippy::no_effect, deprecated, unused)]
+#![allow(clippy::legacy_numeric_constants)] // For imports.
+
+#[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
+}
diff --git a/tests/ui/legacy_numeric_constants.stderr b/tests/ui/legacy_numeric_constants.stderr
new file mode 100644
index 00000000000..267b9ac8e4d
--- /dev/null
+++ b/tests/ui/legacy_numeric_constants.stderr
@@ -0,0 +1,184 @@
+error: usage of a legacy numeric constant
+  --> tests/ui/legacy_numeric_constants.rs:31: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:34: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:37: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:40: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:43: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:46: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:49: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:52: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:55: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:58: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:61: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:64: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:67: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:17: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:81: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:115:5
+   |
+LL |     std::u32::MAX;
+   |     ^^^^^^^^^^^^^
+   |
+help: use the associated constant instead
+   |
+LL |     u32::MAX;
+   |     ~~~~~~~~
+
+error: aborting due to 16 previous errors
+
diff --git a/tests/ui/legacy_numeric_constants_unfixable.rs b/tests/ui/legacy_numeric_constants_unfixable.rs
new file mode 100644
index 00000000000..86738ede210
--- /dev/null
+++ b/tests/ui/legacy_numeric_constants_unfixable.rs
@@ -0,0 +1,78 @@
+//@no-rustfix
+//@aux-build:proc_macros.rs
+#![allow(clippy::no_effect, deprecated, unused)]
+#![warn(clippy::legacy_numeric_constants)]
+
+#[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
+}
diff --git a/tests/ui/legacy_numeric_constants_unfixable.stderr b/tests/ui/legacy_numeric_constants_unfixable.stderr
new file mode 100644
index 00000000000..2edcf718836
--- /dev/null
+++ b/tests/ui/legacy_numeric_constants_unfixable.stderr
@@ -0,0 +1,83 @@
+error: importing legacy numeric constants
+  --> tests/ui/legacy_numeric_constants_unfixable.rs:9: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:13: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:29: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:32: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:36: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:40: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:44: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:21: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:76: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
+
diff --git a/tests/ui/manual_saturating_arithmetic.fixed b/tests/ui/manual_saturating_arithmetic.fixed
index 8218f10881a..41a32df32ee 100644
--- a/tests/ui/manual_saturating_arithmetic.fixed
+++ b/tests/ui/manual_saturating_arithmetic.fixed
@@ -1,4 +1,4 @@
-#![allow(unused_imports)]
+#![allow(clippy::legacy_numeric_constants, unused_imports)]
 
 use std::{i128, i32, u128, u32};
 
diff --git a/tests/ui/manual_saturating_arithmetic.rs b/tests/ui/manual_saturating_arithmetic.rs
index 60022b54b02..3a6b32d8069 100644
--- a/tests/ui/manual_saturating_arithmetic.rs
+++ b/tests/ui/manual_saturating_arithmetic.rs
@@ -1,4 +1,4 @@
-#![allow(unused_imports)]
+#![allow(clippy::legacy_numeric_constants, unused_imports)]
 
 use std::{i128, i32, u128, u32};
 
diff --git a/tests/ui/suspicious_arithmetic_impl.rs b/tests/ui/suspicious_arithmetic_impl.rs
index 1bd4cd5fb50..07280351e76 100644
--- a/tests/ui/suspicious_arithmetic_impl.rs
+++ b/tests/ui/suspicious_arithmetic_impl.rs
@@ -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,
diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr
index 193cd64149b..1bfca49a635 100644
--- a/tests/ui/suspicious_arithmetic_impl.stderr
+++ b/tests/ui/suspicious_arithmetic_impl.stderr
@@ -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)
    |                    ^^