Skip to content

Commit 0411edf

Browse files
committed
Improve diagnostic for cases where autoderef is used
1 parent 6178dda commit 0411edf

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

clippy_lints/src/functions/misnamed_getters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn check_fn(
7575
}
7676
};
7777

78-
let ty = cx.typeck_results().expr_ty(self_data);
78+
let ty = cx.typeck_results().expr_ty_adjusted(self_data);
7979

8080
let def = {
8181
let mut kind = ty.kind();
@@ -102,7 +102,7 @@ pub fn check_fn(
102102

103103
let Some(used_field) = used_field else {
104104
// FIXME: This can be reached if the field access uses autoderef.
105-
// `dec.all_fields()` should be replaced by something that uses autoderef.
105+
// `dec.all_fields()` should be replaced by something that uses autoderef on the unajusted type of `self_data`
106106
return;
107107
};
108108

tests/ui/misnamed_getters.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,23 @@ LL | | &mut self.a
126126
LL | | }
127127
| |_____^
128128

129-
error: aborting due to 14 previous errors
129+
error: getter function appears to return the wrong field
130+
--> $DIR/misnamed_getters.rs:92:5
131+
|
132+
LL | / unsafe fn a(&self) -> &u8 {
133+
LL | | &self.inner.b
134+
| | ------------- help: consider using: `&self.inner.a`
135+
LL | | }
136+
| |_____^
137+
138+
error: getter function appears to return the wrong field
139+
--> $DIR/misnamed_getters.rs:95:5
140+
|
141+
LL | / unsafe fn a_mut(&mut self) -> &mut u8 {
142+
LL | | &mut self.inner.b
143+
| | ----------------- help: consider using: `&mut self.inner.a`
144+
LL | | }
145+
| |_____^
146+
147+
error: aborting due to 16 previous errors
130148

0 commit comments

Comments
 (0)