Skip to content

Commit 8747228

Browse files
tausbnCopilot
andcommitted
Rust: fix formatting and codegen drift
Re-run cargo fmt after clippy --fix to ensure consistent formatting. Re-run codegen to update generated file tracking for MetaImpl.qll. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 68ab2fb commit 8747228

File tree

6 files changed

+44
-41
lines changed

6 files changed

+44
-41
lines changed

rust/ast-generator/src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,13 @@ fn get_fields(node: &AstNodeSrc) -> Vec<FieldInfo> {
309309
let mut result = Vec::new();
310310
for field in &node.fields {
311311
if let Field::Token { token, .. } = field
312-
&& should_predicate_be_extracted(token) {
313-
result.push(FieldInfo {
314-
name: format!("is_{token}"),
315-
ty: FieldType::Predicate,
316-
});
317-
}
312+
&& should_predicate_be_extracted(token)
313+
{
314+
result.push(FieldInfo {
315+
name: format!("is_{token}"),
316+
ty: FieldType::Predicate,
317+
});
318+
}
318319
}
319320

320321
result.extend(get_additional_fields(&node.name));

rust/extractor/src/main.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ impl<'a> Extractor<'a> {
8181
}
8282
let no_location = (LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 });
8383
if let Err(RustAnalyzerNoSemantics { severity, reason }) = semantics_info
84-
&& !reason.is_empty() {
85-
let message = format!("semantic analyzer unavailable ({reason})");
86-
let full_message = format!("{message}: macro expansion will be skipped.");
87-
translator.emit_diagnostic(
88-
severity,
89-
"semantics".to_owned(),
90-
message,
91-
full_message,
92-
no_location,
93-
);
94-
}
84+
&& !reason.is_empty()
85+
{
86+
let message = format!("semantic analyzer unavailable ({reason})");
87+
let full_message = format!("{message}: macro expansion will be skipped.");
88+
translator.emit_diagnostic(
89+
severity,
90+
"semantics".to_owned(),
91+
message,
92+
full_message,
93+
no_location,
94+
);
95+
}
9596
translator.emit_source_file(&ast);
9697
translator.emit_truncated_diagnostics_message();
9798
translator.trap.commit().unwrap_or_else(|err| {
@@ -301,15 +302,15 @@ fn main() -> anyhow::Result<()> {
301302
for (file_id, file) in vfs.iter() {
302303
if let Some(file) = file.as_path().map(<_ as AsRef<Path>>::as_ref)
303304
&& file.extension().is_some_and(|ext| ext == "rs")
304-
&& processed_files.insert(file.to_owned())
305-
&& db
306-
.source_root(db.file_source_root(file_id).source_root_id(db))
307-
.source_root(db)
308-
.is_library
309-
{
310-
extractor.extract_with_semantics(file, &semantics, vfs, library_mode);
311-
extractor.archiver.archive(file);
312-
}
305+
&& processed_files.insert(file.to_owned())
306+
&& db
307+
.source_root(db.file_source_root(file_id).source_root_id(db))
308+
.source_root(db)
309+
.is_library
310+
{
311+
extractor.extract_with_semantics(file, &semantics, vfs, library_mode);
312+
extractor.archiver.archive(file);
313+
}
313314
}
314315
} else {
315316
for file in files {

rust/extractor/src/translate/base.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ impl<'a> Translator<'a> {
216216
let parent_range = parent.syntax().text_range();
217217
let token_range = token.text_range();
218218
if let Some(clipped_range) = token_range.intersect(parent_range)
219-
&& let Some(parent_range2) = self.text_range_for_node(parent) {
220-
let token_range = clipped_range + parent_range2.start() - parent_range.start();
221-
if let Some((start, end)) = self.location(token_range) {
222-
self.trap.emit_location(self.label, label, start, end)
223-
}
219+
&& let Some(parent_range2) = self.text_range_for_node(parent)
220+
{
221+
let token_range = clipped_range + parent_range2.start() - parent_range.start();
222+
if let Some((start, end)) = self.location(token_range) {
223+
self.trap.emit_location(self.label, label, start, end)
224224
}
225+
}
225226
}
226227
pub fn emit_diagnostic(
227228
&mut self,
@@ -332,14 +333,15 @@ impl<'a> Translator<'a> {
332333
) {
333334
for child in children {
334335
if let NodeOrToken::Token(token) = child
335-
&& token.kind() == SyntaxKind::COMMENT {
336-
let label = self.trap.emit(generated::Comment {
337-
id: TrapId::Star,
338-
parent: parent_label,
339-
text: token.text().to_owned(),
340-
});
341-
self.emit_location_token(label.into(), parent_node, &token);
342-
}
336+
&& token.kind() == SyntaxKind::COMMENT
337+
{
338+
let label = self.trap.emit(generated::Comment {
339+
id: TrapId::Star,
340+
parent: parent_label,
341+
text: token.text().to_owned(),
342+
});
343+
self.emit_location_token(label.into(), parent_node, &token);
344+
}
343345
}
344346
}
345347
fn emit_macro_expansion_parse_errors(

rust/ql/.generated.list

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/MetaImpl.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ private import codeql.rust.elements.internal.generated.Meta
1111
* be referenced directly.
1212
*/
1313
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1415
/**
1516
* A meta item in an attribute.
1617
*

0 commit comments

Comments
 (0)