Skip to content

Commit

Permalink
Fix suggestion for unnecessary_ref lint
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Dec 9, 2018
1 parent d2e452e commit bf6792b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
8 changes: 2 additions & 6 deletions clippy_lints/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/unnecessary_ref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


#![feature(stmt_expr_attributes)]
#![allow(unused_variables)]

struct Outer {
inner: u32,
Expand All @@ -19,5 +20,5 @@ struct Outer {
#[deny(clippy::ref_in_deref)]
fn main() {
let outer = Outer { inner: 0 };
let inner = outer.inner.inner;
let inner = outer.inner;
}
1 change: 1 addition & 0 deletions tests/ui/unnecessary_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


#![feature(stmt_expr_attributes)]
#![allow(unused_variables)]

struct Outer {
inner: u32,
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/unnecessary_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: Creating a reference that is immediately dereferenced.
--> $DIR/unnecessary_ref.rs:22:17
--> $DIR/unnecessary_ref.rs:23:17
|
22 | let inner = (&outer).inner;
| ^^^^^^^^ help: try this: `outer.inner`
23 | let inner = (&outer).inner;
| ^^^^^^^^ help: try this: `outer`
|
note: lint level defined here
--> $DIR/unnecessary_ref.rs:19:8
--> $DIR/unnecessary_ref.rs:20:8
|
19 | #[deny(clippy::ref_in_deref)]
20 | #[deny(clippy::ref_in_deref)]
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
Expand Down

0 comments on commit bf6792b

Please sign in to comment.