mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge branch 'main' into redsun82/cargo-upgrade-3
This commit is contained in:
@@ -26,7 +26,17 @@ use ra_ap_syntax::{
|
||||
macro_rules! pre_emit {
|
||||
(Item, $self:ident, $node:ident) => {
|
||||
if let Some(label) = $self.prepare_item_expansion($node) {
|
||||
return Some(label);
|
||||
return Some(label.into());
|
||||
}
|
||||
};
|
||||
(AssocItem, $self:ident, $node:ident) => {
|
||||
if let Some(label) = $self.prepare_item_expansion(&$node.clone().into()) {
|
||||
return Some(label.into());
|
||||
}
|
||||
};
|
||||
(ExternItem, $self:ident, $node:ident) => {
|
||||
if let Some(label) = $self.prepare_item_expansion(&$node.clone().into()) {
|
||||
return Some(label.into());
|
||||
}
|
||||
};
|
||||
(Meta, $self:ident, $node:ident) => {
|
||||
@@ -36,6 +46,22 @@ macro_rules! pre_emit {
|
||||
($($_:tt)*) => {};
|
||||
}
|
||||
|
||||
// TODO: remove the mannually written Label conversions. These can be auto-generated by
|
||||
// changing the base class of AssocItem from AstNode to Item
|
||||
impl From<crate::trap::Label<generated::AssocItem>> for crate::trap::Label<generated::Item> {
|
||||
fn from(value: crate::trap::Label<generated::AssocItem>) -> Self {
|
||||
// SAFETY: this is safe because every concrete instance of `@assoc_item` is also an instance of `@item`
|
||||
unsafe { Self::from_untyped(value.as_untyped()) }
|
||||
}
|
||||
}
|
||||
// TODO: remove the mannually written Label conversions. These can be auto-generated by
|
||||
// changing the base class of ExternItem from AstNode to Item
|
||||
impl From<crate::trap::Label<generated::ExternItem>> for crate::trap::Label<generated::Item> {
|
||||
fn from(value: crate::trap::Label<generated::ExternItem>) -> Self {
|
||||
// SAFETY: this is safe because every concrete instance of `@extern_item` is also an instance of `@item`
|
||||
unsafe { Self::from_untyped(value.as_untyped()) }
|
||||
}
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! post_emit {
|
||||
(MacroCall, $self:ident, $node:ident, $label:ident) => {
|
||||
@@ -66,6 +92,18 @@ macro_rules! post_emit {
|
||||
(Item, $self:ident, $node:ident, $label:ident) => {
|
||||
$self.emit_item_expansion($node, $label);
|
||||
};
|
||||
(AssocItem, $self:ident, $node:ident, $label:ident) => {
|
||||
$self.emit_item_expansion(
|
||||
&$node.clone().into(),
|
||||
From::<Label<generated::AssocItem>>::from($label),
|
||||
);
|
||||
};
|
||||
(ExternItem, $self:ident, $node:ident, $label:ident) => {
|
||||
$self.emit_item_expansion(
|
||||
&$node.clone().into(),
|
||||
From::<Label<generated::ExternItem>>::from($label),
|
||||
);
|
||||
};
|
||||
// TODO canonical origin of other items
|
||||
(PathExpr, $self:ident, $node:ident, $label:ident) => {
|
||||
$self.extract_path_canonical_destination($node, $label.into());
|
||||
@@ -737,10 +775,21 @@ impl<'a> Translator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_attribute_macro_target(&self, node: &ast::Item) -> bool {
|
||||
// rust-analyzer considers as an `attr_macro_call` also a plain macro call, but we want to
|
||||
// process that differently (in `extract_macro_call_expanded`)
|
||||
!matches!(node, ast::Item::MacroCall(_))
|
||||
&& self.semantics.is_some_and(|semantics| {
|
||||
let file = semantics.hir_file_for(node.syntax());
|
||||
let node = InFile::new(file, node);
|
||||
semantics.is_attr_macro_call(node)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_item_expansion(
|
||||
&mut self,
|
||||
node: &ast::Item,
|
||||
) -> Option<Label<generated::Item>> {
|
||||
) -> Option<Label<generated::MacroCall>> {
|
||||
if self.source_kind == SourceKind::Library {
|
||||
// if the item expands via an attribute macro, we want to only emit the expansion
|
||||
if let Some(expanded) = self.emit_attribute_macro_expansion(node) {
|
||||
@@ -757,13 +806,10 @@ impl<'a> Translator<'a> {
|
||||
expanded.into(),
|
||||
&mut self.trap.writer,
|
||||
);
|
||||
return Some(label.into());
|
||||
return Some(label);
|
||||
}
|
||||
}
|
||||
let semantics = self.semantics.as_ref()?;
|
||||
let file = semantics.hir_file_for(node.syntax());
|
||||
let node = InFile::new(file, node);
|
||||
if semantics.is_attr_macro_call(node) {
|
||||
if self.is_attribute_macro_target(node) {
|
||||
self.macro_context_depth += 1;
|
||||
}
|
||||
None
|
||||
@@ -773,10 +819,7 @@ impl<'a> Translator<'a> {
|
||||
&mut self,
|
||||
node: &ast::Item,
|
||||
) -> Option<Label<generated::MacroItems>> {
|
||||
let semantics = self.semantics?;
|
||||
let file = semantics.hir_file_for(node.syntax());
|
||||
let infile_node = InFile::new(file, node);
|
||||
if !semantics.is_attr_macro_call(infile_node) {
|
||||
if !self.is_attribute_macro_target(node) {
|
||||
return None;
|
||||
}
|
||||
self.macro_context_depth -= 1;
|
||||
|
||||
Reference in New Issue
Block a user