Rust: suppress some expected macro expansion warnings

This commit is contained in:
Paolo Tranquilli
2025-06-20 17:56:09 +02:00
parent 02a9d4c86d
commit 7edae1eb17
2 changed files with 18 additions and 4 deletions

View File

@@ -167,9 +167,19 @@ impl<'a> Extractor<'a> {
let Some(id) = path_to_file_id(file, vfs) else {
return Err("not included in files loaded from manifest".to_string());
};
if semantics.file_to_module_def(id).is_none() {
return Err("not included as a module".to_string());
}
match semantics.file_to_module_def(id) {
None => return Err("not included as a module".to_string()),
Some(module)
if module
.as_source_file_id(semantics.db)
.is_none_or(|mod_file_id| mod_file_id.file_id(semantics.db) != id) =>
{
return Err(
"not loaded as its own module, probably included by `!include`".to_string(),
);
}
_ => {}
};
self.steps.push(ExtractionStep::load_source(before, file));
Ok(())
}

View File

@@ -29,6 +29,10 @@ macro_rules! pre_emit {
return Some(label);
}
};
(Meta, $self:ident, $node:ident) => {
// rust-analyzer doesn't expand macros in this context
$self.macro_context_depth += 1;
};
($($_:tt)*) => {};
}
@@ -122,7 +126,7 @@ pub struct Translator<'a> {
pub semantics: Option<&'a Semantics<'a, RootDatabase>>,
resolve_paths: bool,
source_kind: SourceKind,
macro_context_depth: usize,
pub(crate) macro_context_depth: usize,
}
const UNKNOWN_LOCATION: (LineCol, LineCol) =