pub struct MethodDef<'a> {
pub name: Symbol,
pub generics: Bounds,
pub explicit_self: bool,
pub args: Vec<(Ty, Symbol)>,
pub ret_ty: Ty,
pub attributes: Vec<Attribute>,
pub unify_fieldless_variants: bool,
pub combine_substructure: RefCell<Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>>,
}Fields
name: Symbolname of the method
generics: BoundsList of generics, e.g., R: rand::Rng
explicit_self: boolIs there is a &self argument? If not, it is a static function.
args: Vec<(Ty, Symbol)>Arguments other than the self argument
ret_ty: TyReturns type
attributes: Vec<Attribute>unify_fieldless_variants: boolCan we combine fieldless variants for enums into a single match arm?
combine_substructure: RefCell<Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>>Implementations
sourceimpl<'a> MethodDef<'a>
impl<'a> MethodDef<'a>
fn call_substructure_method(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
type_ident: Ident,
nonself_args: &[P<Expr>],
fields: &SubstructureFields<'_>
) -> P<Expr>
fn get_ret_ty(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
generics: &Generics,
type_ident: Ident
) -> P<Ty>
fn is_static(&self) -> bool
fn split_self_nonself_args(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
type_ident: Ident,
generics: &Generics
) -> (Option<ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<Ty>)>)
fn create_method(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
type_ident: Ident,
generics: &Generics,
explicit_self: Option<ExplicitSelf>,
arg_types: Vec<(Ident, P<Ty>)>,
body: P<Expr>
) -> P<AssocItem>
sourcefn expand_struct_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
struct_def: &'b VariantData,
type_ident: Ident,
self_args: &[P<Expr>],
nonself_args: &[P<Expr>],
use_temporaries: bool
) -> P<Expr>
fn expand_struct_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
struct_def: &'b VariantData,
type_ident: Ident,
self_args: &[P<Expr>],
nonself_args: &[P<Expr>],
use_temporaries: bool
) -> P<Expr>
#[derive(PartialEq)]
struct A { x: i32, y: i32 }
// equivalent to:
impl PartialEq for A {
fn eq(&self, other: &A) -> bool {
match *self {
A {x: ref __self_0_0, y: ref __self_0_1} => {
match *other {
A {x: ref __self_1_0, y: ref __self_1_1} => {
__self_0_0.eq(__self_1_0) && __self_0_1.eq(__self_1_1)
}
}
}
}
}
}or if A is repr(packed) - note fields are matched by-value instead of by-reference.
impl PartialEq for A {
fn eq(&self, other: &A) -> bool {
match *self {
A {x: __self_0_0, y: __self_0_1} => {
match other {
A {x: __self_1_0, y: __self_1_1} => {
__self_0_0.eq(&__self_1_0) && __self_0_1.eq(&__self_1_1)
}
}
}
}
}
}fn expand_static_struct_method_body(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
struct_def: &VariantData,
type_ident: Ident,
nonself_args: &[P<Expr>]
) -> P<Expr>
sourcefn expand_enum_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
enum_def: &'b EnumDef,
type_ident: Ident,
self_args: Vec<P<Expr>>,
nonself_args: &[P<Expr>]
) -> P<Expr>
fn expand_enum_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
enum_def: &'b EnumDef,
type_ident: Ident,
self_args: Vec<P<Expr>>,
nonself_args: &[P<Expr>]
) -> P<Expr>
#[derive(PartialEq)]
enum A {
A1,
A2(i32)
}is equivalent to:
impl ::core::cmp::PartialEq for A {
#[inline]
fn eq(&self, other: &A) -> bool {
{
let __self_vi = ::core::intrinsics::discriminant_value(&*self);
let __arg_1_vi = ::core::intrinsics::discriminant_value(&*other);
if true && __self_vi == __arg_1_vi {
match (&*self, &*other) {
(&A::A2(ref __self_0), &A::A2(ref __arg_1_0)) =>
(*__self_0) == (*__arg_1_0),
_ => true,
}
} else {
false // catch-all handler
}
}
}
}Creates a match for a tuple of all self_args, where either all
variants match, or it falls into a catch-all for when one variant
does not match.
There are N + 1 cases because is a case for each of the N variants where all of the variants match, and one catch-all for when one does not match.
As an optimization we generate code which checks whether all variants match first which makes llvm see that C-like enums can be compiled into a simple equality check (for PartialEq).
The catch-all handler is provided access the variant index values for each of the self-args, carried in precomputed variables.
fn expand_static_enum_method_body(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'_>,
enum_def: &EnumDef,
type_ident: Ident,
nonself_args: &[P<Expr>]
) -> P<Expr>
Auto Trait Implementations
impl<'a> !RefUnwindSafe for MethodDef<'a>
impl<'a> !Send for MethodDef<'a>
impl<'a> !Sync for MethodDef<'a>
impl<'a> Unpin for MethodDef<'a>
impl<'a> !UnwindSafe for MethodDef<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 168 bytes