about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2018-12-09 17:25:45 +0100
committerPhilipp Hansch <dev@phansch.net>2018-12-28 20:54:29 +0100
commit298aedf2f874ed86a68966c7b722918b1e2bde0a (patch)
tree0a3a63db7f3f1d37b8c67f7eb5260030b4de4fbc
parent3f978afe8d2260e29dbc593fa294ccaa39b0df32 (diff)
downloadrust-298aedf2f874ed86a68966c7b722918b1e2bde0a.tar.gz
rust-298aedf2f874ed86a68966c7b722918b1e2bde0a.zip
Fix suggestion for unnecessary_ref lint
-rw-r--r--clippy_lints/src/reference.rs8
-rw-r--r--tests/ui/unnecessary_ref.fixed4
-rw-r--r--tests/ui/unnecessary_ref.rs1
-rw-r--r--tests/ui/unnecessary_ref.stderr6
4 files changed, 8 insertions, 11 deletions
diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs
index 2e35719d466..d76fa0c38b9 100644
--- a/clippy_lints/src/reference.rs
+++ b/clippy_lints/src/reference.rs
@@ -98,7 +98,7 @@ impl LintPass for DerefPass {
 impl EarlyLintPass for DerefPass {
     fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
         if_chain! {
-            if let ExprKind::Field(ref object, ref field_name) = e.node;
+            if let ExprKind::Field(ref object, _) = e.node;
             if let ExprKind::Paren(ref parened) = object.node;
             if let ExprKind::AddrOf(_, ref inner) = parened.node;
             then {
@@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
                     object.span,
                     "Creating a reference that is immediately dereferenced.",
                     "try this",
-                    format!(
-                        "{}.{}",
-                        snippet_with_applicability(cx, inner.span, "_", &mut applicability),
-                        snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
-                    ),
+                    snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
                     applicability,
                 );
             }
diff --git a/tests/ui/unnecessary_ref.fixed b/tests/ui/unnecessary_ref.fixed
index 32ad6d72054..3617641a116 100644
--- a/tests/ui/unnecessary_ref.fixed
+++ b/tests/ui/unnecessary_ref.fixed
@@ -9,8 +9,8 @@
 
 // run-rustfix
 
-
 #![feature(stmt_expr_attributes)]
+#![allow(unused_variables)]
 
 struct Outer {
     inner: u32,
@@ -19,5 +19,5 @@ struct Outer {
 #[deny(clippy::ref_in_deref)]
 fn main() {
     let outer = Outer { inner: 0 };
-    let inner = outer.inner.inner;
+    let inner = outer.inner;
 }
diff --git a/tests/ui/unnecessary_ref.rs b/tests/ui/unnecessary_ref.rs
index 4ed47cf8b5d..48101c87a54 100644
--- a/tests/ui/unnecessary_ref.rs
+++ b/tests/ui/unnecessary_ref.rs
@@ -10,6 +10,7 @@
 // run-rustfix
 
 #![feature(stmt_expr_attributes)]
+#![allow(unused_variables)]
 
 struct Outer {
     inner: u32,
diff --git a/tests/ui/unnecessary_ref.stderr b/tests/ui/unnecessary_ref.stderr
index dc221f9921e..863a6389e7f 100644
--- a/tests/ui/unnecessary_ref.stderr
+++ b/tests/ui/unnecessary_ref.stderr
@@ -1,11 +1,11 @@
 error: Creating a reference that is immediately dereferenced.
-  --> $DIR/unnecessary_ref.rs:21:17
+  --> $DIR/unnecessary_ref.rs:22:17
    |
 LL |     let inner = (&outer).inner;
-   |                 ^^^^^^^^ help: try this: `outer.inner`
+   |                 ^^^^^^^^ help: try this: `outer`
    |
 note: lint level defined here
-  --> $DIR/unnecessary_ref.rs:18:8
+  --> $DIR/unnecessary_ref.rs:19:8
    |
 LL | #[deny(clippy::ref_in_deref)]
    |        ^^^^^^^^^^^^^^^^^^^^