Skip to content

Commit 4bf124a

Browse files
committed
Don't analyze platform specific blocks in syntactic phase
1 parent 7446004 commit 4bf124a

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎rule-preprocessor/src/syntactic.rs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn is_va_args_type(ty: &ast::Type) -> bool {
5454
false
5555
}
5656

57-
fn cfg_matches_host(fn_item: &ast::Fn) -> bool {
58-
for attr in fn_item.attrs() {
57+
fn cfg_matches_host(attrs: impl Iterator<Item = ast::Attr>) -> bool {
58+
for attr in attrs {
5959
let Some(meta) = attr.meta() else { continue };
6060
let Some(path) = meta.path() else { continue };
6161
if path.syntax().text() != "cfg" {
@@ -135,7 +135,7 @@ impl SyntacticAnalysis {
135135
let mut file_ir = FileIr::new();
136136

137137
for fn_item in source_file.syntax().descendants().filter_map(ast::Fn::cast) {
138-
if !cfg_matches_host(&fn_item) {
138+
if !cfg_matches_host(fn_item.attrs()) {
139139
continue;
140140
}
141141

@@ -202,6 +202,16 @@ impl<'a> FragmentCtx<'a> {
202202
match child {
203203
ra_ap_syntax::NodeOrToken::Token(token) => self.visit_token(&token),
204204
ra_ap_syntax::NodeOrToken::Node(node) => {
205+
if ast::Attr::can_cast(node.kind()) {
206+
self.text_buf.push_str(&node.text().to_string());
207+
return;
208+
}
209+
if let Some(has_attrs) = ast::AnyHasAttrs::cast(node.clone())
210+
&& !cfg_matches_host(has_attrs.attrs())
211+
{
212+
self.text_buf.push_str(&node.text().to_string());
213+
return;
214+
}
205215
if let Some(call) = ast::MethodCallExpr::cast(node.clone()) {
206216
self.emit_method_call(&call);
207217
return;

0 commit comments

Comments
 (0)