Skip to main content

miniextendr_lint/rules/
lifetime_param.rs

1//! MXL112: explicit lifetime parameter on `#[miniextendr]` function or impl block.
2//!
3//! The C wrapper generated by the proc-macro is `#[no_mangle] extern "C-unwind"`,
4//! which is incompatible with any generic parameter — including lifetimes.
5//! `&[T]` and `&str` arguments work without explicit lifetime annotations because
6//! the macro handles them internally via `TryFromSexp`.
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 (name, line) in &data.lifetime_param_items {
15            diagnostics.push(
16                Diagnostic::new(
17                    LintCode::MXL112,
18                    path,
19                    *line,
20                    format!(
21                        "`{name}` has an explicit lifetime parameter on a `#[miniextendr]` \
22                         item; lifetime parameters are not supported at the FFI boundary",
23                    ),
24                )
25                .with_help(
26                    "use owned types (`Vec<T>` instead of `&[T]`, `String` instead of `&str`) \
27                     or remove the explicit lifetime annotation — `&[T]` and `&str` arguments \
28                     work without explicit lifetime params",
29                ),
30            );
31        }
32    }
33}