9786: fix: Fix detection of macro file in inactive-code diag r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9753

`HirFileId::expansion_info` can return `None` for builtin macros or if there's an error in the macro call or definition, so add a `HirFileId::is_macro` method that checks the right thing.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-08-04 16:04:35 +00:00 committed by GitHub
commit 294cfd61c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -173,6 +173,10 @@ impl HirFileId {
_ => false,
}
}
pub fn is_macro(self) -> bool {
matches!(self.0, HirFileIdRepr::MacroFile(_))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -11,7 +11,7 @@ pub(crate) fn inactive_code(
d: &hir::InactiveCode,
) -> Option<Diagnostic> {
// If there's inactive code somewhere in a macro, don't propagate to the call-site.
if d.node.file_id.expansion_info(ctx.sema.db).is_some() {
if d.node.file_id.is_macro() {
return None;
}