[−][src]Struct chalk_solve::rust_ir::TraitDatum
A rust intermediate representation (rust_ir) of a Trait Definition. For example, given the following rust code:
use std::fmt::Debug; trait Foo<T> where T: Debug, { type Bar<U>; }
This would represent the trait Foo
declaration. Note that the details of
the trait members (e.g., the associated type declaration (type Bar<U>
) are
not contained in this type, and are represented separately (e.g., in
AssociatedTyDatum
).
Not to be confused with the rust_ir for a Trait Implementation, which is
represented by ImplDatum
Fields
id: TraitId<I>
binders: Binders<TraitDatumBound<I>>
flags: TraitFlags
"Flags" indicate special kinds of traits, like auto traits.
In Rust syntax these are represented in different ways, but in
chalk we add annotations like #[auto]
.
associated_ty_ids: Vec<AssocTypeId<I>>
well_known: Option<WellKnownTrait>
If this is a well-known trait, which one? If None
, this is a regular,
user-defined trait.
Implementations
impl<I: Interner> TraitDatum<I>
[src]
pub fn is_auto_trait(&self) -> bool
[src]
pub fn is_non_enumerable_trait(&self) -> bool
[src]
pub fn is_coinductive_trait(&self) -> bool
[src]
pub fn where_clauses(&self) -> Binders<&Vec<QuantifiedWhereClause<I>>>
[src]
Gives access to the where clauses of the trait, quantified over the type parameters of the trait:
trait Foo<T> where T: Debug { } ^^^^^^^^^^^^^^
Trait Implementations
impl<I: Clone + Interner> Clone for TraitDatum<I>
[src]
pub fn clone(&self) -> TraitDatum<I>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<I: Debug + Interner> Debug for TraitDatum<I>
[src]
impl<I: Eq + Interner> Eq for TraitDatum<I>
[src]
impl<I: Hash + Interner> Hash for TraitDatum<I>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<I: PartialEq + Interner> PartialEq<TraitDatum<I>> for TraitDatum<I>
[src]
pub fn eq(&self, other: &TraitDatum<I>) -> bool
[src]
pub fn ne(&self, other: &TraitDatum<I>) -> bool
[src]
impl<I: Interner> StructuralEq for TraitDatum<I>
[src]
impl<I: Interner> StructuralPartialEq for TraitDatum<I>
[src]
impl<I: Interner> ToProgramClauses<I> for TraitDatum<I>
[src]
pub fn to_program_clauses(
&self,
builder: &mut ClauseBuilder<'_, I>,
environment: &Environment<I>
)
[src]
&self,
builder: &mut ClauseBuilder<'_, I>,
environment: &Environment<I>
)
Given the following trait declaration: trait Ord<T> where Self: Eq<T> { ... }
, generate:
-- Rule WellFormed-TraitRef
forall<Self, T> {
WF(Self: Ord<T>) :- Implemented(Self: Ord<T>), WF(Self: Eq<T>).
}
and the reverse rules:
-- Rule Implemented-From-Env
forall<Self, T> {
(Self: Ord<T>) :- FromEnv(Self: Ord<T>).
}
-- Rule Implied-Bound-From-Trait
forall<Self, T> {
FromEnv(Self: Eq<T>) :- FromEnv(Self: Ord<T>).
}
As specified in the orphan rules, if a trait is not marked #[upstream]
, the current crate
can implement it for any type. To represent that, we generate:
// `Ord<T>` would not be `#[upstream]` when compiling `std`
forall<Self, T> { LocalImplAllowed(Self: Ord<T>). }
For traits that are #[upstream]
(i.e. not in the current crate), the orphan rules dictate
that impls are allowed as long as at least one type parameter is local and each type
prior to that is fully visible. That means that each type prior to the first local
type cannot contain any of the type parameters of the impl.
This rule is fairly complex, so we expand it and generate a program clause for each possible case. This is represented as follows:
// for `#[upstream] trait Foo<T, U, V> where Self: Eq<T> { ... }`
forall<Self, T, U, V> {
LocalImplAllowed(Self: Foo<T, U, V>) :- IsLocal(Self).
}
forall<Self, T, U, V> {
LocalImplAllowed(Self: Foo<T, U, V>) :-
IsFullyVisible(Self),
IsLocal(T).
}
forall<Self, T, U, V> {
LocalImplAllowed(Self: Foo<T, U, V>) :-
IsFullyVisible(Self),
IsFullyVisible(T),
IsLocal(U).
}
forall<Self, T, U, V> {
LocalImplAllowed(Self: Foo<T, U, V>) :-
IsFullyVisible(Self),
IsFullyVisible(T),
IsFullyVisible(U),
IsLocal(V).
}
The overlap check uses compatible { ... } mode to ensure that it accounts for impls that may exist in some other compatible world. For every upstream trait, we add a rule to account for the fact that upstream crates are able to compatibly add impls of upstream traits for upstream types.
// For `#[upstream] trait Foo<T, U, V> where Self: Eq<T> { ... }`
forall<Self, T, U, V> {
Implemented(Self: Foo<T, U, V>) :-
Implemented(Self: Eq<T>), // where clauses
Compatible, // compatible modality
IsUpstream(Self),
IsUpstream(T),
IsUpstream(U),
IsUpstream(V),
CannotProve. // returns ambiguous
}
In certain situations, this is too restrictive. Consider the following code:
/* In crate std */
trait Sized { }
struct str { }
/* In crate bar (depends on std) */
trait Bar { }
impl Bar for str { }
impl<T> Bar for T where T: Sized { }
Here, because of the rules we've defined, these two impls overlap. The std crate is upstream to bar, and thus it is allowed to compatibly implement Sized for str. If str can implement Sized in a compatible future, these two impls definitely overlap since the second impl covers all types that implement Sized.
The solution we've got right now is to mark Sized as "fundamental" when it is defined. This signals to the Rust compiler that it can rely on the fact that str does not implement Sized in all contexts. A consequence of this is that we can no longer add an implementation of Sized compatibly for str. This is the trade off you make when defining a fundamental trait.
To implement fundamental traits, we simply just do not add the rule above that allows upstream types to implement upstream traits. Fundamental traits are not allowed to compatibly do that.
impl<I: Interner> Visit<I> for TraitDatum<I>
[src]
pub fn visit_with<'i, B>(
&self,
visitor: &mut dyn Visitor<'i, I, BreakTy = B>,
outer_binder: DebruijnIndex
) -> ControlFlow<B> where
I: 'i,
[src]
&self,
visitor: &mut dyn Visitor<'i, I, BreakTy = B>,
outer_binder: DebruijnIndex
) -> ControlFlow<B> where
I: 'i,
Auto Trait Implementations
impl<I> RefUnwindSafe for TraitDatum<I> where
<I as Interner>::DefId: RefUnwindSafe,
<I as Interner>::InternedLifetime: RefUnwindSafe,
<I as Interner>::InternedSubstitution: RefUnwindSafe,
<I as Interner>::InternedType: RefUnwindSafe,
<I as Interner>::InternedVariableKinds: RefUnwindSafe,
<I as Interner>::DefId: RefUnwindSafe,
<I as Interner>::InternedLifetime: RefUnwindSafe,
<I as Interner>::InternedSubstitution: RefUnwindSafe,
<I as Interner>::InternedType: RefUnwindSafe,
<I as Interner>::InternedVariableKinds: RefUnwindSafe,
impl<I> Send for TraitDatum<I> where
<I as Interner>::DefId: Send,
<I as Interner>::InternedLifetime: Send,
<I as Interner>::InternedSubstitution: Send,
<I as Interner>::InternedType: Send,
<I as Interner>::InternedVariableKinds: Send,
<I as Interner>::DefId: Send,
<I as Interner>::InternedLifetime: Send,
<I as Interner>::InternedSubstitution: Send,
<I as Interner>::InternedType: Send,
<I as Interner>::InternedVariableKinds: Send,
impl<I> Sync for TraitDatum<I> where
<I as Interner>::DefId: Sync,
<I as Interner>::InternedLifetime: Sync,
<I as Interner>::InternedSubstitution: Sync,
<I as Interner>::InternedType: Sync,
<I as Interner>::InternedVariableKinds: Sync,
<I as Interner>::DefId: Sync,
<I as Interner>::InternedLifetime: Sync,
<I as Interner>::InternedSubstitution: Sync,
<I as Interner>::InternedType: Sync,
<I as Interner>::InternedVariableKinds: Sync,
impl<I> Unpin for TraitDatum<I> where
<I as Interner>::DefId: Unpin,
<I as Interner>::InternedLifetime: Unpin,
<I as Interner>::InternedSubstitution: Unpin,
<I as Interner>::InternedType: Unpin,
<I as Interner>::InternedVariableKinds: Unpin,
<I as Interner>::DefId: Unpin,
<I as Interner>::InternedLifetime: Unpin,
<I as Interner>::InternedSubstitution: Unpin,
<I as Interner>::InternedType: Unpin,
<I as Interner>::InternedVariableKinds: Unpin,
impl<I> UnwindSafe for TraitDatum<I> where
<I as Interner>::DefId: UnwindSafe,
<I as Interner>::InternedLifetime: UnwindSafe,
<I as Interner>::InternedSubstitution: UnwindSafe,
<I as Interner>::InternedType: UnwindSafe,
<I as Interner>::InternedVariableKinds: UnwindSafe,
<I as Interner>::DefId: UnwindSafe,
<I as Interner>::InternedLifetime: UnwindSafe,
<I as Interner>::InternedSubstitution: UnwindSafe,
<I as Interner>::InternedType: UnwindSafe,
<I as Interner>::InternedVariableKinds: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Cast for T
[src]
pub fn cast<U>(self, interner: &<U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
[src]
Self: CastTo<U>,
U: HasInterner,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, I> VisitExt<I> for T where
I: Interner,
T: Visit<I>,
[src]
I: Interner,
T: Visit<I>,