Skip to main content

miniextendr_lint/rules/
rf_error.rs

1//! Direct `Rf_error`/`Rf_errorcall` usage lint.
2//!
3//! - MXL300: Warns on direct `Rf_error`/`Rf_errorcall` calls in user code.
4//!   These longjmp through Rust frames, bypassing destructors unless wrapped in
5//!   `R_UnwindProtect`. Prefer `panic!()` or `Err(...)` which produce structured
6//!   R condition objects via the tagged-condition transport.
7
8use crate::crate_index::CrateIndex;
9use crate::diagnostic::Diagnostic;
10use crate::lint_code::LintCode;
11
12pub fn check(index: &CrateIndex, diagnostics: &mut Vec<Diagnostic>) {
13    for (path, data) in &index.file_data {
14        for (fn_name, line) in &data.rf_error_calls {
15            diagnostics.push(
16                Diagnostic::new(
17                    LintCode::MXL300,
18                    path,
19                    *line,
20                    format!(
21                        "Direct `{}()` call. This longjmps through Rust frames \
22                         and may skip destructors.",
23                        fn_name,
24                    ),
25                )
26                .with_help(
27                    "Use `panic!()` for unrecoverable errors or return `Err(...)` for \
28                     Result types. These produce structured R condition objects via \
29                     the tagged-condition transport.",
30                ),
31            );
32        }
33    }
34}