(
node: Node<'_>,
functions: &BTreeMap<(usize, String), Vec<Node<'_>>>,
context: &mut Context<'_>,
issues: &mut Vec<StructuralIssue>,
)
| 2 | use std::collections::{BTreeMap, BTreeSet}; |
| 3 | |
| 4 | pub(super) fn inspect( |
| 5 | node: Node<'_>, |
| 6 | functions: &BTreeMap<(usize, String), Vec<Node<'_>>>, |
| 7 | context: &mut Context<'_>, |
| 8 | issues: &mut Vec<StructuralIssue>, |
| 9 | ) -> Result<(), &'static str> { |
| 10 | match node.kind() { |
| 11 | "function_item" => { |
| 12 | forwarding_wrapper(node, functions, context, issues)?; |
| 13 | if is_test(node, context) && !has_attribute(node, context, "should_panic") { |
| 14 | if let Some(body) = node.child_by_field_name("body") { |
| 15 | if code_children(body).is_empty() { |
| 16 | issues.push(context.issue(Rule::WeakVerification, node, "This #[test] function has an empty executable body and is not a should_panic test. It succeeds without exercising behavior or checking a result.")); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | "macro_invocation" => vacuous_assertion(node, context, issues)?, |
| 22 | "block" => guard_across_await(node, context, issues)?, |
| 23 | "unsafe_block" => { |
| 24 | context.charge(node)?; |
| 25 | if !justified(node, context, true) { |
| 26 | let body = tokens::named(node) |
| 27 | .into_iter() |
| 28 | .find(|child| child.kind() == "block"); |
| 29 | if let Some(body) = body { |
| 30 | let mut stack = vec![body]; |
| 31 | let mut operation = None; |
| 32 | while let Some(child) = stack.pop() { |
| 33 | if child.kind() == "call_expression" { |
| 34 | if let Some(function) = child.child_by_field_name("function") { |
| 35 | let target = context.compact(function)?; |
| 36 | if [ |
| 37 | "std::mem::transmute", |
| 38 | "core::mem::transmute", |
| 39 | "std::ptr::read", |
| 40 | "core::ptr::read", |
| 41 | "std::slice::from_raw_parts", |
| 42 | "core::slice::from_raw_parts", |
| 43 | ] |
| 44 | .iter() |
| 45 | .any(|prefix| { |
| 46 | target == *prefix || target.starts_with(&format!("{prefix}::<")) |
| 47 | }) { |
| 48 | operation = Some(target); |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | stack.extend(code_children(child)); |
| 54 | } |
| 55 | if let Some(operation) = operation { |
| 56 | issues.push(context.issue(Rule::UnsafeShortcuts, node, format!("Unsafe operation `{operation}` has no immediately associated SAFETY explanation of the required memory/layout/lifetime preconditions. This is a missing safety argument at the observed unchecked operation, not proof of undefined behavior."))); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | "attribute_item" | "inner_attribute_item" => { |
nothing calls this directly
no test coverage detected