mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +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 {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
// run-rustfix
|
||||
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
struct Outer {
|
||||
inner: u32,
|
||||
|
|
|
@ -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)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue