]> git.lizzy.rs Git - rust.git/commitdiff
Finalize needless_borrowed_ref lint doc.
authorBenoît CORTIER <benoit.cortier@fried-world.eu>
Sat, 1 Jul 2017 16:51:20 +0000 (18:51 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 21 Aug 2017 12:02:28 +0000 (14:02 +0200)
Make sure the needless_borrowed_ref.stderr in examples is up to date
too.

clippy_lints/src/needless_borrowed_ref.rs
clippy_tests/examples/needless_borrowed_ref.stderr

index 6e17d23fb0bbde470b9c0844f6a3c8588801acda..1451b19aecad3e72f9c8711d53e231e1d0cb1c03 100644 (file)
@@ -3,25 +3,33 @@
 //! This lint is **warn** by default
 
 use rustc::lint::*;
-<<<<<<< HEAD
-use rustc::hir::{MutImmutable, Pat, PatKind, BindingAnnotation};
-=======
-use rustc::hir::{MutImmutable, Pat, PatKind};
-<<<<<<< HEAD
->>>>>>> e30bf721... Improve needless_borrowed_ref and add suggestion to it.
+use rustc::hir::{MutImmutable, Pat, PatKind, BindByRef};
 use rustc::ty;
-=======
->>>>>>> 4ae45c87... Improve needless_borrowed_ref lint: remove the hand rolled span part.
 use utils::{span_lint_and_then, in_macro, snippet};
-use rustc::hir::BindingMode::BindByRef;
 
 /// **What it does:** Checks for useless borrowed references.
 ///
-/// **Why is this bad?** It is completely useless and make the code look more
-/// complex than it
+/// **Why is this bad?** It is mostly useless and make the code look more complex than it
 /// actually is.
 ///
-/// **Known problems:** None.
+/// **Known problems:** It seems that the `&ref` pattern is sometimes useful.
+/// For instance in the following snippet:
+/// ```rust
+/// enum Animal {
+///     Cat(u64),
+///     Dog(u64),
+/// }
+///
+/// fn foo(a: &Animal, b: &Animal) {
+///     match (a, b) {
+///         (&Animal::Cat(v), k) | (k, &Animal::Cat(v)) => (), // lifetime mismatch error
+///         (&Animal::Dog(ref c), &Animal::Dog(_)) => ()
+///     }
+/// }
+/// ```
+/// There is a lifetime mismatch error for `k` (indeed a and b have distinct lifetime).
+/// This can be fixed by using the `&ref` pattern.
+/// However, the code can also be fixed by much cleaner ways
 ///
 /// **Example:**
 /// ```rust
@@ -75,3 +83,4 @@ fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
         }}
     }
 }
+
index a9befd5767c2ab564b0017714da9d2a431a57374..2b506af88f5a8ca16388952d594b070d5d259261 100644 (file)
@@ -1,5 +1,5 @@
 error: this pattern takes a reference on something that is being de-referenced
- --> examples/needless_borrowed_ref.rs:8:34
+ --> needless_borrowed_ref.rs:8:34
   |
 8 |     let _ = v.iter_mut().filter(|&ref a| a.is_empty());
   |                                  ^^^^^^ help: try removing the `&ref` part and just keep `a`
@@ -8,30 +8,27 @@ error: this pattern takes a reference on something that is being de-referenced
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
 
 error: this pattern takes a reference on something that is being de-referenced
-  --> examples/needless_borrowed_ref.rs:13:17
+  --> needless_borrowed_ref.rs:13:17
    |
 13 |     if let Some(&ref v) = thingy {
    |                 ^^^^^^ help: try removing the `&ref` part and just keep `v`
    |
-   = note: `-D needless-borrowed-reference` implied by `-D warnings`
    = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
 
 error: this pattern takes a reference on something that is being de-referenced
-  --> examples/needless_borrowed_ref.rs:42:27
+  --> needless_borrowed_ref.rs:42:27
    |
 42 |         (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
    |                           ^^^^^^ help: try removing the `&ref` part and just keep `k`
    |
-   = note: `-D needless-borrowed-reference` implied by `-D warnings`
    = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
 
 error: this pattern takes a reference on something that is being de-referenced
-  --> examples/needless_borrowed_ref.rs:42:38
+  --> needless_borrowed_ref.rs:42:38
    |
 42 |         (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
    |                                      ^^^^^^ help: try removing the `&ref` part and just keep `k`
    |
-   = note: `-D needless-borrowed-reference` implied by `-D warnings`
    = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_borrowed_reference
 
 error: aborting due to previous error(s)