mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
fix(ty): should query impls in nearest block
This commit is contained in:
parent
80cabf7260
commit
9a15cc81b4
2 changed files with 71 additions and 2 deletions
|
@ -1094,13 +1094,13 @@ fn iterate_inherent_methods(
|
||||||
None => return ControlFlow::Continue(()),
|
None => return ControlFlow::Continue(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (module, block) = match visible_from_module {
|
let (module, mut block) = match visible_from_module {
|
||||||
VisibleFromModule::Filter(module) => (Some(module), module.containing_block()),
|
VisibleFromModule::Filter(module) => (Some(module), module.containing_block()),
|
||||||
VisibleFromModule::IncludeBlock(block) => (None, Some(block)),
|
VisibleFromModule::IncludeBlock(block) => (None, Some(block)),
|
||||||
VisibleFromModule::None => (None, None),
|
VisibleFromModule::None => (None, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(block_id) = block {
|
while let Some(block_id) = block {
|
||||||
if let Some(impls) = db.inherent_impls_in_block(block_id) {
|
if let Some(impls) = db.inherent_impls_in_block(block_id) {
|
||||||
impls_for_self_ty(
|
impls_for_self_ty(
|
||||||
&impls,
|
&impls,
|
||||||
|
@ -1113,6 +1113,11 @@ fn iterate_inherent_methods(
|
||||||
callback,
|
callback,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
block = db
|
||||||
|
.block_def_map(block_id)
|
||||||
|
.and_then(|map| map.parent())
|
||||||
|
.and_then(|module| module.containing_block());
|
||||||
}
|
}
|
||||||
|
|
||||||
for krate in def_crates {
|
for krate in def_crates {
|
||||||
|
|
|
@ -1916,4 +1916,68 @@ fn main() {
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn query_impls_in_nearest_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
}
|
||||||
|
fn f1() {
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
//^
|
||||||
|
}
|
||||||
|
fn f2() {
|
||||||
|
fn f3() {
|
||||||
|
S1::e$0();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
}
|
||||||
|
fn f1() {
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
//^
|
||||||
|
}
|
||||||
|
fn f2() {
|
||||||
|
struct S2;
|
||||||
|
S1::e$0();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn f12() {
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S1;
|
||||||
|
impl S1 {
|
||||||
|
fn e() -> () {}
|
||||||
|
//^
|
||||||
|
}
|
||||||
|
fn f2() {
|
||||||
|
struct S2;
|
||||||
|
S1::e$0();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue