/// Type that the method returns. #[derive(Debug, Clone)] #[non_exhaustive] pubenum SuccessType {
Writeable,
OutType(OutType),
Unit,
}
/// Whether or not the method returns a value or a result. #[derive(Debug)] #[allow(clippy::exhaustive_enums)] // this only exists for fallible/infallible, breaking changes for more complex returns are ok pubenum ReturnType {
Infallible(SuccessType),
Fallible(SuccessType, Option<OutType>),
Nullable(SuccessType),
}
/// The `self` parameter of a method. #[derive(Debug)] #[non_exhaustive] pubstruct ParamSelf { pub ty: SelfType,
}
/// A parameter in a method. #[derive(Debug)] #[non_exhaustive] pubstruct Param { pub name: IdentBuf, pub ty: Type,
}
impl SuccessType { /// Returns whether the variant is `Writeable`. pubfn is_writeable(&self) -> bool {
matches!(self, SuccessType::Writeable)
}
/// Returns whether the variant is `Unit`. pubfn is_unit(&self) -> bool {
matches!(self, SuccessType::Unit)
}
impl ReturnType { /// Returns `true` if the FFI function returns `void`. Not that this is different from `is_unit`, /// which will be true for `DiplomatResult<(), E>` and false for infallible writeable. pubfn is_ffi_unit(&self) -> bool {
matches!( self,
ReturnType::Infallible(SuccessType::Unit | SuccessType::Writeable)
)
}
/// The "main" return type of this function: the Ok, Some, or regular type pubfn success_type(&self) -> &SuccessType { match &self { Self::Infallible(s) => s, Self::Fallible(s, _) => s, Self::Nullable(s) => s,
}
}
/// Get the list of method lifetimes actually used by the method return type /// /// Most input lifetimes aren't actually used. An input lifetime is generated /// for each borrowing parameter but is only important if we use it in the return. pubfn used_method_lifetimes(&self) -> BTreeSet<Lifetime> { letmut set = BTreeSet::new();
letmut add_to_set = |ty: &OutType| { for lt in ty.lifetimes() { iflet MaybeStatic::NonStatic(lt) = lt {
set.insert(lt);
}
}
};
/// Return the number of fields and leaves that will show up in the [`BorrowingFieldVisitor`]. /// /// This method is used to calculate how much space to allocate upfront. fn field_leaf_lifetime_counts(&self, tcx: &TypeContext) -> (usize, usize) { matchself.ty {
SelfType::Opaque(_) => (1, 1),
SelfType::Struct(ref ty) => ty.resolve(tcx).fields.iter().fold((1, 0), |acc, field| { let inner = field.ty.field_leaf_lifetime_counts(tcx);
(acc.0 + inner.0, acc.1 + inner.1)
}),
SelfType::Enum(_) => (0, 0),
}
}
}
impl Method { /// Returns a fresh [`Lifetimes`] corresponding to `self`. pubfn method_lifetimes(&self) -> Lifetimes { self.lifetime_env.lifetimes()
}
/// Returns a new [`BorrowingParamVisitor`], which can *shallowly* link output lifetimes /// to the parameters they borrow from. /// /// This is useful for backends which wish to have lifetime codegen for methods only handle the local /// method lifetime, and delegate to generated code on structs for handling the internals of struct lifetimes. pubfn borrowing_param_visitor<'tcx>(
&'tcx self,
tcx: &'tcx TypeContext,
) -> BorrowingParamVisitor<'tcx> {
BorrowingParamVisitor::new(self, tcx)
}
/// Returns a new [`BorrowingFieldVisitor`], which allocates memory to /// efficiently represent all fields (and their paths!) of the inputs that /// have a lifetime. /// /// This is useful for backends which wish to "splat out" lifetime edge codegen for methods, /// linking each borrowed input param/field (however deep it may be in a struct) to a borrowed output param/field. /// /// ```ignore /// # use std::collections::BTreeMap; /// let visitor = method.borrowing_field_visitor(&tcx, "this".ck().unwrap()); /// let mut map = BTreeMap::new(); /// visitor.visit_borrowing_fields(|lifetime, field| { /// map.entry(lifetime).or_default().push(field); /// }) /// ``` pubfn borrowing_field_visitor<'m>(
&'m self,
tcx: &'m TypeContext,
self_name: &'m Ident,
) -> BorrowingFieldVisitor<'m> {
BorrowingFieldVisitor::new(self, tcx, self_name)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet am 2026-06-23)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.