Skip to content

Commit 298aedf

Browse files
committed
Fix suggestion for unnecessary_ref lint
1 parent 3f978af commit 298aedf

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

clippy_lints/src/reference.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl LintPass for DerefPass {
9898
impl EarlyLintPass for DerefPass {
9999
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
100100
if_chain! {
101-
if let ExprKind::Field(ref object, ref field_name) = e.node;
101+
if let ExprKind::Field(ref object, _) = e.node;
102102
if let ExprKind::Paren(ref parened) = object.node;
103103
if let ExprKind::AddrOf(_, ref inner) = parened.node;
104104
then {
@@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
109109
object.span,
110110
"Creating a reference that is immediately dereferenced.",
111111
"try this",
112-
format!(
113-
"{}.{}",
114-
snippet_with_applicability(cx, inner.span, "_", &mut applicability),
115-
snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
116-
),
112+
snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
117113
applicability,
118114
);
119115
}

tests/ui/unnecessary_ref.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
// run-rustfix
1111

12-
1312
#![feature(stmt_expr_attributes)]
13+
#![allow(unused_variables)]
1414

1515
struct Outer {
1616
inner: u32,
@@ -19,5 +19,5 @@ struct Outer {
1919
#[deny(clippy::ref_in_deref)]
2020
fn main() {
2121
let outer = Outer { inner: 0 };
22-
let inner = outer.inner.inner;
22+
let inner = outer.inner;
2323
}

tests/ui/unnecessary_ref.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// run-rustfix
1111

1212
#![feature(stmt_expr_attributes)]
13+
#![allow(unused_variables)]
1314

1415
struct Outer {
1516
inner: u32,

tests/ui/unnecessary_ref.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: Creating a reference that is immediately dereferenced.
2-
--> $DIR/unnecessary_ref.rs:21:17
2+
--> $DIR/unnecessary_ref.rs:22:17
33
|
44
LL | let inner = (&outer).inner;
5-
| ^^^^^^^^ help: try this: `outer.inner`
5+
| ^^^^^^^^ help: try this: `outer`
66
|
77
note: lint level defined here
8-
--> $DIR/unnecessary_ref.rs:18:8
8+
--> $DIR/unnecessary_ref.rs:19:8
99
|
1010
LL | #[deny(clippy::ref_in_deref)]
1111
| ^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)