]> git.proxmox.com Git - rustc.git/blob - vendor/chalk-solve-0.25.0/src/display/stub.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / vendor / chalk-solve-0.25.0 / src / display / stub.rs
1 //! Contains a `LoggingIrDatabase` which returns stub versions of everything
2 //! queried.
3 use std::sync::Arc;
4
5 use crate::{
6 rust_ir::{
7 AdtDatumBound, AdtKind, AdtVariantDatum, AssociatedTyDatumBound, FnDefDatumBound,
8 OpaqueTyDatumBound, TraitDatumBound,
9 },
10 RustIrDatabase,
11 };
12 use chalk_ir::{
13 interner::Interner, ApplicationTy, Binders, CanonicalVarKinds, TypeName, VariableKinds,
14 };
15
16 #[derive(Debug)]
17 pub struct StubWrapper<'a, DB> {
18 db: &'a DB,
19 }
20
21 impl<'a, DB> StubWrapper<'a, DB> {
22 pub fn new(db: &'a DB) -> Self {
23 StubWrapper { db }
24 }
25 }
26
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()
30 }
31
32 fn associated_ty_data(
33 &self,
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(),
41 bounds: Vec::new(),
42 },
43 );
44 Arc::new(v)
45 }
46
47 fn trait_datum(
48 &self,
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(),
54 TraitDatumBound {
55 where_clauses: Vec::new(),
56 },
57 );
58 Arc::new(v)
59 }
60
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![],
66 };
67 v.binders = Binders::new(
68 v.binders.binders.clone(),
69 AdtDatumBound {
70 variants,
71 where_clauses: Vec::new(),
72 },
73 );
74 Arc::new(v)
75 }
76
77 fn adt_repr(&self, id: chalk_ir::AdtId<I>) -> crate::rust_ir::AdtRepr {
78 self.db.adt_repr(id)
79 }
80
81 fn fn_def_datum(
82 &self,
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(),
88 FnDefDatumBound {
89 inputs_and_output: v.binders.skip_binders().inputs_and_output.clone(),
90 where_clauses: Vec::new(),
91 },
92 );
93 Arc::new(v)
94 }
95
96 fn impl_datum(
97 &self,
98 _impl_id: chalk_ir::ImplId<I>,
99 ) -> std::sync::Arc<crate::rust_ir::ImplDatum<I>> {
100 unreachable!("impl items should never be stubbed")
101 }
102
103 fn associated_ty_value(
104 &self,
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")
108 }
109
110 fn opaque_ty_data(
111 &self,
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(
116 v.bound.binders,
117 OpaqueTyDatumBound {
118 bounds: Binders::new(VariableKinds::empty(self.db.interner()), Vec::new()),
119 where_clauses: Binders::new(VariableKinds::empty(self.db.interner()), Vec::new()),
120 },
121 );
122 Arc::new(v)
123 }
124
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(
131 self.db.interner(),
132 Vec::<chalk_ir::GenericArg<_>>::new(),
133 ),
134 })
135 .intern(self.db.interner())
136 }
137
138 fn impls_for_trait(
139 &self,
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")
147 }
148
149 fn local_impls_to_coherence_check(
150 &self,
151 trait_id: chalk_ir::TraitId<I>,
152 ) -> Vec<chalk_ir::ImplId<I>> {
153 self.db.local_impls_to_coherence_check(trait_id)
154 }
155
156 fn impl_provided_for(
157 &self,
158 _auto_trait_id: chalk_ir::TraitId<I>,
159 _adt_id: chalk_ir::AdtId<I>,
160 ) -> bool {
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")
164 }
165
166 fn well_known_trait_id(
167 &self,
168 well_known_trait: crate::rust_ir::WellKnownTrait,
169 ) -> Option<chalk_ir::TraitId<I>> {
170 self.db.well_known_trait_id(well_known_trait)
171 }
172
173 fn program_clauses_for_env(
174 &self,
175 environment: &chalk_ir::Environment<I>,
176 ) -> chalk_ir::ProgramClauses<I> {
177 self.db.program_clauses_for_env(environment)
178 }
179
180 fn interner(&self) -> &I {
181 self.db.interner()
182 }
183
184 fn is_object_safe(&self, trait_id: chalk_ir::TraitId<I>) -> bool {
185 self.db.is_object_safe(trait_id)
186 }
187
188 fn closure_kind(
189 &self,
190 _closure_id: chalk_ir::ClosureId<I>,
191 _substs: &chalk_ir::Substitution<I>,
192 ) -> crate::rust_ir::ClosureKind {
193 unimplemented!("cannot stub closures")
194 }
195
196 fn closure_inputs_and_output(
197 &self,
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")
202 }
203
204 fn closure_upvars(
205 &self,
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")
210 }
211
212 fn closure_fn_substitution(
213 &self,
214 _closure_id: chalk_ir::ClosureId<I>,
215 _substs: &chalk_ir::Substitution<I>,
216 ) -> chalk_ir::Substitution<I> {
217 unimplemented!("cannot stub closures")
218 }
219
220 fn trait_name(&self, trait_id: chalk_ir::TraitId<I>) -> String {
221 self.db.trait_name(trait_id)
222 }
223
224 fn adt_name(&self, struct_id: chalk_ir::AdtId<I>) -> String {
225 self.db.adt_name(struct_id)
226 }
227
228 fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<I>) -> String {
229 self.db.assoc_type_name(assoc_ty_id)
230 }
231
232 fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<I>) -> String {
233 self.db.opaque_type_name(opaque_ty_id)
234 }
235
236 fn fn_def_name(&self, fn_def_id: chalk_ir::FnDefId<I>) -> String {
237 self.db.fn_def_name(fn_def_id)
238 }
239 }