Skip to main content

Module vctrs_self_ctor

Module vctrs_self_ctor 

Source
Expand description

MXL120: vctrs constructor returns Self / named type, or impl has an instance-method receiver.

A #[miniextendr(vctrs(...))] impl has two hard invariants:

  1. Constructor return type — the constructor (fn new or a method tagged #[miniextendr(constructor)]) must NOT return Self, &Self, &mut Self, Box<Self>, the named impl type, Result<Self, _>, or Result<NamedType, _>. The generated R wrapper passes the return value to vctrs::new_vctr() / new_rcrd() / new_list_of(), which require a plain vector payload, not an ExternalPtr (EXTPTRSXP).

  2. Instance receivers — no method may carry any form of self receiver (&self, &mut self, self, self: &ExternalPtr<Self>, etc.). A vctrs object is an S3-classed base vector; there is no Rust Self stored inside the SEXP. The C wrapper cannot reconstruct Self from a base vector, so calling an instance method would panic at runtime.

§Mirror

The same checks fire as proc-macro hard errors in miniextendr-macros/src/miniextendr_impl.rs (search MXL120). This lint is defence-in-depth: it catches the mistake during the build-time static-analysis pass (when the macro isn’t being expanded, e.g. lint-only IDE runs, third-party tooling). Keep both implementations in sync: if the macro relaxes either check, update this rule too.

Functions§

check
return_type_is_self_or_named 🔒
Returns true if return_type_str represents Self, &Self, &mut Self, Box<Self>, the named type, Result<Self, _>, or Result<NamedType, _>.
ty_is_self_or_named 🔒
Recursively checks whether ty is Self, &Self, &mut Self, Box<Self>, the named type, or Result<(Self | NamedType), _>.