Skip to content

Commit c564065

Browse files
committed
fix(ty): should query impls in nearest block
1 parent 80cabf7 commit c564065

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

crates/hir-ty/src/method_resolution.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,25 @@ fn iterate_inherent_methods(
11131113
callback,
11141114
)?;
11151115
}
1116+
1117+
// try to find impls in the nearest ancestor block module
1118+
if let Some(impls) = db
1119+
.block_def_map(block_id)
1120+
.and_then(|map| map.parent())
1121+
.and_then(|module| module.containing_block())
1122+
.and_then(|block| db.inherent_impls_in_block(block))
1123+
{
1124+
impls_for_self_ty(
1125+
&impls,
1126+
self_ty,
1127+
table,
1128+
name,
1129+
receiver_ty,
1130+
receiver_adjustments.clone(),
1131+
module,
1132+
callback,
1133+
)?
1134+
}
11161135
}
11171136

11181137
for krate in def_crates {

crates/ide/src/goto_definition.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,4 +1916,68 @@ fn main() {
19161916
"#,
19171917
)
19181918
}
1919+
1920+
#[test]
1921+
fn query_impls_in_nearest_block() {
1922+
check(
1923+
r#"
1924+
struct S1;
1925+
impl S1 {
1926+
fn e() -> () {}
1927+
}
1928+
fn f1() {
1929+
struct S1;
1930+
impl S1 {
1931+
fn e() -> () {}
1932+
//^
1933+
}
1934+
fn f2() {
1935+
fn f3() {
1936+
S1::e$0();
1937+
}
1938+
}
1939+
}
1940+
"#,
1941+
);
1942+
1943+
check(
1944+
r#"
1945+
struct S1;
1946+
impl S1 {
1947+
fn e() -> () {}
1948+
}
1949+
fn f1() {
1950+
struct S1;
1951+
impl S1 {
1952+
fn e() -> () {}
1953+
//^
1954+
}
1955+
fn f2() {
1956+
struct S2;
1957+
S1::e$0();
1958+
}
1959+
}
1960+
fn f12() {
1961+
struct S1;
1962+
impl S1 {
1963+
fn e() -> () {}
1964+
}
1965+
}
1966+
"#,
1967+
);
1968+
1969+
check(
1970+
r#"
1971+
struct S1;
1972+
impl S1 {
1973+
fn e() -> () {}
1974+
//^
1975+
}
1976+
fn f2() {
1977+
struct S2;
1978+
S1::e$0();
1979+
}
1980+
"#,
1981+
);
1982+
}
19191983
}

0 commit comments

Comments
 (0)