rustc_builtin_macros::deriving::generic

Struct MethodDef

Source
pub(crate) struct MethodDef<'a> {
    pub name: Symbol,
    pub generics: Bounds,
    pub explicit_self: bool,
    pub nonself_args: Vec<(Ty, Symbol)>,
    pub ret_ty: Ty,
    pub attributes: AttrVec,
    pub fieldless_variants_strategy: FieldlessVariantsStrategy,
    pub combine_substructure: RefCell<Box<dyn FnMut(&ExtCtxt<'_>, Span, &Substructure<'_>) -> BlockOrExpr + 'a>>,
}

Fields§

§name: Symbol

name of the method

§generics: Bounds

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

§explicit_self: bool

Is there is a &self argument? If not, it is a static function.

§nonself_args: Vec<(Ty, Symbol)>

Arguments other than the self argument.

§ret_ty: Ty

Returns type

§attributes: AttrVec§fieldless_variants_strategy: FieldlessVariantsStrategy§combine_substructure: RefCell<Box<dyn FnMut(&ExtCtxt<'_>, Span, &Substructure<'_>) -> BlockOrExpr + 'a>>

Implementations§

Source§

impl<'a> MethodDef<'a>

Source

fn call_substructure_method( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, nonselflike_args: &[P<Expr>], fields: &SubstructureFields<'_>, ) -> BlockOrExpr

Source

fn get_ret_ty( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, generics: &Generics, type_ident: Ident, ) -> P<Ty>

Source

fn is_static(&self) -> bool

Source

fn extract_arg_details( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, ) -> (Option<ExplicitSelf>, ThinVec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<Ty>)>)

Source

fn create_method( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, explicit_self: Option<ExplicitSelf>, nonself_arg_tys: Vec<(Ident, P<Ty>)>, body: BlockOrExpr, ) -> P<AssocItem>

Source

fn expand_struct_method_body<'b>( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'b>, struct_def: &'b VariantData, type_ident: Ident, selflike_args: &[P<Expr>], nonselflike_args: &[P<Expr>], is_packed: bool, ) -> BlockOrExpr

The normal case uses field access.

#[derive(PartialEq)]
struct A { x: u8, y: u8 }

// equivalent to:
impl PartialEq for A {
    fn eq(&self, other: &A) -> bool {
        self.x == other.x && self.y == other.y
    }
}

But if the struct is repr(packed), we can’t use something like &self.x because that might cause an unaligned ref. So for any trait method that takes a reference, we use a local block to force a copy. This requires that the field impl Copy.

impl PartialEq for A {
    fn eq(&self, other: &A) -> bool {
        // Desugars to `{ self.x }.eq(&{ other.y }) && ...`
        { self.x } == { other.y } && { self.y } == { other.y }
    }
}
impl Hash for A {
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
        ::core::hash::Hash::hash(&{ self.x }, state);
        ::core::hash::Hash::hash(&{ self.y }, state);
    }
}
Source

fn expand_static_struct_method_body( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, struct_def: &VariantData, type_ident: Ident, nonselflike_args: &[P<Expr>], ) -> BlockOrExpr

Source

fn expand_enum_method_body<'b>( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'b>, enum_def: &'b EnumDef, type_ident: Ident, selflike_args: ThinVec<P<Expr>>, nonselflike_args: &[P<Expr>], ) -> BlockOrExpr

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

is equivalent to:

#![feature(core_intrinsics)]
enum A {
    A1,
    A2(i32)
}
impl ::core::cmp::PartialEq for A {
    #[inline]
    fn eq(&self, other: &A) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
            && match (self, other) {
                (A::A2(__self_0), A::A2(__arg1_0)) => *__self_0 == *__arg1_0,
                _ => true,
            }
    }
}

Creates a discriminant check combined with a match for a tuple of all selflike_args, with an arm for each variant with fields, possibly an arm for each fieldless variant (if unify_fieldless_variants is not Unify), and possibly a default arm.

Source

fn expand_static_enum_method_body( &self, cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, enum_def: &EnumDef, type_ident: Ident, nonselflike_args: &[P<Expr>], ) -> BlockOrExpr

Auto Trait Implementations§

§

impl<'a> !DynSend for MethodDef<'a>

§

impl<'a> !DynSync for MethodDef<'a>

§

impl<'a> !Freeze for MethodDef<'a>

§

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§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment = _

Alignment of Self.
Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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: 144 bytes