1 #![deny(rust_2018_idioms)]
4 use chalk_ir
::interner
::Interner
;
20 #[cfg(feature = "recursive-solver")]
27 pub trait RustIrDatabase
<I
: Interner
>: Debug
{
28 /// Returns any "custom program clauses" that do not derive from
29 /// Rust IR. Used only in testing the underlying solver.
30 fn custom_clauses(&self) -> Vec
<ProgramClause
<I
>>;
32 /// Returns the datum for the associated type with the given id.
33 fn associated_ty_data(&self, ty
: AssocTypeId
<I
>) -> Arc
<AssociatedTyDatum
<I
>>;
35 /// Returns the datum for the definition with the given id.
36 fn trait_datum(&self, trait_id
: TraitId
<I
>) -> Arc
<TraitDatum
<I
>>;
38 /// Returns the datum for the impl with the given id.
39 fn adt_datum(&self, adt_id
: AdtId
<I
>) -> Arc
<AdtDatum
<I
>>;
41 fn fn_def_datum(&self, fn_def_id
: FnDefId
<I
>) -> Arc
<FnDefDatum
<I
>>;
43 /// Returns the datum for the impl with the given id.
44 fn impl_datum(&self, impl_id
: ImplId
<I
>) -> Arc
<ImplDatum
<I
>>;
46 /// Returns the `AssociatedTyValue` with the given id.
47 fn associated_ty_value(&self, id
: AssociatedTyValueId
<I
>) -> Arc
<AssociatedTyValue
<I
>>;
49 /// Returns the `OpaqueTyDatum` with the given id.
50 fn opaque_ty_data(&self, id
: OpaqueTyId
<I
>) -> Arc
<OpaqueTyDatum
<I
>>;
52 /// Returns the "hidden type" corresponding with the opaque type.
53 fn hidden_opaque_type(&self, id
: OpaqueTyId
<I
>) -> Ty
<I
>;
55 /// Returns a list of potentially relevant impls for a given
56 /// trait-id; we also supply the type parameters that we are
57 /// trying to match (if known: these parameters may contain
58 /// inference variables, for example). The implementor is
59 /// permitted to return any superset of the applicable impls;
60 /// chalk will narrow down the list to only those that truly
61 /// apply. The parameters are provided as a "hint" to help the
62 /// implementor do less work, but can be completely ignored if
64 fn impls_for_trait(&self, trait_id
: TraitId
<I
>, parameters
: &[GenericArg
<I
>])
67 /// Returns the impls that require coherence checking. This is not the
68 /// full set of impls that exist:
70 /// - It can exclude impls not defined in the current crate.
71 /// - It can exclude "built-in" impls, like those for closures; only the
72 /// impls actually written by users need to be checked.
73 fn local_impls_to_coherence_check(&self, trait_id
: TraitId
<I
>) -> Vec
<ImplId
<I
>>;
75 /// Returns true if there is an explicit impl of the auto trait
76 /// `auto_trait_id` for the ADT `adt_id`. This is part of
77 /// the auto trait handling -- if there is no explicit impl given
78 /// by the user for the struct, then we provide default impls
79 /// based on the field types (otherwise, we rely on the impls the
81 fn impl_provided_for(&self, auto_trait_id
: TraitId
<I
>, adt_id
: AdtId
<I
>) -> bool
;
83 /// A stop-gap solution to force an impl for a given well-known trait.
84 /// Useful when the logic for a given trait is absent or incomplete.
85 /// A value of `Some(true)` means that the the clause for the impl will be
86 /// added. A value of `Some(false)` means that the clause for the impl will
87 /// not be added, and fallback logic will not be checked. A value of `None`
88 /// means that the clause will not be added, but fallback logic may add logic.
89 #[allow(unused_variables)]
90 fn force_impl_for(&self, well_known
: WellKnownTrait
, ty
: &TyData
<I
>) -> Option
<bool
> {
94 /// Returns id of a trait lang item, if found
95 fn well_known_trait_id(&self, well_known_trait
: WellKnownTrait
) -> Option
<TraitId
<I
>>;
97 /// Calculates program clauses from an env. This is intended to call the
98 /// `program_clauses_for_env` function and then possibly cache the clauses.
99 fn program_clauses_for_env(&self, environment
: &Environment
<I
>) -> ProgramClauses
<I
>;
101 fn interner(&self) -> &I
;
103 /// Check if a trait is object safe
104 fn is_object_safe(&self, trait_id
: TraitId
<I
>) -> bool
;
106 /// Gets the `ClosureKind` for a given closure and substitution.
107 fn closure_kind(&self, closure_id
: ClosureId
<I
>, substs
: &Substitution
<I
>) -> ClosureKind
;
109 /// Gets the inputs and output for a given closure id and substitution. We
110 /// pass both the `ClosureId` and it's `Substituion` to give implementors
111 /// the freedom to store associated data in the substitution (like rustc) or
112 /// separately (like chalk-integration).
113 fn closure_inputs_and_output(
115 closure_id
: ClosureId
<I
>,
116 substs
: &Substitution
<I
>,
117 ) -> Binders
<FnDefInputsAndOutputDatum
<I
>>;
119 /// Gets the upvars as a `Ty` for a given closure id and substitution. There
120 /// are no restrictions on the type of upvars.
121 fn closure_upvars(&self, closure_id
: ClosureId
<I
>, substs
: &Substitution
<I
>) -> Binders
<Ty
<I
>>;
123 /// Gets the substitution for the closure when used as a function.
124 /// For example, for the following (not-quite-)rust code:
126 /// let foo = |a: &mut u32| { a += 1; };
127 /// let c: &'a u32 = &0;
131 /// This would return a `Substitution` of `[&'a]`. This could either be
132 /// substituted into the inputs and output, or into the upvars.
133 fn closure_fn_substitution(
135 closure_id
: ClosureId
<I
>,
136 substs
: &Substitution
<I
>,
137 ) -> Substitution
<I
>;
140 pub use clauses
::program_clauses_for_env
;
142 pub use solve
::Guidance
;
143 pub use solve
::Solution
;
144 pub use solve
::Solver
;
145 pub use solve
::SolverChoice
;
146 pub use solve
::SubstitutionResult
;
151 macro_rules
! debug_span
{
153 let __span
= tracing
::debug_span
!($
($t
)*);
154 let __span
= __span
.enter();