1 //! Contains a `LoggingIrDatabase` which returns stub versions of everything
7 AdtDatumBound
, AdtKind
, AdtVariantDatum
, AssociatedTyDatumBound
, FnDefDatumBound
,
8 OpaqueTyDatumBound
, TraitDatumBound
,
13 interner
::Interner
, ApplicationTy
, Binders
, CanonicalVarKinds
, TypeName
, VariableKinds
,
17 pub struct StubWrapper
<'a
, DB
> {
21 impl<'a
, DB
> StubWrapper
<'a
, DB
> {
22 pub fn new(db
: &'a DB
) -> Self {
27 impl<I
: Interner
, DB
: RustIrDatabase
<I
>> RustIrDatabase
<I
> for StubWrapper
<'_
, DB
> {
28 fn custom_clauses(&self) -> Vec
<chalk_ir
::ProgramClause
<I
>> {
29 self.db
.custom_clauses()
32 fn associated_ty_data(
34 ty
: chalk_ir
::AssocTypeId
<I
>,
35 ) -> std
::sync
::Arc
<crate::rust_ir
::AssociatedTyDatum
<I
>> {
36 let mut v
= (*self.db
.associated_ty_data(ty
)).clone();
37 v
.binders
= Binders
::new(
38 v
.binders
.binders
.clone(),
39 AssociatedTyDatumBound
{
40 where_clauses
: Vec
::new(),
49 trait_id
: chalk_ir
::TraitId
<I
>,
50 ) -> std
::sync
::Arc
<crate::rust_ir
::TraitDatum
<I
>> {
51 let mut v
= (*self.db
.trait_datum(trait_id
)).clone();
52 v
.binders
= Binders
::new(
53 v
.binders
.binders
.clone(),
55 where_clauses
: Vec
::new(),
61 fn adt_datum(&self, adt_id
: chalk_ir
::AdtId
<I
>) -> std
::sync
::Arc
<crate::rust_ir
::AdtDatum
<I
>> {
62 let mut v
= (*self.db
.adt_datum(adt_id
)).clone();
63 let variants
= match v
.kind
{
64 AdtKind
::Struct
| AdtKind
::Union
=> vec
![AdtVariantDatum { fields: vec![] }
],
65 AdtKind
::Enum
=> vec
![],
67 v
.binders
= Binders
::new(
68 v
.binders
.binders
.clone(),
71 where_clauses
: Vec
::new(),
77 fn adt_repr(&self, id
: chalk_ir
::AdtId
<I
>) -> crate::rust_ir
::AdtRepr
{
83 fn_def_id
: chalk_ir
::FnDefId
<I
>,
84 ) -> std
::sync
::Arc
<crate::rust_ir
::FnDefDatum
<I
>> {
85 let mut v
= (*self.db
.fn_def_datum(fn_def_id
)).clone();
86 v
.binders
= Binders
::new(
87 v
.binders
.binders
.clone(),
89 inputs_and_output
: v
.binders
.skip_binders().inputs_and_output
.clone(),
90 where_clauses
: Vec
::new(),
98 _impl_id
: chalk_ir
::ImplId
<I
>,
99 ) -> std
::sync
::Arc
<crate::rust_ir
::ImplDatum
<I
>> {
100 unreachable
!("impl items should never be stubbed")
103 fn associated_ty_value(
105 _id
: crate::rust_ir
::AssociatedTyValueId
<I
>,
106 ) -> std
::sync
::Arc
<crate::rust_ir
::AssociatedTyValue
<I
>> {
107 unreachable
!("associated type values should never be stubbed")
112 id
: chalk_ir
::OpaqueTyId
<I
>,
113 ) -> std
::sync
::Arc
<crate::rust_ir
::OpaqueTyDatum
<I
>> {
114 let mut v
= (*self.db
.opaque_ty_data(id
)).clone();
115 v
.bound
= Binders
::new(
118 bounds
: Binders
::new(VariableKinds
::empty(self.db
.interner()), Vec
::new()),
119 where_clauses
: Binders
::new(VariableKinds
::empty(self.db
.interner()), Vec
::new()),
125 fn hidden_opaque_type(&self, _id
: chalk_ir
::OpaqueTyId
<I
>) -> chalk_ir
::Ty
<I
> {
126 // Return a unit since the particular hidden type doesn't matter (If it
127 // did matter, it would have been recorded)
128 chalk_ir
::TyData
::Apply(ApplicationTy
{
129 name
: TypeName
::Tuple(0),
130 substitution
: chalk_ir
::Substitution
::from_iter(
132 Vec
::<chalk_ir
::GenericArg
<_
>>::new(),
135 .intern(self.db
.interner())
140 _trait_id
: chalk_ir
::TraitId
<I
>,
141 _parameters
: &[chalk_ir
::GenericArg
<I
>],
142 _binders
: &CanonicalVarKinds
<I
>,
143 ) -> Vec
<chalk_ir
::ImplId
<I
>> {
144 // We panic here because the returned ids may not be collected,
145 // resulting in unresolvable names.
146 unimplemented
!("stub display code should call this")
149 fn local_impls_to_coherence_check(
151 trait_id
: chalk_ir
::TraitId
<I
>,
152 ) -> Vec
<chalk_ir
::ImplId
<I
>> {
153 self.db
.local_impls_to_coherence_check(trait_id
)
156 fn impl_provided_for(
158 _auto_trait_id
: chalk_ir
::TraitId
<I
>,
159 _adt_id
: chalk_ir
::AdtId
<I
>,
161 // We panic here because the returned ids may not be collected,
162 // resulting in unresolvable names.
163 unimplemented
!("stub display code should call this")
166 fn well_known_trait_id(
168 well_known_trait
: crate::rust_ir
::WellKnownTrait
,
169 ) -> Option
<chalk_ir
::TraitId
<I
>> {
170 self.db
.well_known_trait_id(well_known_trait
)
173 fn program_clauses_for_env(
175 environment
: &chalk_ir
::Environment
<I
>,
176 ) -> chalk_ir
::ProgramClauses
<I
> {
177 self.db
.program_clauses_for_env(environment
)
180 fn interner(&self) -> &I
{
184 fn is_object_safe(&self, trait_id
: chalk_ir
::TraitId
<I
>) -> bool
{
185 self.db
.is_object_safe(trait_id
)
190 _closure_id
: chalk_ir
::ClosureId
<I
>,
191 _substs
: &chalk_ir
::Substitution
<I
>,
192 ) -> crate::rust_ir
::ClosureKind
{
193 unimplemented
!("cannot stub closures")
196 fn closure_inputs_and_output(
198 _closure_id
: chalk_ir
::ClosureId
<I
>,
199 _substs
: &chalk_ir
::Substitution
<I
>,
200 ) -> chalk_ir
::Binders
<crate::rust_ir
::FnDefInputsAndOutputDatum
<I
>> {
201 unimplemented
!("cannot stub closures")
206 _closure_id
: chalk_ir
::ClosureId
<I
>,
207 _substs
: &chalk_ir
::Substitution
<I
>,
208 ) -> chalk_ir
::Binders
<chalk_ir
::Ty
<I
>> {
209 unimplemented
!("cannot stub closures")
212 fn closure_fn_substitution(
214 _closure_id
: chalk_ir
::ClosureId
<I
>,
215 _substs
: &chalk_ir
::Substitution
<I
>,
216 ) -> chalk_ir
::Substitution
<I
> {
217 unimplemented
!("cannot stub closures")
220 fn trait_name(&self, trait_id
: chalk_ir
::TraitId
<I
>) -> String
{
221 self.db
.trait_name(trait_id
)
224 fn adt_name(&self, struct_id
: chalk_ir
::AdtId
<I
>) -> String
{
225 self.db
.adt_name(struct_id
)
228 fn assoc_type_name(&self, assoc_ty_id
: chalk_ir
::AssocTypeId
<I
>) -> String
{
229 self.db
.assoc_type_name(assoc_ty_id
)
232 fn opaque_type_name(&self, opaque_ty_id
: chalk_ir
::OpaqueTyId
<I
>) -> String
{
233 self.db
.opaque_type_name(opaque_ty_id
)
236 fn fn_def_name(&self, fn_def_id
: chalk_ir
::FnDefId
<I
>) -> String
{
237 self.db
.fn_def_name(fn_def_id
)