Struct rustc_builtin_macros::deriving::generic::MethodDef
source · pub 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(&mut 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(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> BlockOrExpr + 'a>>
Implementations§
source§impl<'a> MethodDef<'a>
impl<'a> MethodDef<'a>
fn call_substructure_method( &self, cx: &mut ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, nonselflike_args: &[P<Expr>], fields: &SubstructureFields<'_> ) -> BlockOrExpr
fn get_ret_ty( &self, cx: &mut ExtCtxt<'_>, trait_: &TraitDef<'_>, generics: &Generics, type_ident: Ident ) -> P<Ty>
fn is_static(&self) -> bool
fn extract_arg_details( &self, cx: &mut ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics ) -> (Option<ExplicitSelf>, ThinVec<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>, nonself_arg_tys: Vec<(Ident, P<Ty>)>, body: BlockOrExpr ) -> P<AssocItem>
sourcefn expand_struct_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
struct_def: &'b VariantData,
type_ident: Ident,
selflike_args: &[P<Expr>],
nonselflike_args: &[P<Expr>],
is_packed: bool
) -> BlockOrExpr
fn expand_struct_method_body<'b>( &self, cx: &mut 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)
}
}
fn expand_static_struct_method_body( &self, cx: &mut ExtCtxt<'_>, trait_: &TraitDef<'_>, struct_def: &VariantData, type_ident: Ident, nonselflike_args: &[P<Expr>] ) -> BlockOrExpr
sourcefn expand_enum_method_body<'b>(
&self,
cx: &mut ExtCtxt<'_>,
trait_: &TraitDef<'b>,
enum_def: &'b EnumDef,
type_ident: Ident,
selflike_args: ThinVec<P<Expr>>,
nonselflike_args: &[P<Expr>]
) -> BlockOrExpr
fn expand_enum_method_body<'b>( &self, cx: &mut 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_tag = ::core::intrinsics::discriminant_value(self);
let __arg1_tag = ::core::intrinsics::discriminant_value(other);
__self_tag == __arg1_tag &&
match (self, other) {
(A::A2(__self_0), A::A2(__arg1_0)) =>
*__self_0 == *__arg1_0,
_ => true,
}
}
}
Creates a tag 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.
fn expand_static_enum_method_body( &self, cx: &mut ExtCtxt<'_>, trait_: &TraitDef<'_>, enum_def: &EnumDef, type_ident: Ident, nonselflike_args: &[P<Expr>] ) -> BlockOrExpr
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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