about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compile-test.rs14
-rw-r--r--tests/ui/expect_fun_call.fixed1
-rw-r--r--tests/ui/expect_fun_call.rs1
-rw-r--r--tests/ui/expect_fun_call.stderr24
-rw-r--r--tests/ui/format.fixed2
-rw-r--r--tests/ui/format.rs2
-rw-r--r--tests/ui/format_args.fixed105
-rw-r--r--tests/ui/format_args.rs105
-rw-r--r--tests/ui/format_args.stderr106
-rw-r--r--tests/ui/format_args_unfixable.rs60
-rw-r--r--tests/ui/format_args_unfixable.stderr175
-rw-r--r--tests/ui/implicit_saturating_sub.fixed8
-rw-r--r--tests/ui/implicit_saturating_sub.rs8
-rw-r--r--tests/ui/match_overlapping_arm.rs59
-rw-r--r--tests/ui/match_overlapping_arm.stderr34
-rw-r--r--tests/ui/question_mark.fixed17
-rw-r--r--tests/ui/question_mark.rs19
-rw-r--r--tests/ui/question_mark.stderr16
-rw-r--r--tests/ui/to_string_in_display.rs2
-rw-r--r--tests/ui/unnecessary_sort_by.fixed5
-rw-r--r--tests/ui/unnecessary_sort_by.rs5
-rw-r--r--tests/ui/unnecessary_sort_by.stderr24
-rw-r--r--tests/ui_test/eq_op.rs15
23 files changed, 737 insertions, 70 deletions
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index e8b1640c869..c15835ef299 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -149,6 +149,19 @@ fn run_ui(cfg: &mut compiletest::Config) {
     compiletest::run_tests(cfg);
 }
 
