Skip to content

Commit ddc3caa

Browse files
committed
Subsume ref_in_deref into needless_borrow
1 parent 2eacf3f commit ddc3caa

21 files changed

+67
-182
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,6 @@ Released 2018-09-13
32273227
[`redundant_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
32283228
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
32293229
[`ref_binding_to_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
3230-
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
32313230
[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
32323231
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
32333232
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once

clippy_lints/src/lib.register_all.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
247247
LintId::of(redundant_slicing::REDUNDANT_SLICING),
248248
LintId::of(redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
249249
LintId::of(reference::DEREF_ADDROF),
250-
LintId::of(reference::REF_IN_DEREF),
251250
LintId::of(regex::INVALID_REGEX),
252251
LintId::of(repeat_once::REPEAT_ONCE),
253252
LintId::of(returns::LET_AND_RETURN),

clippy_lints/src/lib.register_complexity.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
7171
LintId::of(redundant_closure_call::REDUNDANT_CLOSURE_CALL),
7272
LintId::of(redundant_slicing::REDUNDANT_SLICING),
7373
LintId::of(reference::DEREF_ADDROF),
74-
LintId::of(reference::REF_IN_DEREF),
7574
LintId::of(repeat_once::REPEAT_ONCE),
7675
LintId::of(strings::STRING_FROM_UTF8_AS_BYTES),
7776
LintId::of(strlen_on_c_strings::STRLEN_ON_C_STRINGS),

clippy_lints/src/lib.register_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ store.register_lints(&[
423423
redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
424424
ref_option_ref::REF_OPTION_REF,
425425
reference::DEREF_ADDROF,
426-
reference::REF_IN_DEREF,
427426
regex::INVALID_REGEX,
428427
regex::TRIVIAL_REGEX,
429428
repeat_once::REPEAT_ONCE,

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
703703
store.register_late_pass(|| Box::new(mut_key::MutableKeyType));
704704
store.register_late_pass(|| Box::new(modulo_arithmetic::ModuloArithmetic));
705705
store.register_early_pass(|| Box::new(reference::DerefAddrOf));
706-
store.register_early_pass(|| Box::new(reference::RefInDeref));
707706
store.register_early_pass(|| Box::new(double_parens::DoubleParens));
708707
store.register_late_pass(|| Box::new(to_string_in_display::ToStringInDisplay::new()));
709708
store.register_early_pass(|| Box::new(unsafe_removed_from_name::UnsafeNameRemoval));
@@ -935,6 +934,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
935934
ls.register_renamed("clippy::if_let_some_result", "clippy::match_result_ok");
936935
ls.register_renamed("clippy::disallowed_type", "clippy::disallowed_types");
937936
ls.register_renamed("clippy::disallowed_method", "clippy::disallowed_methods");
937+
ls.register_renamed("clippy::ref_in_deref", "clippy::needless_borrow");
938938

939939
// uplifted lints
940940
ls.register_renamed("clippy::invalid_ref", "invalid_value");

clippy_lints/src/reference.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
3-
use clippy_utils::sugg::Sugg;
43
use if_chain::if_chain;
54
use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
65
use rustc_errors::Applicability;
@@ -104,59 +103,3 @@ impl EarlyLintPass for DerefAddrOf {
104103
}
105104
}
106105
}
107-
108-
declare_clippy_lint! {
109-
/// ### What it does
110-
/// Checks for references in expressions that use
111-
/// auto dereference.
112-
///
113-
/// ### Why is this bad?
114-
/// The reference is a no-op and is automatically
115-
/// dereferenced by the compiler and makes the code less clear.
116-
///
117-
/// ### Example
118-
/// ```rust
119-
/// struct Point(u32, u32);
120-
/// let point = Point(30, 20);
121-
/// let x = (&point).0;
122-
/// ```
123-
/// Use instead:
124-
/// ```rust
125-
/// # struct Point(u32, u32);
126-
/// # let point = Point(30, 20);
127-
/// let x = point.0;
128-
/// ```
129-
#[clippy::version = "pre 1.29.0"]
130-
pub REF_IN_DEREF,
131-
complexity,
132-
"Use of reference in auto dereference expression."
133-
}
134-
135-
declare_lint_pass!(RefInDeref => [REF_IN_DEREF]);
136-
137-
impl EarlyLintPass for RefInDeref {
138-
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
139-
if_chain! {
140-
if let ExprKind::Field(ref object, _) = e.kind;
141-
if let ExprKind::Paren(ref parened) = object.kind;
142-
if let ExprKind::AddrOf(_, _, ref inner) = parened.kind;
143-
then {
144-
let applicability = if inner.span.from_expansion() {
145-
Applicability::MaybeIncorrect
146-
} else {
147-
Applicability::MachineApplicable
148-
};
149-
let sugg = Sugg::ast(cx, inner, "_").maybe_par();
150-
span_lint_and_sugg(
151-
cx,
152-
REF_IN_DEREF,
153-
object.span,
154-
"creating a reference that is immediately dereferenced",
155-
"try this",
156-
sugg.to_string(),
157-
applicability,
158-
);
159-
}
160-
}
161-
}
162-
}

tests/ui/borrow_interior_mutable_const/others.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#![warn(clippy::borrow_interior_mutable_const)]
2-
#![allow(
3-
clippy::declare_interior_mutable_const,
4-
clippy::ref_in_deref,
5-
clippy::needless_borrow
6-
)]
2+
#![allow(clippy::declare_interior_mutable_const, clippy::needless_borrow)]
73
#![allow(const_item_mutation)]
84

95
use std::borrow::Cow;

