@@ -95,6 +95,14 @@ fn try_lookup_include_path(
9595 if !matches ! ( & * name. text( ) , "include" | "include_str" | "include_bytes" ) {
9696 return None ;
9797 }
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+
98106 let file_id = sema. db . resolve_path ( AnchoredPath { anchor : file_id, path : & path } ) ?;
99107 let size = sema. db . file_text ( file_id) . len ( ) . try_into ( ) . ok ( ) ?;
100108 Some ( NavigationTarget {
@@ -156,9 +164,6 @@ mod tests {
156164 fn check ( ra_fixture : & str ) {
157165 let ( analysis, position, expected) = fixture:: annotations ( ra_fixture) ;
158166 let navs = analysis. goto_definition ( position) . unwrap ( ) . expect ( "no definition found" ) . info ;
159- if navs. is_empty ( ) {
160- panic ! ( "unresolved reference" )
161- }
162167
163168 let cmp = |& FileRange { file_id, range } : & _ | ( file_id, range. start ( ) ) ;
164169 let navs = navs
@@ -1348,6 +1353,10 @@ fn f(e: Enum) {
13481353 check (
13491354 r#"
13501355//- /main.rs
1356+
1357+ #[rustc_builtin_macro]
1358+ macro_rules! include_str {}
1359+
13511360fn main() {
13521361 let str = include_str!("foo.txt$0");
13531362}
@@ -1357,6 +1366,24 @@ fn main() {
13571366"# ,
13581367 ) ;
13591368 }
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+
13601387 #[ cfg( test) ]
13611388 mod goto_impl_of_trait_fn {
13621389 use super :: check;
0 commit comments