pub struct TraitDecl {
pub def_id: TraitDeclId,
pub item_meta: ItemMeta,
pub generics: GenericParams,
pub parent_clauses: Vector<TraitClauseId, TraitClause>,
pub consts: Vec<TraitAssocConst>,
pub types: Vec<Binder<TraitAssocTy>>,
pub methods: Vec<Binder<TraitMethod>>,
pub vtable: Option<TypeDeclRef>,
}
Expand description
A trait declaration.
For instance:
trait Foo {
type Bar;
fn baz(...); // required method (see below)
fn test() -> bool { true } // provided method (see below)
}
In case of a trait declaration, we don’t include the provided methods (the methods with a default implementation): they will be translated on a per-need basis. This is important for two reasons:
- this makes the trait definitions a lot smaller (the Iterator trait has one declared function and more than 70 provided functions)
- this is important for the external traits, whose provided methods often use features we don’t support yet
Remark: In Aeneas, we still translate the provided methods on an individual basis, and in such a way thay they take as input a trait instance. This means that we can use default methods but:
- implementations of required methods shoudln’t call default methods
- trait implementations shouldn’t redefine required methods
The use case we have in mind is std::iter::Iterator: it declares one required
method (
next
) that should be implemented for every iterator, and defines many helpers likeall
,map
, etc. that shouldn’t be re-implemented. Of course, this forbids other useful use cases such as visitors implemented by means of traits.
Fields§
§def_id: TraitDeclId
§item_meta: ItemMeta
§generics: GenericParams
§parent_clauses: Vector<TraitClauseId, TraitClause>
The “parent” clauses: the supertraits.
Supertraits are actually regular where clauses, but we decided to have a custom treatment.
trait Foo : Bar {
^^^
supertrait, that we treat as a parent predicate
}
TODO: actually, as of today, we consider that all trait clauses of trait declarations are parent clauses.
consts: Vec<TraitAssocConst>
The associated constants declared in the trait.
types: Vec<Binder<TraitAssocTy>>
The associated types declared in the trait. The binder binds the generic parameters of the type if it is a GAT (Generic Associated Type). For a plain associated type the binder binds nothing.
methods: Vec<Binder<TraitMethod>>
The methods declared by the trait. The binder binds the generic parameters of the method.
trait Trait<T> {
// The `Binder` for this method binds `'a` and `U`.
fn method<'a, U>(x: &'a U);
}
vtable: Option<TypeDeclRef>
The virtual table struct for this trait, if it has one. It is guaranteed that the trait has a vtable iff it is dyn-compatible.
Implementations§
Trait Implementations§
Source§impl AstVisitable for TraitDecl
impl AstVisitable for TraitDecl
Source§fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner
.Source§fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner
.Source§fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
self
, in pre-order traversal.Source§fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
self
, in pre-order traversal.Source§impl<'de> Deserialize<'de> for TraitDecl
impl<'de> Deserialize<'de> for TraitDecl
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'s, V> Drive<'s, V> for TraitDeclwhere
V: Visitor + Visit<'s, ItemMeta> + Visit<'s, GenericParams> + Visit<'s, Vector<TraitClauseId, TraitClause>> + Visit<'s, Vec<TraitAssocConst>> + Visit<'s, Vec<Binder<TraitAssocTy>>> + Visit<'s, Vec<Binder<TraitMethod>>> + Visit<'s, Option<TypeDeclRef>>,
impl<'s, V> Drive<'s, V> for TraitDeclwhere
V: Visitor + Visit<'s, ItemMeta> + Visit<'s, GenericParams> + Visit<'s, Vector<TraitClauseId, TraitClause>> + Visit<'s, Vec<TraitAssocConst>> + Visit<'s, Vec<Binder<TraitAssocTy>>> + Visit<'s, Vec<Binder<TraitMethod>>> + Visit<'s, Option<TypeDeclRef>>,
Source§fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit()
on the immediate contents of self
.Source§impl<'s, V> DriveMut<'s, V> for TraitDeclwhere
V: Visitor + VisitMut<'s, ItemMeta> + VisitMut<'s, GenericParams> + VisitMut<'s, Vector<TraitClauseId, TraitClause>> + VisitMut<'s, Vec<TraitAssocConst>> + VisitMut<'s, Vec<Binder<TraitAssocTy>>> + VisitMut<'s, Vec<Binder<TraitMethod>>> + VisitMut<'s, Option<TypeDeclRef>>,
impl<'s, V> DriveMut<'s, V> for TraitDeclwhere
V: Visitor + VisitMut<'s, ItemMeta> + VisitMut<'s, GenericParams> + VisitMut<'s, Vector<TraitClauseId, TraitClause>> + VisitMut<'s, Vec<TraitAssocConst>> + VisitMut<'s, Vec<Binder<TraitAssocTy>>> + VisitMut<'s, Vec<Binder<TraitMethod>>> + VisitMut<'s, Option<TypeDeclRef>>,
Source§fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit()
on the immediate contents of self
.Source§impl<C: AstFormatter> FmtWithCtx<C> for TraitDecl
impl<C: AstFormatter> FmtWithCtx<C> for TraitDecl
Auto Trait Implementations§
impl Freeze for TraitDecl
impl RefUnwindSafe for TraitDecl
impl Send for TraitDecl
impl Sync for TraitDecl
impl Unpin for TraitDecl
impl UnwindSafe for TraitDecl
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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§impl<I> RecreateContext<I> for I
impl<I> RecreateContext<I> for I
§fn recreate_context(_original_input: I, tail: I) -> I
fn recreate_context(_original_input: I, tail: I) -> I
Source§impl<T> TyVisitable for Twhere
T: AstVisitable,
impl<T> TyVisitable for Twhere
T: AstVisitable,
Source§fn visit_vars(&mut self, v: &mut impl VarsVisitor)
fn visit_vars(&mut self, v: &mut impl VarsVisitor)
self
, as seen from the outside of self
. This means
that any variable bound inside self
will be skipped, and all the seen De Bruijn indices
will count from the outside of self
.fn substitute(self, generics: &GenericArgs) -> Self
fn substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Self
Source§fn move_under_binder(self) -> Self
fn move_under_binder(self) -> Self
Source§fn move_under_binders(self, depth: DeBruijnId) -> Self
fn move_under_binders(self, depth: DeBruijnId) -> Self
depth
binders.Source§fn move_from_under_binder(self) -> Option<Self>
fn move_from_under_binder(self) -> Option<Self>
Source§fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
depth
binders. Returns None
if it contains a variable bound in
one of these depth
binders.Source§fn visit_db_id<B>(
&mut self,
f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>
self
, as seen from the outside of self
. This means
that any variable bound inside self
will be skipped, and all the seen indices will count
from the outside of self.