Skip to content

Commit

Permalink
Auto merge of #15312 - alexkirsz:alexkirsz/resolve-deref-raw-follow-u…
Browse files Browse the repository at this point in the history
…p, r=lnicola

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

In #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).
  • Loading branch information
bors committed Jul 19, 2023
2 parents 3759c41 + 5187533 commit cecbd3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/hir-ty/src/method_resolution.rs
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions crates/hir-ty/src/tests/method_resolution.rs
Expand Up @@ -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(
Expand Down

0 comments on commit cecbd3f

Please sign in to comment.