File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -167,9 +167,19 @@ impl<'a> Extractor<'a> {
167167 let Some ( id) = path_to_file_id ( file, vfs) else {
168168 return Err ( "not included in files loaded from manifest" . to_string ( ) ) ;
169169 } ;
170- if semantics. file_to_module_def ( id) . is_none ( ) {
171- return Err ( "not included as a module" . to_string ( ) ) ;
172- }
170+ match semantics. file_to_module_def ( id) {
171+ None => return Err ( "not included as a module" . to_string ( ) ) ,
172+ Some ( module)
173+ if module
174+ . as_source_file_id ( semantics. db )
175+ . is_none_or ( |mod_file_id| mod_file_id. file_id ( semantics. db ) != id) =>
176+ {
177+ return Err (
178+ "not loaded as its own module, probably included by `!include`" . to_string ( ) ,
179+ ) ;
180+ }
181+ _ => { }
182+ } ;
173183 self . steps . push ( ExtractionStep :: load_source ( before, file) ) ;
174184 Ok ( ( ) )
175185 }
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ macro_rules! pre_emit {
2929 return Some ( label) ;
3030 }
3131 } ;
32+ ( Meta , $self: ident, $node: ident) => {
33+ // rust-analyzer doesn't expand macros in this context
34+ $self. macro_context_depth += 1 ;
35+ } ;
3236 ( $( $_: tt) * ) => { } ;
3337}
3438
@@ -122,7 +126,7 @@ pub struct Translator<'a> {
122126 pub semantics : Option < & ' a Semantics < ' a , RootDatabase > > ,
123127 resolve_paths : bool ,
124128 source_kind : SourceKind ,
125- macro_context_depth : usize ,
129+ pub ( crate ) macro_context_depth : usize ,
126130}
127131
128132const UNKNOWN_LOCATION : ( LineCol , LineCol ) =
You can’t perform that action at this time.
0 commit comments