Improve diagnostic for cases where autoderef is used

This commit is contained in:
Sosthène Guédon 2022-11-20 15:34:56 +01:00
parent 6178ddaded
commit 0411edfbbd
2 changed files with 21 additions and 3 deletions

View File

@ -75,7 +75,7 @@ pub fn check_fn(
}
};
let ty = cx.typeck_results().expr_ty(self_data);
let ty = cx.typeck_results().expr_ty_adjusted(self_data);
let def = {
let mut kind = ty.kind();
@ -102,7 +102,7 @@ pub fn check_fn(
let Some(used_field) = used_field else {
// FIXME: This can be reached if the field access uses autoderef.
// `dec.all_fields()` should be replaced by something that uses autoderef.
// `dec.all_fields()` should be replaced by something that uses autoderef on the unajusted type of `self_data`
return;
};

View File

@ -126,5 +126,23 @@ LL | | &mut self.a
LL | | }
| |_____^
error: aborting due to 14 previous errors
error: getter function appears to return the wrong field
--> $DIR/misnamed_getters.rs:92:5
|
LL | / unsafe fn a(&self) -> &u8 {
LL | | &self.inner.b
| | ------------- help: consider using: `&self.inner.a`
LL | | }
| |_____^
error: getter function appears to return the wrong field
--> $DIR/misnamed_getters.rs:95:5
|
LL | / unsafe fn a_mut(&mut self) -> &mut u8 {
LL | | &mut self.inner.b
| | ----------------- help: consider using: `&mut self.inner.a`
LL | | }
| |_____^
error: aborting due to 16 previous errors