File tree Expand file tree Collapse file tree 2 files changed +71
-2
lines changed Expand file tree Collapse file tree 2 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -1094,13 +1094,13 @@ fn iterate_inherent_methods(
10941094 None => return ControlFlow :: Continue ( ( ) ) ,
10951095 } ;
10961096
1097- let ( module, block) = match visible_from_module {
1097+ let ( module, mut block) = match visible_from_module {
10981098 VisibleFromModule :: Filter ( module) => ( Some ( module) , module. containing_block ( ) ) ,
10991099 VisibleFromModule :: IncludeBlock ( block) => ( None , Some ( block) ) ,
11001100 VisibleFromModule :: None => ( None , None ) ,
11011101 } ;
11021102
1103- if let Some ( block_id) = block {
1103+ while let Some ( block_id) = block {
11041104 if let Some ( impls) = db. inherent_impls_in_block ( block_id) {
11051105 impls_for_self_ty (
11061106 & impls,
@@ -1113,6 +1113,11 @@ fn iterate_inherent_methods(
11131113 callback,
11141114 ) ?;
11151115 }
1116+
1117+ block = db
1118+ . block_def_map ( block_id)
1119+ . and_then ( |map| map. parent ( ) )
1120+ . and_then ( |module| module. containing_block ( ) ) ;
11161121 }
11171122
11181123 for krate in def_crates {
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments