Skip to content

Commit b28f8ef

Browse files
committed
field
1 parent c334e54 commit b28f8ef

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

clippy_lints/src/needless_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl LateLintPass<'_> for NeedlessDeref {
6767
if span.from_expansion() {
6868
return;
6969
}
70-
if matches!(deref_expr.kind, ExprKind::Path(..)) {
70+
if matches!(deref_expr.kind, ExprKind::Path(..) | ExprKind::Field(..)) {
7171
if let Some(parent_node) = map.find(parent_hir_id) {
7272
if let rustc_hir::Node::Local(..) = parent_node {
7373
let outer_ty = cx.typeck_results().node_type(parent_hir_id);

tests/ui/needless_deref.rs

+14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ mod should_not_lint2 {
3737
}
3838
}
3939

40+
// similar to should_not_lint2
41+
mod should_not_lint3 {
42+
struct S<'a> {
43+
a: &'a u32,
44+
b: u32,
45+
}
46+
47+
fn main() {
48+
let s = S { a: &1, b: 1 };
49+
let x = &mut &*s.a;
50+
*x = &2;
51+
}
52+
}
53+
4054
// this mod explains why we should not lint `& &* (&T)`
4155
mod false_negative {
4256
fn foo() {

tests/ui/needless_deref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | let b = &mut &*bar(a);
1717
= help: consider using `bar(a)` if you would like to reborrow
1818

1919
error: deref on an immutable reference
20-
--> $DIR/needless_deref.rs:45:23
20+
--> $DIR/needless_deref.rs:59:23
2121
|
2222
LL | let addr_y = &&*x as *const _ as usize; // assert ok
2323
| ^^^

0 commit comments

Comments
 (0)