Skip to content

Commit cecbd3f

Browse files
committed
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 rust-lang/rust-analyzer#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).
2 parents 3759c41 + 5187533 commit cecbd3f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/hir-ty/src/method_resolution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ fn autoderef_method_receiver(
15041504
ty: Ty,
15051505
) -> Vec<(Canonical<Ty>, ReceiverAdjustments)> {
15061506
let mut deref_chain: Vec<_> = Vec::new();
1507-
let mut autoderef = autoderef::Autoderef::new(table, ty, true);
1507+
let mut autoderef = autoderef::Autoderef::new(table, ty, false);
15081508
while let Some((ty, derefs)) = autoderef.next() {
15091509
deref_chain.push((
15101510
autoderef.table.canonicalize(ty).value,

crates/hir-ty/src/tests/method_resolution.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,27 @@ fn main() {
12361236
);
12371237
}
12381238

1239+
#[test]
1240+
fn inherent_method_ref_self_deref_raw() {
1241+
check_types(
1242+
r#"
1243+
struct Val;
1244+
1245+
impl Val {
1246+
pub fn method(&self) -> u32 {
1247+
0
1248+
}
1249+
}
1250+
1251+
fn main() {
1252+
let foo: *const Val;
1253+
foo.method();
1254+
// ^^^^^^^^^^^^ {unknown}
1255+
}
1256+
"#,
1257+
);
1258+
}
1259+
12391260
#[test]
12401261
fn trait_method_deref_raw() {
12411262
check_types(

0 commit comments

Comments
 (0)