about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2022-06-06 11:51:36 +0200
committerxFrednet <xFrednet@gmail.com>2022-06-06 11:51:36 +0200
commita613460e8ade73dc387c19b0a45588681de46fef (patch)
treec7e25d8b9fda8d37a8321d86ba177bd4c1b9855a /tests
parent3e771624e1e0de266ae4720354cf4534f010d39d (diff)
downloadrust-a613460e8ade73dc387c19b0a45588681de46fef.tar.gz
rust-a613460e8ade73dc387c19b0a45588681de46fef.zip
Fix `#[expect]` for `needless_borrow`, `ref_binding_to_ref`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/needless_borrow.fixed8
-rw-r--r--tests/ui/needless_borrow.rs8
-rw-r--r--tests/ui/needless_borrow.stderr32
-rw-r--r--tests/ui/ref_binding_to_reference.rs10
-rw-r--r--tests/ui/ref_binding_to_reference.stderr14
5 files changed, 49 insertions, 23 deletions
diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed
index efeb5cf5b2b..6b1576d6732 100644
--- a/tests/ui/needless_borrow.fixed
+++ b/tests/ui/needless_borrow.fixed
@@ -1,5 +1,7 @@
 // run-rustfix
 
+#![feature(lint_reasons)]
+
 #[warn(clippy::all, clippy::needless_borrow)]
 #[allow(unused_variables, clippy::unnecessary_mut_passed)]
 fn main() {
@@ -96,3 +98,9 @@ trait Trait {}
 impl<'a> Trait for &'a str {}
 
 fn h(_: &dyn Trait) {}
+
+fn check_expect_suppression() {
+    let a = 5;
+    #[expect(clippy::needless_borrow)]
+    let _ = x(&&a);
+}
diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs
index 3e416a0eb84..ebe76361db4 100644
--- a/tests/ui/needless_borrow.rs
+++ b/tests/ui/needless_borrow.rs
@@ -1,5 +1,7 @@
 // run-rustfix
 
+#![feature(lint_reasons)]
+
 #[warn(clippy::all, clippy::needless_borrow)]
 #[allow(unused_variables, clippy::unnecessary_mut_passed)]
 fn main() {
@@ -96,3 +98,9 @@ trait Trait {}
 impl<'a> Trait for &'a str {}
 
 fn h(_: &dyn Trait) {}
+
+fn check_expect_suppression() {
+    let a = 5;
+    #[expect(clippy::needless_borrow)]
+    let _ = x(&&a);
+}
diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr
index 05591ce4117..be59d8f546d 100644
--- a/tests/ui/needless_borrow.stderr
+++ b/tests/ui/needless_borrow.stderr
@@ -1,5 +1,5 @@
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:9:15
+  --> $DIR/needless_borrow.rs:11:15
    |
 LL |     let _ = x(&&a); // warn
    |               ^^^ help: change this to: `&a`
@@ -7,91 +7,91 @@ LL |     let _ = x(&&a); // warn
    = note: `-D clippy::needless-borrow` implied by `-D warnings`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:13:13
+  --> $DIR/needless_borrow.rs:15:13
    |
 LL |     mut_ref(&mut &mut b); // warn
    |             ^^^^^^^^^^^ help: change this to: `&mut b`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:25:13
+  --> $DIR/needless_borrow.rs:27:13
    |
 LL |             &&a
    |             ^^^ help: change this to: `&a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:27:15
+  --> $DIR/needless_borrow.rs:29:15
    |
 LL |         46 => &&a,
    |               ^^^ help: change this to: `&a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:33:27
+  --> $DIR/needless_borrow.rs:35:27
    |
 LL |                     break &ref_a;
    |                           ^^^^^^ help: change this to: `ref_a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:40:15
+  --> $DIR/needless_borrow.rs:42:15
    |
 LL |     let _ = x(&&&a);
    |               ^^^^ help: change this to: `&a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:41:15
+  --> $DIR/needless_borrow.rs:43:15
    |
 LL |     let _ = x(&mut &&a);
    |               ^^^^^^^^ help: change this to: `&a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:42:15
+  --> $DIR/needless_borrow.rs:44:15
    |
 LL |     let _ = x(&&&mut b);
    |               ^^^^^^^^ help: change this to: `&mut b`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:43:15
+  --> $DIR/needless_borrow.rs:45:15
    |
 LL |     let _ = x(&&ref_a);
    |               ^^^^^^^ help: change this to: `ref_a`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:46:11
+  --> $DIR/needless_borrow.rs:48:11
    |
 LL |         x(&b);
    |           ^^ help: change this to: `b`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:53:13
+  --> $DIR/needless_borrow.rs:55:13
    |
 LL |     mut_ref(&mut x);
    |             ^^^^^^ help: change this to: `x`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:54:13
+  --> $DIR/needless_borrow.rs:56:13
    |
 LL |     mut_ref(&mut &mut x);
    |             ^^^^^^^^^^^ help: change this to: `x`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:55:23
+  --> $DIR/needless_borrow.rs:57:23
    |
 LL |     let y: &mut i32 = &mut x;
    |                       ^^^^^^ help: change this to: `x`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> $DIR/needless_borrow.rs:56:23
+  --> $DIR/needless_borrow.rs:58:23
    |
 LL |     let y: &mut i32 = &mut &mut x;
    |                       ^^^^^^^^^^^ help: change this to: `x`
 
 error: this expression borrows a value the compiler would automatically borrow
-  --> $DIR/needless_borrow.rs:72:13
+  --> $DIR/needless_borrow.rs:74:13
    |
 LL |     let _ = (&x).0;
    |             ^^^^ help: change this to: `x`
 
 error: this expression borrows a value the compiler would automatically borrow
-  --> $DIR/needless_borrow.rs:74:22
+  --> $DIR/needless_borrow.rs:76:22
    |
 LL |     let _ = unsafe { (&*x).0 };
    |                      ^^^^^ help: change this to: `(*x)`
diff --git a/tests/ui/ref_binding_to_reference.rs b/tests/ui/ref_binding_to_reference.rs
index fe742a4c2f4..570ef406e4a 100644
--- a/tests/ui/ref_binding_to_reference.rs
+++ b/tests/ui/ref_binding_to_reference.rs
@@ -1,5 +1,6 @@
 // FIXME: run-rustfix waiting on multi-span suggestions
 
+#![feature(lint_reasons)]
 #![warn(clippy::ref_binding_to_reference)]
 #![allow(clippy::needless_borrowed_reference)]
 
@@ -73,3 +74,12 @@ impl T1 for S {
         let _: &&String = x;
     }
 }
+
+fn check_expect_suppression() {
+    let x = String::new();
+    #[expect(clippy::ref_binding_to_reference)]
+    let _: &&String = match Some(&x) {
+        Some(ref x) => x,
+        None => return,
+    };
+}
diff --git a/tests/ui/ref_binding_to_reference.stderr b/tests/ui/ref_binding_to_reference.stderr
index c5856e15fa9..eb36cd516a2 100644
--- a/tests/ui/ref_binding_to_reference.stderr
+++ b/tests/ui/ref_binding_to_reference.stderr
@@ -1,5 +1,5 @@
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:30:14
+  --> $DIR/ref_binding_to_reference.rs:31:14
    |
 LL |         Some(ref x) => x,
    |              ^^^^^
@@ -11,7 +11,7 @@ LL |         Some(x) => &x,
    |              ~     ~~
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:36:14
+  --> $DIR/ref_binding_to_reference.rs:37:14
    |
 LL |         Some(ref x) => {
    |              ^^^^^
@@ -25,7 +25,7 @@ LL ~             &x
    |
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:46:14
+  --> $DIR/ref_binding_to_reference.rs:47:14
    |
 LL |         Some(ref x) => m2!(x),
    |              ^^^^^
@@ -36,7 +36,7 @@ LL |         Some(x) => m2!(&x),
    |              ~         ~~
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:51:15
+  --> $DIR/ref_binding_to_reference.rs:52:15
    |
 LL |     let _ = |&ref x: &&String| {
    |               ^^^^^
@@ -48,7 +48,7 @@ LL ~         let _: &&String = &x;
    |
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:57:12
+  --> $DIR/ref_binding_to_reference.rs:58:12
    |
 LL | fn f2<'a>(&ref x: &&'a String) -> &'a String {
    |            ^^^^^
@@ -61,7 +61,7 @@ LL ~     x
    |
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:64:11
+  --> $DIR/ref_binding_to_reference.rs:65:11
    |
 LL |     fn f(&ref x: &&String) {
    |           ^^^^^
@@ -73,7 +73,7 @@ LL ~         let _: &&String = &x;
    |
 
 error: this pattern creates a reference to a reference
-  --> $DIR/ref_binding_to_reference.rs:72:11
+  --> $DIR/ref_binding_to_reference.rs:73:11
    |
 LL |     fn f(&ref x: &&String) {
    |           ^^^^^