@@ -95,6 +95,14 @@ fn try_lookup_include_path(
95
95
if !matches ! ( & * name. text( ) , "include" | "include_str" | "include_bytes" ) {
96
96
return None ;
97
97
}
98
+
99
+ // Ignore non-built-in macros to account for shadowing
100
+ if let Some ( it) = sema. resolve_macro_call ( & macro_call) {
101
+ if !matches ! ( it. kind( sema. db) , hir:: MacroKind :: BuiltIn ) {
102
+ return None ;
103
+ }
104
+ }
105
+
98
106
let file_id = sema. db . resolve_path ( AnchoredPath { anchor : file_id, path : & path } ) ?;
99
107
let size = sema. db . file_text ( file_id) . len ( ) . try_into ( ) . ok ( ) ?;
100
108
Some ( NavigationTarget {
@@ -156,9 +164,6 @@ mod tests {
156
164
fn check ( ra_fixture : & str ) {
157
165
let ( analysis, position, expected) = fixture:: annotations ( ra_fixture) ;
158
166
let navs = analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
159
- if navs. is_empty ( ) {
160
- panic ! ( "unresolved reference" )
161
- }
162
167
163
168
let cmp = |& FileRange { file_id, range } : & _ | ( file_id, range. start ( ) ) ;
164
169
let navs = navs
@@ -1348,6 +1353,10 @@ fn f(e: Enum) {
1348
1353
check (
1349
1354
r#"
1350
1355
//- /main.rs
1356
+
1357
+ #[rustc_builtin_macro]
1358
+ macro_rules! include_str {}
1359
+
1351
1360
fn main() {
1352
1361
let str = include_str!("foo.txt$0");
1353
1362
}
@@ -1357,6 +1366,24 @@ fn main() {
1357
1366
"# ,
1358
1367
) ;
1359
1368
}
1369
+
1370
+ #[ test]
1371
+ fn goto_shadow_include ( ) {
1372
+ check (
1373
+ r#"
1374
+ //- /main.rs
1375
+ macro_rules! include {
1376
+ ("included.rs") => {}
1377
+ }
1378
+
1379
+ include!("included.rs$0");
1380
+
1381
+ //- /included.rs
1382
+ // empty
1383
+ "# ,
1384
+ ) ;
1385
+ }
1386
+
1360
1387
#[ cfg( test) ]
1361
1388
mod goto_impl_of_trait_fn {
1362
1389
use super :: check;
0 commit comments