mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Fix suggestion for unnecessary_ref lint
This commit is contained in:
parent
3f978afe8d
commit
298aedf2f8
4 changed files with 8 additions and 11 deletions
|
@ -98,7 +98,7 @@ impl LintPass for DerefPass {
|
||||||
impl EarlyLintPass for DerefPass {
|
impl EarlyLintPass for DerefPass {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
||||||
if_chain! {
|
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::Paren(ref parened) = object.node;
|
||||||
if let ExprKind::AddrOf(_, ref inner) = parened.node;
|
if let ExprKind::AddrOf(_, ref inner) = parened.node;
|
||||||
then {
|
then {
|
||||||
|
@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
|
||||||
object.span,
|
object.span,
|
||||||
"Creating a reference that is immediately dereferenced.",
|
"Creating a reference that is immediately dereferenced.",
|
||||||
"try this",
|
"try this",
|
||||||
format!(
|
snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
|
||||||
"{}.{}",
|
|
||||||
snippet_with_applicability(cx, inner.span, "_", &mut applicability),
|
|
||||||
snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
|
|
||||||
),
|
|
||||||
applicability,
|
applicability,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
struct Outer {
|
struct Outer {
|
||||||
inner: u32,
|
inner: u32,
|
||||||
|
@ -19,5 +19,5 @@ struct Outer {
|
||||||
#[deny(clippy::ref_in_deref)]
|
#[deny(clippy::ref_in_deref)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let outer = Outer { inner: 0 };
|
let outer = Outer { inner: 0 };
|
||||||
let inner = outer.inner.inner;
|
let inner = outer.inner;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
struct Outer {
|
struct Outer {
|
||||||
inner: u32,
|
inner: u32,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
error: Creating a reference that is immediately dereferenced.
|
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;
|
LL | let inner = (&outer).inner;
|
||||||
| ^^^^^^^^ help: try this: `outer.inner`
|
| ^^^^^^^^ help: try this: `outer`
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/unnecessary_ref.rs:18:8
|
--> $DIR/unnecessary_ref.rs:19:8
|
||||||
|
|
|
|
||||||
LL | #[deny(clippy::ref_in_deref)]
|
LL | #[deny(clippy::ref_in_deref)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
Loading…
Reference in a new issue