+fn run_ui_test(cfg: &mut compiletest::Config) {
+    cfg.mode = TestMode::Ui;
+    cfg.src_base = Path::new("tests").join("ui_test");
+    let _g = VarGuard::set("CARGO_MANIFEST_DIR", std::fs::canonicalize("tests").unwrap());
+    let rustcflags = cfg.target_rustcflags.get_or_insert_with(Default::default);
+    let len = rustcflags.len();
+    rustcflags.push_str(" --test");
+    compiletest::run_tests(cfg);
+    if let Some(ref mut flags) = &mut cfg.target_rustcflags {
+        flags.truncate(len);
+    }
+}
+
 fn run_internal_tests(cfg: &mut compiletest::Config) {
     // only run internal tests with the internal-tests feature
     if !RUN_INTERNAL_TESTS {
@@ -312,6 +325,7 @@ fn compile_test() {
     prepare_env();
     let mut config = default_config();
     run_ui(&mut config);
+    run_ui_test(&mut config);
     run_ui_toml(&mut config);
     run_ui_cargo(&mut config);
     run_internal_tests(&mut config);
diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed
index a756d1cf506..cf923a6a594 100644
--- a/tests/ui/expect_fun_call.fixed
+++ b/tests/ui/expect_fun_call.fixed
@@ -1,6 +1,7 @@
 // run-rustfix
 
 #![warn(clippy::expect_fun_call)]
+#![allow(clippy::to_string_in_format_args)]
 
 /// Checks implementation of the `EXPECT_FUN_CALL` lint
 
diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs
index 60bbaa89d42..e6f252259df 100644
--- a/tests/ui/expect_fun_call.rs
+++ b/tests/ui/expect_fun_call.rs
@@ -1,6 +1,7 @@
 // run-rustfix
 
 #![warn(clippy::expect_fun_call)]
+#![allow(clippy::to_string_in_format_args)]
 
 /// Checks implementation of the `EXPECT_FUN_CALL` lint
 
diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr
index 6dc796f5cee..ac48a06671c 100644
--- a/tests/ui/expect_fun_call.stderr
+++ b/tests/ui/expect_fun_call.stderr
@@ -1,5 +1,5 @@
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:28:26
+  --> $DIR/expect_fun_call.rs:29:26
    |
 LL |     with_none_and_format.expect(&format!("Error {}: fake error", error_code));
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
@@ -7,67 +7,67 @@ LL |     with_none_and_format.expect(&format!("Error {}: fake error", error_code
    = note: `-D clippy::expect-fun-call` implied by `-D warnings`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:31:26
+  --> $DIR/expect_fun_call.rs:32:26
    |
 LL |     with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:41:25
+  --> $DIR/expect_fun_call.rs:42:25
    |
 LL |     with_err_and_format.expect(&format!("Error {}: fake error", error_code));
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:44:25
+  --> $DIR/expect_fun_call.rs:45:25
    |
 LL |     with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:56:17
+  --> $DIR/expect_fun_call.rs:57:17
    |
 LL |     Some("foo").expect(format!("{} {}", 1, 2).as_ref());
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:77:21
+  --> $DIR/expect_fun_call.rs:78:21
    |
 LL |         Some("foo").expect(&get_string());
    |                     ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:78:21
+  --> $DIR/expect_fun_call.rs:79:21
    |
 LL |         Some("foo").expect(get_string().as_ref());
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:79:21
+  --> $DIR/expect_fun_call.rs:80:21
    |
 LL |         Some("foo").expect(get_string().as_str());
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:81:21
+  --> $DIR/expect_fun_call.rs:82:21
    |
 LL |         Some("foo").expect(get_static_str());
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:82:21
+  --> $DIR/expect_fun_call.rs:83:21
    |
 LL |         Some("foo").expect(get_non_static_str(&0));
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:86:16
+  --> $DIR/expect_fun_call.rs:87:16
    |
 LL |     Some(true).expect(&format!("key {}, {}", 1, 2));
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
 
 error: use of `expect` followed by a function call
-  --> $DIR/expect_fun_call.rs:92:17
+  --> $DIR/expect_fun_call.rs:93:17
    |
 LL |         opt_ref.expect(&format!("{:?}", opt_ref));
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
diff --git a/tests/ui/format.fixed b/tests/ui/format.fixed
index 5dd64140e81..73fc750511c 100644
--- a/tests/ui/format.fixed
+++ b/tests/ui/format.fixed
@@ -1,6 +1,6 @@
 // run-rustfix
 
-#![allow(clippy::print_literal, clippy::redundant_clone)]
+#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
 #![warn(clippy::useless_format)]
 
 struct Foo(pub String);
diff --git a/tests/ui/format.rs b/tests/ui/format.rs
index 4599fb5207e..2f4595650cb 100644
--- a/tests/ui/format.rs
+++ b/tests/ui/format.rs
@@ -1,6 +1,6 @@
 // run-rustfix
 
-#![allow(clippy::print_literal, clippy::redundant_clone)]
+#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
 #![warn(clippy::useless_format)]
 
 struct Foo(pub String);
diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed
new file mode 100644
index 00000000000..8376566c4d6
--- /dev/null
+++ b/tests/ui/format_args.fixed
@@ -0,0 +1,105 @@
+// run-rustfix
+
+#![allow(unreachable_code)]
+#![allow(unused_macros)]
+#![allow(unused_variables)]
+#![allow(clippy::assertions_on_constants)]
+#![allow(clippy::eq_op)]
+#![warn(clippy::to_string_in_format_args)]
+
+use std::io::{stdout, Write};
+use std::ops::Deref;
+use std::panic::Location;
+
+struct Somewhere;
+
+impl ToString for Somewhere {
+    fn to_string(&self) -> String {
+        String::from("somewhere")
+    }
+}
+
+struct X(u32);
+
+impl Deref for X {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+struct Y<'a>(&'a X);
+
+impl<'a> Deref for Y<'a> {
+    type Target = &'a X;
+
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+
+struct Z(u32);
+
+impl Deref for Z {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+impl std::fmt::Display for Z {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "Z")
+    }
+}
+
+macro_rules! my_macro {
+    () => {
+        // here be dragons, do not enter (or lint)
+        println!("error: something failed at {}", Location::caller().to_string());
+    };
+}
+
+macro_rules! my_other_macro {
+    () => {
+        Location::caller().to_string()
+    };
+}
+
+fn main() {
+    let x = &X(1);
+    let x_ref = &x;
+
+    let _ = format!("error: something failed at {}", Location::caller());
+    let _ = write!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller()
+    );
+    let _ = writeln!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller()
+    );
+    print!("error: something failed at {}", Location::caller());
+    println!("error: something failed at {}", Location::caller());
+    eprint!("error: something failed at {}", Location::caller());
+    eprintln!("error: something failed at {}", Location::caller());
+    let _ = format_args!("error: something failed at {}", Location::caller());
+    assert!(true, "error: something failed at {}", Location::caller());
+    assert_eq!(0, 0, "error: something failed at {}", Location::caller());
+    assert_ne!(0, 0, "error: something failed at {}", Location::caller());
+    panic!("error: something failed at {}", Location::caller());
+    println!("{}", *X(1));
+    println!("{}", ***Y(&X(1)));
+    println!("{}", Z(1));
+    println!("{}", **x);
+    println!("{}", ***x_ref);
+
+    println!("error: something failed at {}", Somewhere.to_string());
+    println!("{} and again {0}", x.to_string());
+    my_macro!();
+    println!("error: something failed at {}", my_other_macro!());
+}
diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs
new file mode 100644
index 00000000000..164cc07066d
--- /dev/null
+++ b/tests/ui/format_args.rs
@@ -0,0 +1,105 @@
+// run-rustfix
+
+#![allow(unreachable_code)]
+#![allow(unused_macros)]
+#![allow(unused_variables)]
+#![allow(clippy::assertions_on_constants)]
+#![allow(clippy::eq_op)]
+#![warn(clippy::to_string_in_format_args)]
+
+use std::io::{stdout, Write};
+use std::ops::Deref;
+use std::panic::Location;
+
+struct Somewhere;
+
+impl ToString for Somewhere {
+    fn to_string(&self) -> String {
+        String::from("somewhere")
+    }
+}
+
+struct X(u32);
+
+impl Deref for X {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+struct Y<'a>(&'a X);
+
+impl<'a> Deref for Y<'a> {
+    type Target = &'a X;
+
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+
+struct Z(u32);
+
+impl Deref for Z {
+    type Target = u32;
+
+    fn deref(&self) -> &u32 {
+        &self.0
+    }
+}
+
+impl std::fmt::Display for Z {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "Z")
+    }
+}
+
+macro_rules! my_macro {
+    () => {
+        // here be dragons, do not enter (or lint)
+        println!("error: something failed at {}", Location::caller().to_string());
+    };
+}
+
+macro_rules! my_other_macro {
+    () => {
+        Location::caller().to_string()
+    };
+}
+
+fn main() {
+    let x = &X(1);
+    let x_ref = &x;
+
+    let _ = format!("error: something failed at {}", Location::caller().to_string());
+    let _ = write!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller().to_string()
+    );
+    let _ = writeln!(
+        stdout(),
+        "error: something failed at {}",
+        Location::caller().to_string()
+    );
+    print!("error: something failed at {}", Location::caller().to_string());
+    println!("error: something failed at {}", Location::caller().to_string());
+    eprint!("error: something failed at {}", Location::caller().to_string());
+    eprintln!("error: something failed at {}", Location::caller().to_string());
+    let _ = format_args!("error: something failed at {}", Location::caller().to_string());
+    assert!(true, "error: something failed at {}", Location::caller().to_string());
+    assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string());
+    assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string());
+    panic!("error: something failed at {}", Location::caller().to_string());
+    println!("{}", X(1).to_string());
+    println!("{}", Y(&X(1)).to_string());
+    println!("{}", Z(1).to_string());
+    println!("{}", x.to_string());
+    println!("{}", x_ref.to_string());
+
+    println!("error: something failed at {}", Somewhere.to_string());
+    println!("{} and again {0}", x.to_string());
+    my_macro!();
+    println!("error: something failed at {}", my_other_macro!());
+}
diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr
new file mode 100644
index 00000000000..9cfc97edeaf
--- /dev/null
+++ b/tests/ui/format_args.stderr
@@ -0,0 +1,106 @@
+error: `to_string` applied to a type that implements `Display` in `format!` args
+  --> $DIR/format_args.rs:75:72
+   |
+LL |     let _ = format!("error: something failed at {}", Location::caller().to_string());
+   |                                                                        ^^^^^^^^^^^^ help: remove this
+   |
+   = note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
+
+error: `to_string` applied to a type that implements `Display` in `write!` args
+  --> $DIR/format_args.rs:79:27
+   |
+LL |         Location::caller().to_string()
+   |                           ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `writeln!` args
+  --> $DIR/format_args.rs:84:27
+   |
+LL |         Location::caller().to_string()
+   |                           ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `print!` args
+  --> $DIR/format_args.rs:86:63
+   |
+LL |     print!("error: something failed at {}", Location::caller().to_string());
+   |                                                               ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:87:65
+   |
+LL |     println!("error: something failed at {}", Location::caller().to_string());
+   |                                                                 ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `eprint!` args
+  --> $DIR/format_args.rs:88:64
+   |
+LL |     eprint!("error: something failed at {}", Location::caller().to_string());
+   |                                                                ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `eprintln!` args
+  --> $DIR/format_args.rs:89:66
+   |
+LL |     eprintln!("error: something failed at {}", Location::caller().to_string());
+   |                                                                  ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `format_args!` args
+  --> $DIR/format_args.rs:90:77
+   |
+LL |     let _ = format_args!("error: something failed at {}", Location::caller().to_string());
+   |                                                                             ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `assert!` args
+  --> $DIR/format_args.rs:91:70
+   |
+LL |     assert!(true, "error: something failed at {}", Location::caller().to_string());
+   |                                                                      ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `assert_eq!` args
+  --> $DIR/format_args.rs:92:73
+   |
+LL |     assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string());
+   |                                                                         ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `assert_ne!` args
+  --> $DIR/format_args.rs:93:73
+   |
+LL |     assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string());
+   |                                                                         ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `panic!` args
+  --> $DIR/format_args.rs:94:63
+   |
+LL |     panic!("error: something failed at {}", Location::caller().to_string());
+   |                                                               ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:95:20
+   |
+LL |     println!("{}", X(1).to_string());
+   |                    ^^^^^^^^^^^^^^^^ help: use this: `*X(1)`
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:96:20
+   |
+LL |     println!("{}", Y(&X(1)).to_string());
+   |                    ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))`
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:97:24
+   |
+LL |     println!("{}", Z(1).to_string());
+   |                        ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:98:20
+   |
+LL |     println!("{}", x.to_string());
+   |                    ^^^^^^^^^^^^^ help: use this: `**x`
+
+error: `to_string` applied to a type that implements `Display` in `println!` args
+  --> $DIR/format_args.rs:99:20
+   |
+LL |     println!("{}", x_ref.to_string());
+   |                    ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref`
+
+error: aborting due to 17 previous errors
+
diff --git a/tests/ui/format_args_unfixable.rs b/tests/ui/format_args_unfixable.rs
new file mode 100644
index 00000000000..a8c06c2bde6
--- /dev/null
+++ b/tests/ui/format_args_unfixable.rs
@@ -0,0 +1,60 @@
+#![allow(clippy::assertions_on_constants)]
+#![allow(clippy::eq_op)]
+#![warn(clippy::format_in_format_args)]
+#![warn(clippy::to_string_in_format_args)]
+
+use std::io::{stdout, Error, ErrorKind, Write};
+use std::ops::Deref;
+use std::panic::Location;
+
+macro_rules! my_macro {
+    () => {
+        // here be dragons, do not enter (or lint)
+        println!("error: {}", format!("something failed at {}", Location::caller()));
+    };
+}
+
+macro_rules! my_other_macro {
+    () => {
+        format!("something failed at {}", Location::caller())
+    };
+}
+
+fn main() {
+    let error = Error::new(ErrorKind::Other, "bad thing");
+    let x = 'x';
+
+    println!("error: {}", format!("something failed at {}", Location::caller()));
+    println!("{}: {}", error, format!("something failed at {}", Location::caller()));
+    println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
+    println!("{{}}: {}", format!("something failed at {}", Location::caller()));
+    println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
+    println!("error: {}", format!(r#"something failed at "{}""#, Location::caller()));
+    println!("error: {}", format!("something failed at {} {0}", Location::caller()));
+    let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
+    let _ = write!(
+        stdout(),
+        "error: {}",
+        format!("something failed at {}", Location::caller())
+    );
+    let _ = writeln!(
+        stdout(),
+        "error: {}",
+        format!("something failed at {}", Location::caller())
+    );
+    print!("error: {}", format!("something failed at {}", Location::caller()));
+    eprint!("error: {}", format!("something failed at {}", Location::caller()));
+    eprintln!("error: {}", format!("something failed at {}", Location::caller()));
+    let _ = format_args!("error: {}", format!("something failed at {}", Location::caller()));
+    assert!(true, "error: {}", format!("something failed at {}", Location::caller()));
+    assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
+    assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
+    panic!("error: {}", format!("something failed at {}", Location::caller()));
+
+    println!("error: {}", format_args!("something failed at {}", Location::caller()));
+    println!("error: {:>70}", format!("something failed at {}", Location::caller()));
+    println!("error: {} {0}", format!("something failed at {}", Location::caller()));
+    println!("{} and again {0}", format!("hi {}", x));
+    my_macro!();
+    println!("error: {}", my_other_macro!());
+}
diff --git a/tests/ui/format_args_unfixable.stderr b/tests/ui/format_args_unfixable.stderr
new file mode 100644
index 00000000000..4476218ad58
--- /dev/null
+++ b/tests/ui/format_args_unfixable.stderr
@@ -0,0 +1,175 @@
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:27:5
+   |
+LL |     println!("error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::format-in-format-args` implied by `-D warnings`
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:28:5
+   |
+LL |     println!("{}: {}", error, format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:29:5
+   |
+LL |     println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:30:5
+   |
+LL |     println!("{{}}: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:31:5
+   |
+LL |     println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:32:5
+   |
+LL |     println!("error: {}", format!(r#"something failed at "{}""#, Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `println!` args
+  --> $DIR/format_args_unfixable.rs:33:5
+   |
+LL |     println!("error: {}", format!("something failed at {} {0}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `println!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `format!` args
+  --> $DIR/format_args_unfixable.rs:34:13
+   |
+LL |     let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `format!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `write!` args
+  --> $DIR/format_args_unfixable.rs:35:13
+   |
+LL |       let _ = write!(
+   |  _____________^
+LL | |         stdout(),
+LL | |         "error: {}",
+LL | |         format!("something failed at {}", Location::caller())
+LL | |     );
+   | |_____^
+   |
+   = help: combine the `format!(..)` arguments with the outer `write!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `writeln!` args
+  --> $DIR/format_args_unfixable.rs:40:13
+   |
+LL |       let _ = writeln!(
+   |  _____________^
+LL | |         stdout(),
+LL | |         "error: {}",
+LL | |         format!("something failed at {}", Location::caller())
+LL | |     );
+   | |_____^
+   |
+   = help: combine the `format!(..)` arguments with the outer `writeln!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `print!` args
+  --> $DIR/format_args_unfixable.rs:45:5
+   |
+LL |     print!("error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `print!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `eprint!` args
+  --> $DIR/format_args_unfixable.rs:46:5
+   |
+LL |     eprint!("error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `eprint!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `eprintln!` args
+  --> $DIR/format_args_unfixable.rs:47:5
+   |
+LL |     eprintln!("error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `eprintln!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `format_args!` args
+  --> $DIR/format_args_unfixable.rs:48:13
+   |
+LL |     let _ = format_args!("error: {}", format!("something failed at {}", Location::caller()));
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `format_args!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `assert!` args
+  --> $DIR/format_args_unfixable.rs:49:5
+   |
+LL |     assert!(true, "error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `assert!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `assert_eq!` args
+  --> $DIR/format_args_unfixable.rs:50:5
+   |
+LL |     assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `assert_eq!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `assert_ne!` args
+  --> $DIR/format_args_unfixable.rs:51:5
+   |
+LL |     assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `assert_ne!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: `format!` in `panic!` args
+  --> $DIR/format_args_unfixable.rs:52:5
+   |
+LL |     panic!("error: {}", format!("something failed at {}", Location::caller()));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: combine the `format!(..)` arguments with the outer `panic!(..)` call
+   = help: or consider changing `format!` to `format_args!`
+
+error: aborting due to 18 previous errors
+
diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed
index 859765d08a7..e6f57e9267e 100644
--- a/tests/ui/implicit_saturating_sub.fixed
+++ b/tests/ui/implicit_saturating_sub.fixed
@@ -157,4 +157,12 @@ fn main() {
     if i_64 != 0 {
         i_64 -= 1;
     }
+
+    // issue #7831
+    // No Lint
+    if u_32 > 0 {
+        u_32 -= 1;
+    } else {
+        println!("side effect");
+    }
 }
diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs
index 2f32a7b1578..8bb28d149c6 100644
--- a/tests/ui/implicit_saturating_sub.rs
+++ b/tests/ui/implicit_saturating_sub.rs
@@ -203,4 +203,12 @@ fn main() {
     if i_64 != 0 {
         i_64 -= 1;
     }
+
+    // issue #7831
+    // No Lint
+    if u_32 > 0 {
+        u_32 -= 1;
+    } else {
+        println!("side effect");
+    }
 }
diff --git a/tests/ui/match_overlapping_arm.rs b/tests/ui/match_overlapping_arm.rs
index 846d665d1d8..ff91c4498ec 100644
--- a/tests/ui/match_overlapping_arm.rs
+++ b/tests/ui/match_overlapping_arm.rs
@@ -10,98 +10,95 @@ fn overlapping() {
     const FOO: u64 = 2;
 
     match 42 {
-        0..=10 => println!("0 ... 10"),
-        0..=11 => println!("0 ... 11"),
+        0..=10 => println!("0..=10"),
+        0..=11 => println!("0..=11"),
         _ => (),
     }
 
     match 42 {
-        0..=5 => println!("0 ... 5"),
-        6..=7 => println!("6 ... 7"),
-        FOO..=11 => println!("0 ... 11"),
+        0..=5 => println!("0..=5"),
+        6..=7 => println!("6..=7"),
+        FOO..=11 => println!("FOO..=11"),
         _ => (),
     }
 
     match 42 {
         2 => println!("2"),
-        0..=5 => println!("0 ... 5"),
+        0..=5 => println!("0..=5"),
         _ => (),
     }
 
     match 42 {
         2 => println!("2"),
-        0..=2 => println!("0 ... 2"),
+        0..=2 => println!("0..=2"),
         _ => (),
     }
 
     match 42 {
-        0..=10 => println!("0 ... 10"),
-        11..=50 => println!("11 ... 50"),
+        0..=10 => println!("0..=10"),
+        11..=50 => println!("11..=50"),
         _ => (),
     }
 
     match 42 {
         2 => println!("2"),
-        0..2 => println!("0 .. 2"),
+        0..2 => println!("0..2"),
         _ => (),
     }
 
     match 42 {
-        0..10 => println!("0 .. 10"),
-        10..50 => println!("10 .. 50"),
+        0..10 => println!("0..10"),
+        10..50 => println!("10..50"),
         _ => (),
     }
 
     match 42 {
-        0..11 => println!("0 .. 11"),
-        0..=11 => println!("0 ... 11"),
+        0..11 => println!("0..11"),
+        0..=11 => println!("0..=11"),
         _ => (),
     }
 
     match 42 {
-        5..7 => println!("5 .. 7"),
-        0..10 => println!("0 .. 10"),
+        5..7 => println!("5..7"),
+        0..10 => println!("0..10"),
         _ => (),
     }
 
     match 42 {
-        5..10 => println!("5 .. 10"),
-        0..=10 => println!("0 ... 10"),
+        5..10 => println!("5..10"),
+        0..=10 => println!("0..=10"),
         _ => (),
     }
 
     match 42 {
-        0..14 => println!("0 .. 14"),
-        5..10 => println!("5 .. 10"),
+        0..14 => println!("0..14"),
+        5..10 => println!("5..10"),
         _ => (),
     }
 
     match 42 {
-        5..14 => println!("5 .. 14"),
-        0..=10 => println!("0 ... 10"),
+        5..14 => println!("5..14"),
+        0..=10 => println!("0..=10"),
         _ => (),
     }
 
     match 42 {
-        0..7 => println!("0 .. 7"),
-        0..=10 => println!("0 ... 10"),
+        0..7 => println!("0..7"),
+        0..=10 => println!("0..=10"),
         _ => (),
     }
 
-    /*
-    // FIXME(JohnTitor): uncomment this once rustfmt knows half-open patterns
     match 42 {
-        0.. => println!("0 .. 42"),
-        3.. => println!("3 .. 42"),
+        3.. => println!("3.."),
+        0.. => println!("0.."),
         _ => (),
     }
 
     match 42 {
-        ..=23 => println!("0 ... 23"),
-        ..26 => println!("0 .. 26"),
+        ..=23 => println!("..=23"),
+        ..26 => println!("..26"),
         _ => (),
     }
-    */
 
     if let None = Some(42) {
         // nothing
diff --git a/tests/ui/match_overlapping_arm.stderr b/tests/ui/match_overlapping_arm.stderr
index 359fa49f51b..c2b3f173c2b 100644
--- a/tests/ui/match_overlapping_arm.stderr
+++ b/tests/ui/match_overlapping_arm.stderr
@@ -1,63 +1,75 @@
 error: some ranges overlap
   --> $DIR/match_overlapping_arm.rs:13:9
    |
-LL |         0..=10 => println!("0 ... 10"),
+LL |         0..=10 => println!("0..=10"),
    |         ^^^^^^
    |
    = note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
 note: overlaps with this
   --> $DIR/match_overlapping_arm.rs:14:9
    |
-LL |         0..=11 => println!("0 ... 11"),
+LL |         0..=11 => println!("0..=11"),
    |         ^^^^^^
 
 error: some ranges overlap
   --> $DIR/match_overlapping_arm.rs:19:9
    |
-LL |         0..=5 => println!("0 ... 5"),
+LL |         0..=5 => println!("0..=5"),
    |         ^^^^^
    |
 note: overlaps with this
   --> $DIR/match_overlapping_arm.rs:21:9
    |
-LL |         FOO..=11 => println!("0 ... 11"),
+LL |         FOO..=11 => println!("FOO..=11"),
    |         ^^^^^^^^
 
 error: some ranges overlap
   --> $DIR/match_overlapping_arm.rs:56:9
    |
-LL |         0..11 => println!("0 .. 11"),
+LL |         0..11 => println!("0..11"),
    |         ^^^^^
    |
 note: overlaps with this
   --> $DIR/match_overlapping_arm.rs:57:9
    |
-LL |         0..=11 => println!("0 ... 11"),
+LL |         0..=11 => println!("0..=11"),
    |         ^^^^^^
 
 error: some ranges overlap
   --> $DIR/match_overlapping_arm.rs:81:9
    |
-LL |         0..=10 => println!("0 ... 10"),
+LL |         0..=10 => println!("0..=10"),
    |         ^^^^^^
    |
 note: overlaps with this
   --> $DIR/match_overlapping_arm.rs:80:9
    |
-LL |         5..14 => println!("5 .. 14"),
+LL |         5..14 => println!("5..14"),
    |         ^^^^^
 
 error: some ranges overlap
   --> $DIR/match_overlapping_arm.rs:86:9
    |
-LL |         0..7 => println!("0 .. 7"),
+LL |         0..7 => println!("0..7"),
    |         ^^^^
    |
 note: overlaps with this
   --> $DIR/match_overlapping_arm.rs:87:9
    |
-LL |         0..=10 => println!("0 ... 10"),
+LL |         0..=10 => println!("0..=10"),
    |         ^^^^^^
 
-error: aborting due to 5 previous errors
+error: some ranges overlap
+  --> $DIR/match_overlapping_arm.rs:98:9
+   |
+LL |         ..=23 => println!("..=23"),
+   |         ^^^^^
+   |
+note: overlaps with this
+  --> $DIR/match_overlapping_arm.rs:99:9
+   |
+LL |         ..26 => println!("..26"),
+   |         ^^^^
+
+error: aborting due to 6 previous errors
 
diff --git a/tests/ui/question_mark.fixed b/tests/ui/question_mark.fixed
index 0b5746cb522..ccb2e5a302e 100644
--- a/tests/ui/question_mark.fixed
+++ b/tests/ui/question_mark.fixed
@@ -104,6 +104,21 @@ fn func() -> Option<i32> {
     Some(0)
 }
 
+fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
+    let _ = x?;
+
+    x?;
+
+    // No warning
+    let y = if let Ok(x) = x {
+        x
+    } else {
+        return Err("some error");
+    };
+
+    Ok(y)
+}
+
 fn main() {
     some_func(Some(42));
     some_func(None);
@@ -123,4 +138,6 @@ fn main() {
     returns_something_similar_to_option(so);
 
     func();
+
+    let _ = result_func(Ok(42));
 }
diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs
index 0f0825c9334..ca3722371f5 100644
--- a/tests/ui/question_mark.rs
+++ b/tests/ui/question_mark.rs
@@ -134,6 +134,23 @@ fn func() -> Option<i32> {
     Some(0)
 }
 
+fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
+    let _ = if let Ok(x) = x { x } else { return x };
+
+    if x.is_err() {
+        return x;
+    }
+
+    // No warning
+    let y = if let Ok(x) = x {
+        x
+    } else {
+        return Err("some error");
+    };
+
+    Ok(y)
+}
+
 fn main() {
     some_func(Some(42));
     some_func(None);
@@ -153,4 +170,6 @@ fn main() {
     returns_something_similar_to_option(so);
 
     func();
+
+    let _ = result_func(Ok(42));
 }
diff --git a/tests/ui/question_mark.stderr b/tests/ui/question_mark.stderr
index 6f330cfa385..161588cb73c 100644
--- a/tests/ui/question_mark.stderr
+++ b/tests/ui/question_mark.stderr
@@ -100,5 +100,19 @@ LL | |         return None;
 LL | |     }
    | |_____^ help: replace it with: `f()?;`
 
-error: aborting due to 11 previous errors
+error: this if-let-else may be rewritten with the `?` operator
+  --> $DIR/question_mark.rs:138:13
+   |
+LL |     let _ = if let Ok(x) = x { x } else { return x };
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
+
+error: this block may be rewritten with the `?` operator
+  --> $DIR/question_mark.rs:140:5
+   |
+LL | /     if x.is_err() {
+LL | |         return x;
+LL | |     }
+   | |_____^ help: replace it with: `x?;`
+
+error: aborting due to 13 previous errors
 
diff --git a/tests/ui/to_string_in_display.rs b/tests/ui/to_string_in_display.rs
index eb8105c6b6d..3ccdcd1117b 100644
--- a/tests/ui/to_string_in_display.rs
+++ b/tests/ui/to_string_in_display.rs
@@ -1,5 +1,5 @@
 #![warn(clippy::to_string_in_display)]
-#![allow(clippy::inherent_to_string_shadow_display)]
+#![allow(clippy::inherent_to_string_shadow_display, clippy::to_string_in_format_args)]
 
 use std::fmt;
 
diff --git a/tests/ui/unnecessary_sort_by.fixed b/tests/ui/unnecessary_sort_by.fixed
index b45b27d8f23..d806d620b17 100644
--- a/tests/ui/unnecessary_sort_by.fixed
+++ b/tests/ui/unnecessary_sort_by.fixed
@@ -2,6 +2,7 @@
 
 #![allow(clippy::stable_sort_primitive)]
 
+use std::cell::Ref;
 use std::cmp::Reverse;
 
 fn unnecessary_sort_by() {
@@ -33,6 +34,10 @@ fn unnecessary_sort_by() {
     // `Reverse(b)` would borrow in the following cases, don't lint
     vec.sort_by(|a, b| b.cmp(a));
     vec.sort_unstable_by(|a, b| b.cmp(a));
+
+    // No warning if element does not implement `Ord`
+    let mut vec: Vec<Ref<usize>> = Vec::new();
+    vec.sort_unstable_by(|a, b| a.cmp(b));
 }
 
 // Do not suggest returning a reference to the closure parameter of `Vec::sort_by_key`
diff --git a/tests/ui/unnecessary_sort_by.rs b/tests/ui/unnecessary_sort_by.rs
index be2abe7f701..6ee9c3af455 100644
--- a/tests/ui/unnecessary_sort_by.rs
+++ b/tests/ui/unnecessary_sort_by.rs
@@ -2,6 +2,7 @@
 
 #![allow(clippy::stable_sort_primitive)]
 
+use std::cell::Ref;
 use std::cmp::Reverse;
 
 fn unnecessary_sort_by() {
@@ -33,6 +34,10 @@ fn unnecessary_sort_by() {
     // `Reverse(b)` would borrow in the following cases, don't lint
     vec.sort_by(|a, b| b.cmp(a));
     vec.sort_unstable_by(|a, b| b.cmp(a));
+
+    // No warning if element does not implement `Ord`
+    let mut vec: Vec<Ref<usize>> = Vec::new();
+    vec.sort_unstable_by(|a, b| a.cmp(b));
 }
 
 // Do not suggest returning a reference to the closure parameter of `Vec::sort_by_key`
diff --git a/tests/ui/unnecessary_sort_by.stderr b/tests/ui/unnecessary_sort_by.stderr
index 50607933e18..ca9641e8803 100644
--- a/tests/ui/unnecessary_sort_by.stderr
+++ b/tests/ui/unnecessary_sort_by.stderr
@@ -1,5 +1,5 @@
 error: use Vec::sort here instead
-  --> $DIR/unnecessary_sort_by.rs:14:5
+  --> $DIR/unnecessary_sort_by.rs:15:5
    |
 LL |     vec.sort_by(|a, b| a.cmp(b));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort()`
@@ -7,67 +7,67 @@ LL |     vec.sort_by(|a, b| a.cmp(b));
    = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings`
 
 error: use Vec::sort here instead
-  --> $DIR/unnecessary_sort_by.rs:15:5
+  --> $DIR/unnecessary_sort_by.rs:16:5
    |
 LL |     vec.sort_unstable_by(|a, b| a.cmp(b));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable()`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:16:5
+  --> $DIR/unnecessary_sort_by.rs:17:5
    |
 LL |     vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs()));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (a + 5).abs())`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:17:5
+  --> $DIR/unnecessary_sort_by.rs:18:5
    |
 LL |     vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b)));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:20:5
+  --> $DIR/unnecessary_sort_by.rs:21:5
    |
 LL |     vec.sort_by(|a, b| (b + 5).abs().cmp(&(a + 5).abs()));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|b| Reverse((b + 5).abs()))`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:21:5
+  --> $DIR/unnecessary_sort_by.rs:22:5
    |
 LL |     vec.sort_unstable_by(|a, b| id(-b).cmp(&id(-a)));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|b| Reverse(id(-b)))`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:31:5
+  --> $DIR/unnecessary_sort_by.rs:32:5
    |
 LL |     vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs()));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:32:5
+  --> $DIR/unnecessary_sort_by.rs:33:5
    |
 LL |     vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs()));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:88:9
+  --> $DIR/unnecessary_sort_by.rs:93:9
    |
 LL |         args.sort_by(|a, b| a.name().cmp(&b.name()));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:89:9
+  --> $DIR/unnecessary_sort_by.rs:94:9
    |
 LL |         args.sort_unstable_by(|a, b| a.name().cmp(&b.name()));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:91:9
+  --> $DIR/unnecessary_sort_by.rs:96:9
    |
 LL |         args.sort_by(|a, b| b.name().cmp(&a.name()));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|b| Reverse(b.name()))`
 
 error: use Vec::sort_by_key here instead
-  --> $DIR/unnecessary_sort_by.rs:92:9
+  --> $DIR/unnecessary_sort_by.rs:97:9
    |
 LL |         args.sort_unstable_by(|a, b| b.name().cmp(&a.name()));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|b| Reverse(b.name()))`
diff --git a/tests/ui_test/eq_op.rs b/tests/ui_test/eq_op.rs
new file mode 100644
index 00000000000..f2f5f1e588e
--- /dev/null
+++ b/tests/ui_test/eq_op.rs
@@ -0,0 +1,15 @@
+#[warn(clippy::eq_op)]
+#[test]
+fn eq_op_shouldnt_trigger_in_tests() {
+    let a = 1;
+    let result = a + 1 == 1 + a;
+    assert!(result);
+}
+
+#[test]
+fn eq_op_macros_shouldnt_trigger_in_tests() {
+    let a = 1;
+    let b = 2;
+    assert_eq!(a, a);
+    assert_eq!(a + b, b + a);
+}