File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed
tests/e2e/find_references Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -150,12 +150,20 @@ impl SymbolDef {
150
150
pub fn search_scope ( & self , db : & AnalysisDatabase ) -> SearchScope {
151
151
match & self {
152
152
Self :: Variable ( var) => {
153
- match db. first_ancestor_of_kind ( var. syntax_node ( db) , SyntaxKind :: FunctionWithBody ) {
154
- Some ( owning_function) => SearchScope :: file_span (
153
+ if let Some ( owning_function) =
154
+ iter:: successors ( Some ( var. syntax_node ( db) ) , SyntaxNode :: parent) . find ( |node| {
155
+ matches ! (
156
+ node. kind( db. upcast( ) ) ,
157
+ SyntaxKind :: FunctionWithBody | SyntaxKind :: TraitItemFunction
158
+ )
159
+ } )
160
+ {
161
+ SearchScope :: file_span (
155
162
owning_function. stable_ptr ( ) . file_id ( db. upcast ( ) ) ,
156
163
owning_function. span ( db. upcast ( ) ) ,
157
- ) ,
158
- None => SearchScope :: file ( var. definition_stable_ptr . file_id ( db. upcast ( ) ) ) ,
164
+ )
165
+ } else {
166
+ SearchScope :: file ( var. definition_stable_ptr . file_id ( db. upcast ( ) ) )
159
167
}
160
168
}
161
169
Original file line number Diff line number Diff line change @@ -166,3 +166,28 @@ fn param_captured_by_closure() {
166
166
}
167
167
" )
168
168
}
169
+
170
+ #[ test]
171
+ fn var_in_trait_function_default_body ( ) {
172
+ test_transform ! ( find_references, r#"
173
+ trait Foo<T> {
174
+ fn foo() {
175
+ let foobar = 42;
176
+ let x = foo<caret>bar + 1;
177
+ }
178
+ }
179
+ fn bar() {
180
+ let foobar = 42;
181
+ }
182
+ "# , @r"
183
+ trait Foo<T> {
184
+ fn foo() {
185
+ let <sel=declaration>foobar</sel> = 42;
186
+ let x = <sel>foobar</sel> + 1;
187
+ }
188
+ }
189
+ fn bar() {
190
+ let foobar = 42;
191
+ }
192
+ " )
193
+ }
You can’t perform that action at this time.
0 commit comments