Auto merge of #15312 - alexkirsz:alexkirsz/resolve-deref-raw-follow-up, r=lnicola

Don't follow raw pointer derefs when considering method receiver candidates

In https://github.com/rust-lang/rust-analyzer/pull/15118, I enabled following raw pointer derefs when considering self type candidates. However, I also inadvertently enabled it for receiver type candidates, which is invalid and causes false positives (see new test).
This commit is contained in:
bors 2023-07-19 17:52:17 +00:00
commit cecbd3f84a
2 changed files with 22 additions and 1 deletions

View File

@ -1504,7 +1504,7 @@ fn autoderef_method_receiver(
ty: Ty,
) -> Vec<(Canonical<Ty>, ReceiverAdjustments)> {
let mut deref_chain: Vec<_> = Vec::new();
let mut autoderef = autoderef::Autoderef::new(table, ty, true);
let mut autoderef = autoderef::Autoderef::new(table, ty, false);
while let Some((ty, derefs)) = autoderef.next() {
deref_chain.push((
autoderef.table.canonicalize(ty).value,

View File

@ -1236,6 +1236,27 @@ fn main() {
);
}
#[test]
fn inherent_method_ref_self_deref_raw() {
check_types(
r#"
struct Val;
impl Val {
pub fn method(&self) -> u32 {
0
}
}
fn main() {
let foo: *const Val;
foo.method();
// ^^^^^^^^^^^^ {unknown}
}
"#,
);
}
#[test]
fn trait_method_deref_raw() {
check_types(