Skip to content

Commit c145457

Browse files
committed
Rust: suppress semantics for source files included via include!
1 parent aadf486 commit c145457

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

rust/extractor/src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

rust/ql/integration-tests/macro-expansion/test.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ unexpanded_macro_calls
3838
| calls/src/lib.rs:22:9:22:31 | concat!... |
3939
| calls/src/lib.rs:29:9:29:32 | include_str!... |
4040
warnings
41-
| calls/src/included.rs:2:9:2:39 | macro expansion failed: could not resolve macro 'concat' |
41+
| calls/src/included.rs:1:1:1:1 | semantic analyzer unavailable (not loaded as its own module, probably included by `!include`) |
4242
| calls/src/lib.rs:22:9:22:31 | macro expansion failed: could not resolve macro 'concat' |

0 commit comments

Comments
 (0)