Expand description
MXL120: vctrs constructor returns Self / named type, or impl has an instance-method receiver.
A #[miniextendr(vctrs(...))] impl has two hard invariants:
-
Constructor return type — the constructor (
fn newor a method tagged#[miniextendr(constructor)]) must NOT returnSelf,&Self,&mut Self,Box<Self>, the named impl type,Result<Self, _>, orResult<NamedType, _>. The generated R wrapper passes the return value tovctrs::new_vctr()/new_rcrd()/new_list_of(), which require a plain vector payload, not anExternalPtr(EXTPTRSXP). -
Instance receivers — no method may carry any form of
selfreceiver (&self,&mut self,self,self: &ExternalPtr<Self>, etc.). A vctrs object is an S3-classed base vector; there is no RustSelfstored inside the SEXP. The C wrapper cannot reconstructSelffrom 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_strrepresentsSelf,&Self,&mut Self,Box<Self>, the named type,Result<Self, _>, orResult<NamedType, _>. - ty_
is_ 🔒self_ or_ named - Recursively checks whether
tyisSelf,&Self,&mut Self,Box<Self>, the named type, orResult<(Self | NamedType), _>.