Skip to content

Commit bf6792b

Browse files
committed
Fix suggestion for unnecessary_ref lint
1 parent d2e452e commit bf6792b

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
#![feature(stmt_expr_attributes)]
14+
#![allow(unused_variables)]
1415

1516
struct Outer {
1617
inner: u32,
@@ -19,5 +20,5 @@ struct Outer {
1920
#[deny(clippy::ref_in_deref)]
2021
fn main() {
2122
let outer = Outer { inner: 0 };
22-
let inner = outer.inner.inner;
23+
let inner = outer.inner;
2324
}

tests/ui/unnecessary_ref.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
#![feature(stmt_expr_attributes)]
14+
#![allow(unused_variables)]
1415

1516
struct Outer {
1617
inner: u32,

tests/ui/unnecessary_ref.stderr

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

1313
error: aborting due to previous error

0 commit comments

Comments
 (0)