tests/ui/borrow_interior_mutable_const/others.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: a `const` item with interior mutability should not be borrowed
2-
--> $DIR/others.rs:58:5
2+
--> $DIR/others.rs:54:5
33
|
44
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
55
| ^^^^^^
@@ -8,103 +8,103 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
88
= help: assign this const to a local or static variable, and use the variable here
99

1010
error: a `const` item with interior mutability should not be borrowed
11-
--> $DIR/others.rs:59:16
11+
--> $DIR/others.rs:55:16
1212
|
1313
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
1414
| ^^^^^^
1515
|
1616
= help: assign this const to a local or static variable, and use the variable here
1717

1818
error: a `const` item with interior mutability should not be borrowed
19-
--> $DIR/others.rs:62:22
19+
--> $DIR/others.rs:58:22
2020
|
2121
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
2222
| ^^^^^^^^^
2323
|
2424
= help: assign this const to a local or static variable, and use the variable here
2525

2626
error: a `const` item with interior mutability should not be borrowed
27-
--> $DIR/others.rs:63:25
27+
--> $DIR/others.rs:59:25
2828
|
2929
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
3030
| ^^^^^^^^^
3131
|
3232
= help: assign this const to a local or static variable, and use the variable here
3333

3434
error: a `const` item with interior mutability should not be borrowed
35-
--> $DIR/others.rs:64:27
35+
--> $DIR/others.rs:60:27
3636
|
3737
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
3838
| ^^^^^^^^^
3939
|
4040
= help: assign this const to a local or static variable, and use the variable here
4141

4242
error: a `const` item with interior mutability should not be borrowed
43-
--> $DIR/others.rs:65:26
43+
--> $DIR/others.rs:61:26
4444
|
4545
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
4646
| ^^^^^^^^^
4747
|
4848
= help: assign this const to a local or static variable, and use the variable here
4949

5050
error: a `const` item with interior mutability should not be borrowed
51-
--> $DIR/others.rs:76:14
51+
--> $DIR/others.rs:72:14
5252
|
5353
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
5454
| ^^^^^^^^^^^^
5555
|
5656
= help: assign this const to a local or static variable, and use the variable here
5757

5858
error: a `const` item with interior mutability should not be borrowed
59-
--> $DIR/others.rs:77:14
59+
--> $DIR/others.rs:73:14
6060
|
6161
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
6262
| ^^^^^^^^^^^^
6363
|
6464
= help: assign this const to a local or static variable, and use the variable here
6565

6666
error: a `const` item with interior mutability should not be borrowed
67-
--> $DIR/others.rs:78:19
67+
--> $DIR/others.rs:74:19
6868
|
6969
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
7070
| ^^^^^^^^^^^^
7171
|
7272
= help: assign this const to a local or static variable, and use the variable here
7373

7474
error: a `const` item with interior mutability should not be borrowed
75-
--> $DIR/others.rs:79:14
75+
--> $DIR/others.rs:75:14
7676
|
7777
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
7878
| ^^^^^^^^^^^^
7979
|
8080
= help: assign this const to a local or static variable, and use the variable here
8181

8282
error: a `const` item with interior mutability should not be borrowed
83-
--> $DIR/others.rs:80:13
83+
--> $DIR/others.rs:76:13
8484
|
8585
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
8686
| ^^^^^^^^^^^^
8787
|
8888
= help: assign this const to a local or static variable, and use the variable here
8989

9090
error: a `const` item with interior mutability should not be borrowed
91-
--> $DIR/others.rs:86:13
91+
--> $DIR/others.rs:82:13
9292
|
9393
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
9494
| ^^^^^^^^^^^^
9595
|
9696
= help: assign this const to a local or static variable, and use the variable here
9797

9898
error: a `const` item with interior mutability should not be borrowed
99-
--> $DIR/others.rs:91:5
99+
--> $DIR/others.rs:87:5
100100
|
101101
LL | CELL.set(2); //~ ERROR interior mutability
102102
| ^^^^
103103
|
104104
= help: assign this const to a local or static variable, and use the variable here
105105

106106
error: a `const` item with interior mutability should not be borrowed
107-
--> $DIR/others.rs:92:16
107+
--> $DIR/others.rs:88:16
108108
|
109109
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
110110
| ^^^^

tests/ui/explicit_deref_methods.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_variables, clippy::clone_double_ref)]
3+
#![allow(unused_variables, clippy::clone_double_ref, clippy::needless_borrow)]
44
#![warn(clippy::explicit_deref_methods)]
55

66
use std::ops::{Deref, DerefMut};

tests/ui/explicit_deref_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![allow(unused_variables, clippy::clone_double_ref)]
3+
#![allow(unused_variables, clippy::clone_double_ref, clippy::needless_borrow)]
44
#![warn(clippy::explicit_deref_methods)]
55

66
use std::ops::{Deref, DerefMut};

tests/ui/format.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// run-rustfix
22

3-
#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
3+
#![allow(
4+
clippy::print_literal,
5+
clippy::redundant_clone,
6+
clippy::to_string_in_format_args,
7+
clippy::needless_borrow
8+
)]
49
#![warn(clippy::useless_format)]
510

611
struct Foo(pub String);

tests/ui/format.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// run-rustfix
22

3-
#![allow(clippy::print_literal, clippy::redundant_clone, clippy::to_string_in_format_args)]
3+
#![allow(
4+
clippy::print_literal,
5+
clippy::redundant_clone,
6+
clippy::to_string_in_format_args,
7+
clippy::needless_borrow
8+
)]
49
#![warn(clippy::useless_format)]
510

611
struct Foo(pub String);

0 commit comments

Comments
 (0)