1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use super::*;
pub struct UnsafeBlockRule;
impl Rule for UnsafeBlockRule {
fn name(&self) -> &'static str {
"unsafe-block"
}
fn check(&self, ctx: &mut RuleContext) {
let mut issues_to_report = Vec::new();
// Check unsafe functions first
for item in &ctx.syntax_tree.items {
if let syn::Item::Fn(func) = item {
if func.sig.unsafety.is_some() {
let (line, col) = ctx.line_col(func.sig.ident.span());
// Check for safety documentation
let has_safety_doc = func.attrs.iter().any(|attr| {
if attr.path().is_ident("doc") {
// For now, just assume it doesn't have safety docs
// A proper implementation would parse the attribute value
false
} else {
false
}
});
if !has_safety_doc {
issues_to_report.push(Issue {
rule: self.name().to_string(),
severity: Severity::Error,
message: "Unsafe function without safety documentation".to_string(),
location: Location {
line,
column: col,
end_line: None,
end_column: None,
},
fix: None,
});
}
}
}
}
// Report all issues
for issue in issues_to_report {
ctx.report(issue);
}
// TODO: Add unsafe block checking by traversing the AST more carefully
// For now, we'll skip the complex visitor pattern that causes borrowing issues
}
}