]> git.proxmox.com Git - rustc.git/blame - vendor/chalk-solve/src/display/stub.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / vendor / chalk-solve / src / display / stub.rs
CommitLineData
3dfed10e
XL
1//! Contains a `LoggingIrDatabase` which returns stub versions of everything
2//! queried.
3use std::sync::Arc;
4
29967ef6 5use crate::rust_ir::{GeneratorDatum, GeneratorWitnessDatum};
3dfed10e
XL
6use crate::{
7 rust_ir::{
8 AdtDatumBound, AdtKind, AdtVariantDatum, AssociatedTyDatumBound, FnDefDatumBound,
9 OpaqueTyDatumBound, TraitDatumBound,
10 },
11 RustIrDatabase,
12};
13use chalk_ir::{
5869c6ff
XL
14 interner::Interner, Binders, CanonicalVarKinds, GeneratorId, Substitution, Ty,
15 UnificationDatabase, VariableKinds, Variances,
3dfed10e
XL
16};
17
18#[derive(Debug)]
19pub struct StubWrapper<'a, DB> {
20 db: &'a DB,
21}
22
23impl<'a, DB> StubWrapper<'a, DB> {
24 pub fn new(db: &'a DB) -> Self {
25 StubWrapper { db }
26 }
27}
28
5869c6ff
XL
29impl<I: Interner, DB: RustIrDatabase<I>> UnificationDatabase<I> for StubWrapper<'_, DB> {
30 fn fn_def_variance(&self, fn_def_id: chalk_ir::FnDefId<I>) -> Variances<I> {
31 self.db.unification_database().fn_def_variance(fn_def_id)
32 }
33
34 fn adt_variance(&self, adt_id: chalk_ir::AdtId<I>) -> Variances<I> {
35 self.db.unification_database().adt_variance(adt_id)
36 }
37}
38
3dfed10e
XL
39impl<I: Interner, DB: RustIrDatabase<I>> RustIrDatabase<I> for StubWrapper<'_, DB> {
40 fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<I>> {
41 self.db.custom_clauses()
42 }
43
44 fn associated_ty_data(
45 &self,
46 ty: chalk_ir::AssocTypeId<I>,
47 ) -> std::sync::Arc<crate::rust_ir::AssociatedTyDatum<I>> {
48 let mut v = (*self.db.associated_ty_data(ty)).clone();
49 v.binders = Binders::new(
50 v.binders.binders.clone(),
51 AssociatedTyDatumBound {
52 where_clauses: Vec::new(),
53 bounds: Vec::new(),
54 },
55 );
56 Arc::new(v)
57 }
58
59 fn trait_datum(
60 &self,
61 trait_id: chalk_ir::TraitId<I>,
62 ) -> std::sync::Arc<crate::rust_ir::TraitDatum<I>> {
63 let mut v = (*self.db.trait_datum(trait_id)).clone();
64 v.binders = Binders::new(
65 v.binders.binders.clone(),
66 TraitDatumBound {
67 where_clauses: Vec::new(),
68 },
69 );
70 Arc::new(v)
71 }
72
73 fn adt_datum(&self, adt_id: chalk_ir::AdtId<I>) -> std::sync::Arc<crate::rust_ir::AdtDatum<I>> {
74 let mut v = (*self.db.adt_datum(adt_id)).clone();
75 let variants = match v.kind {
76 AdtKind::Struct | AdtKind::Union => vec![AdtVariantDatum { fields: vec![] }],
77 AdtKind::Enum => vec![],
78 };
79 v.binders = Binders::new(
80 v.binders.binders.clone(),
81 AdtDatumBound {
82 variants,
83 where_clauses: Vec::new(),
84 },
85 );
86 Arc::new(v)
87 }
88
5869c6ff 89 fn adt_repr(&self, id: chalk_ir::AdtId<I>) -> std::sync::Arc<crate::rust_ir::AdtRepr<I>> {
3dfed10e
XL
90 self.db.adt_repr(id)
91 }
92
93 fn fn_def_datum(
94 &self,
95 fn_def_id: chalk_ir::FnDefId<I>,
96 ) -> std::sync::Arc<crate::rust_ir::FnDefDatum<I>> {
97 let mut v = (*self.db.fn_def_datum(fn_def_id)).clone();
98 v.binders = Binders::new(
99 v.binders.binders.clone(),
100 FnDefDatumBound {
101 inputs_and_output: v.binders.skip_binders().inputs_and_output.clone(),
102 where_clauses: Vec::new(),
103 },
104 );
105 Arc::new(v)
106 }
107
108 fn impl_datum(
109 &self,
110 _impl_id: chalk_ir::ImplId<I>,
111 ) -> std::sync::Arc<crate::rust_ir::ImplDatum<I>> {
112 unreachable!("impl items should never be stubbed")
113 }
114
115 fn associated_ty_value(
116 &self,
117 _id: crate::rust_ir::AssociatedTyValueId<I>,
118 ) -> std::sync::Arc<crate::rust_ir::AssociatedTyValue<I>> {
119 unreachable!("associated type values should never be stubbed")
120 }
121
122 fn opaque_ty_data(
123 &self,
124 id: chalk_ir::OpaqueTyId<I>,
125 ) -> std::sync::Arc<crate::rust_ir::OpaqueTyDatum<I>> {
126 let mut v = (*self.db.opaque_ty_data(id)).clone();
127 v.bound = Binders::new(
128 v.bound.binders,
129 OpaqueTyDatumBound {
130 bounds: Binders::new(VariableKinds::empty(self.db.interner()), Vec::new()),
131 where_clauses: Binders::new(VariableKinds::empty(self.db.interner()), Vec::new()),
132 },
133 );
134 Arc::new(v)
135 }
136
137 fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<I>) -> chalk_ir::Ty<I> {
138 // Return a unit since the particular hidden type doesn't matter (If it
139 // did matter, it would have been recorded)
29967ef6
XL
140 chalk_ir::TyKind::Tuple(0, Substitution::empty(self.db.interner()))
141 .intern(self.db.interner())
3dfed10e
XL
142 }
143
144 fn impls_for_trait(
145 &self,
146 _trait_id: chalk_ir::TraitId<I>,
147 _parameters: &[chalk_ir::GenericArg<I>],
148 _binders: &CanonicalVarKinds<I>,
149 ) -> Vec<chalk_ir::ImplId<I>> {
150 // We panic here because the returned ids may not be collected,
151 // resulting in unresolvable names.
152 unimplemented!("stub display code should call this")
153 }
154
155 fn local_impls_to_coherence_check(
156 &self,
157 trait_id: chalk_ir::TraitId<I>,
158 ) -> Vec<chalk_ir::ImplId<I>> {
159 self.db.local_impls_to_coherence_check(trait_id)
160 }
161
162 fn impl_provided_for(
163 &self,
164 _auto_trait_id: chalk_ir::TraitId<I>,
29967ef6 165 _ty: &chalk_ir::TyKind<I>,
3dfed10e
XL
166 ) -> bool {
167 // We panic here because the returned ids may not be collected,
168 // resulting in unresolvable names.
169 unimplemented!("stub display code should call this")
170 }
171
172 fn well_known_trait_id(
173 &self,
174 well_known_trait: crate::rust_ir::WellKnownTrait,
175 ) -> Option<chalk_ir::TraitId<I>> {
176 self.db.well_known_trait_id(well_known_trait)
177 }
178
179 fn program_clauses_for_env(
180 &self,
181 environment: &chalk_ir::Environment<I>,
182 ) -> chalk_ir::ProgramClauses<I> {
183 self.db.program_clauses_for_env(environment)
184 }
185
a2a8927a 186 fn interner(&self) -> I {
3dfed10e
XL
187 self.db.interner()
188 }
189
190 fn is_object_safe(&self, trait_id: chalk_ir::TraitId<I>) -> bool {
191 self.db.is_object_safe(trait_id)
192 }
193
194 fn closure_kind(
195 &self,
196 _closure_id: chalk_ir::ClosureId<I>,
197 _substs: &chalk_ir::Substitution<I>,
198 ) -> crate::rust_ir::ClosureKind {
199 unimplemented!("cannot stub closures")
200 }
201
202 fn closure_inputs_and_output(
203 &self,
204 _closure_id: chalk_ir::ClosureId<I>,
205 _substs: &chalk_ir::Substitution<I>,
206 ) -> chalk_ir::Binders<crate::rust_ir::FnDefInputsAndOutputDatum<I>> {
207 unimplemented!("cannot stub closures")
208 }
209
210 fn closure_upvars(
211 &self,
212 _closure_id: chalk_ir::ClosureId<I>,
213 _substs: &chalk_ir::Substitution<I>,
214 ) -> chalk_ir::Binders<chalk_ir::Ty<I>> {
215 unimplemented!("cannot stub closures")
216 }
217
29967ef6
XL
218 fn generator_datum(&self, _generator_id: GeneratorId<I>) -> Arc<GeneratorDatum<I>> {
219 unimplemented!("cannot stub generator")
220 }
221
222 fn generator_witness_datum(
223 &self,
224 _generator_id: GeneratorId<I>,
225 ) -> Arc<GeneratorWitnessDatum<I>> {
226 unimplemented!("cannot stub generator witness")
227 }
228
3dfed10e
XL
229 fn closure_fn_substitution(
230 &self,
231 _closure_id: chalk_ir::ClosureId<I>,
232 _substs: &chalk_ir::Substitution<I>,
233 ) -> chalk_ir::Substitution<I> {
234 unimplemented!("cannot stub closures")
235 }
236
5869c6ff
XL
237 fn unification_database(&self) -> &dyn UnificationDatabase<I> {
238 self
239 }
240
3dfed10e
XL
241 fn trait_name(&self, trait_id: chalk_ir::TraitId<I>) -> String {
242 self.db.trait_name(trait_id)
243 }
244
245 fn adt_name(&self, struct_id: chalk_ir::AdtId<I>) -> String {
246 self.db.adt_name(struct_id)
247 }
248
249 fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<I>) -> String {
250 self.db.assoc_type_name(assoc_ty_id)
251 }
252
253 fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<I>) -> String {
254 self.db.opaque_type_name(opaque_ty_id)
255 }
256
257 fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId<I>) -> String {
258 self.db.fn_def_name(fn_def_id)
259 }
5869c6ff
XL
260
261 fn discriminant_type(&self, ty: Ty<I>) -> Ty<I> {
262 self.db.discriminant_type(ty)
263 }
3dfed10e 264}