[−][src]Struct rustc_builtin_macros::deriving::generic::MethodDef

pub struct MethodDef<'a> {
    pub name: Symbol,
    pub generics: Bounds,
    pub explicit_self: Option<Option<PtrTy>>,
    pub args: Vec<(Ty, Symbol)>,
    pub ret_ty: Ty,
    pub attributes: Vec<Attribute>,
    pub is_unsafe: bool,
    pub unify_fieldless_variants: bool,
    pub combine_substructure: RefCell<Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>>,
}

Fields

name: Symbol

name of the method

generics: Bounds

List of generics, e.g., R: rand::Rng

explicit_self: Option<Option<PtrTy>>

Whether there is a self argument (outer Option) i.e., whether this is a static function, and whether it is a pointer (inner Option)

args: Vec<(Ty, Symbol)>

Arguments other than the self argument

ret_ty: Ty

Returns type

attributes: Vec<Attribute>is_unsafe: boolunify_fieldless_variants: bool

Can 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

impl<'a> MethodDef<'a>[src]

pub(in deriving::generic) fn call_substructure_method(
    &self,
    cx: &mut ExtCtxt<'_>,
    trait_: &TraitDef<'_>,
    type_ident: Ident,
    self_args: &[P<Expr>],
    nonself_args: &[P<Expr>],
    fields: &SubstructureFields<'_>
) -> P<Expr>
[src]

pub(in deriving::generic) fn get_ret_ty(
    &self,
    cx: &mut ExtCtxt<'_>,
    trait_: &TraitDef<'_>,
    generics: &Generics,
    type_ident: Ident
) -> P<Ty>
[src]

pub(in deriving::generic) fn is_static(
    &self
) -> bool
[src]

pub(in deriving::generic) 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>)>)
[src]

pub(in deriving::generic) 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>
[src]

pub(in deriving::generic) 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>
[src]

#[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)
                    }
                }
            }
        }
    }
}

pub(in deriving::generic) fn expand_static_struct_method_body(
    &self,
    cx: &mut ExtCtxt<'_>,
    trait_: &TraitDef<'_>,
    struct_def: &VariantData,
    type_ident: Ident,
    self_args: &[P<Expr>],
    nonself_args: &[P<Expr>]
) -> P<Expr>
[src]

pub(in deriving::generic) 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>
[src]

#[derive(PartialEq)]
enum A {
    A1,
    A2(i32)
}

// is equivalent to

impl PartialEq for A {
    fn eq(&self, other: &A) -> ::bool {
        match (&*self, &*other) {
            (&A1, &A1) => true,
            (&A2(ref self_0),
             &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)),
            _ => {
                let __self_vi = match *self { A1(..) => 0, A2(..) => 1 };
                let __arg_1_vi = match *other { A1(..) => 0, A2(..) => 1 };
                false
            }
        }
    }
}

(Of course __self_vi and __arg_1_vi are unused for PartialEq, and those subcomputations will hopefully be removed as their results are unused. The point of __self_vi and __arg_1_vi is for PartialOrd; see #15503.)

pub(in deriving::generic) fn build_enum_match_tuple<'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>
[src]

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.

let __self0_vi = std::intrinsics::discriminant_value(&self);
let __self1_vi = std::intrinsics::discriminant_value(&arg1);
let __self2_vi = std::intrinsics::discriminant_value(&arg2);

if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
    match (...) {
        (Variant1, Variant1, ...) => Body1
        (Variant2, Variant2, ...) => Body2,
        ...
        _ => ::core::intrinsics::unreachable()
    }
}
else {
    ... // catch-all remainder can inspect above variant index values.
}

pub(in deriving::generic) fn expand_static_enum_method_body(
    &self,
    cx: &mut ExtCtxt<'_>,
    trait_: &TraitDef<'_>,
    enum_def: &EnumDef,
    type_ident: Ident,
    self_args: &[P<Expr>],
    nonself_args: &[P<Expr>]
) -> P<Expr>
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.