Fix suggestion for unnecessary_ref lint

This commit is contained in:
Philipp Hansch 2018-12-09 17:25:45 +01:00
parent 3f978afe8d
commit 298aedf2f8
No known key found for this signature in database
GPG key ID: B6FA06A6E0E2665B
4 changed files with 8 additions and 11 deletions

View file

@ -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,
);
}

View file

@ -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;
}

View file

@ -10,6 +10,7 @@
// run-rustfix
#![feature(stmt_expr_attributes)]
#![allow(unused_variables)]
struct Outer {
inner: u32,

View file

@ -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)]
| ^^^^^^^^^^^^^^^^^^^^