1 //! Contains the logic to lower rustc types into Chalk types
3 //! In many cases there is a 1:1 relationship between a rustc type and a Chalk type.
4 //! For example, a `SubstsRef` maps almost directly to a `Substitution`. In some
5 //! other cases, such as `Param`s, there is no Chalk type, so we have to handle
9 //! Much of the `Ty` lowering is 1:1 with Chalk. (Or will be eventually). A
10 //! helpful table for what types lower to what can be found in the
11 //! [Chalk book](https://rust-lang.github.io/chalk/book/types/rust_types.html).
12 //! The most notable difference lies with `Param`s. To convert from rustc to
13 //! Chalk, we eagerly and deeply convert `Param`s to placeholders (in goals) or
14 //! bound variables (for clause generation through functions in `db`).
16 //! ## `Region` lowering
17 //! Regions are handled in rustc and Chalk is quite differently. In rustc, there
18 //! is a difference between "early bound" and "late bound" regions, where only
19 //! the late bound regions have a `DebruijnIndex`. Moreover, in Chalk all
20 //! regions (Lifetimes) have an associated index. In rustc, only `BrAnon`s have
21 //! an index, whereas `BrNamed` don't. In order to lower regions to Chalk, we
22 //! convert all regions into `BrAnon` late-bound regions.
24 //! ## `Const` lowering
25 //! Chalk doesn't handle consts currently, so consts are currently lowered to
28 //! ## Bound variable collection
29 //! Another difference between rustc and Chalk lies in the handling of binders.
30 //! Chalk requires that we store the bound parameter kinds, whereas rustc does
31 //! not. To lower anything wrapped in a `Binder`, we first deeply find any bound
32 //! variables from the current `Binder`.
35 use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
36 use rustc_middle::ty::fold::TypeFolder;
37 use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
38 use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeVisitor};
39 use rustc_span::def_id::DefId;
41 use chalk_ir::{FnSig, ForeignDefId};
42 use rustc_hir::Unsafety;
43 use std::collections::btree_map::{BTreeMap, Entry};
44 use std::ops::ControlFlow;
46 /// Essentially an `Into` with a `&RustInterner` parameter
47 crate trait LowerInto<'tcx, T> {
48 /// Lower a rustc construct (e.g., `ty::TraitPredicate`) to a chalk type, consuming `self`.
49 fn lower_into(self, interner: RustInterner<'tcx>) -> T;
52 impl<'tcx> LowerInto<'tcx, chalk_ir::Substitution<RustInterner<'tcx>>> for SubstsRef<'tcx> {
55 interner: RustInterner<'tcx>,
56 ) -> chalk_ir::Substitution<RustInterner<'tcx>> {
57 chalk_ir::Substitution::from_iter(interner, self.iter().map(|s| s.lower_into(interner)))
61 impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution<RustInterner<'tcx>> {
62 fn lower_into(self, interner: RustInterner<'tcx>) -> SubstsRef<'tcx> {
63 interner.tcx.mk_substs(self.iter(interner).map(|subst| subst.lower_into(interner)))
67 impl<'tcx> LowerInto<'tcx, chalk_ir::AliasTy<RustInterner<'tcx>>> for ty::ProjectionTy<'tcx> {
68 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasTy<RustInterner<'tcx>> {
69 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
70 associated_ty_id: chalk_ir::AssocTypeId(self.item_def_id),
71 substitution: self.substs.lower_into(interner),
76 impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>>>
77 for ChalkEnvironmentAndGoal<'tcx>
81 interner: RustInterner<'tcx>,
82 ) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
83 let clauses = self.environment.into_iter().map(|predicate| {
84 let (predicate, binders, _named_regions) =
85 collect_bound_vars(interner, interner.tcx, predicate.kind());
86 let consequence = match predicate {
87 ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
88 chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
90 ty::PredicateKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
91 chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
93 ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
94 chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
95 a: predicate.0.lower_into(interner),
96 b: predicate.1.lower_into(interner),
99 ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
100 chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
101 ty: predicate.0.lower_into(interner),
102 lifetime: predicate.1.lower_into(interner),
105 ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
106 chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
108 ty::PredicateKind::WellFormed(..)
109 | ty::PredicateKind::ObjectSafe(..)
110 | ty::PredicateKind::ClosureKind(..)
111 | ty::PredicateKind::Subtype(..)
112 | ty::PredicateKind::Coerce(..)
113 | ty::PredicateKind::ConstEvaluatable(..)
114 | ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
116 let value = chalk_ir::ProgramClauseImplication {
118 conditions: chalk_ir::Goals::empty(interner),
119 priority: chalk_ir::ClausePriority::High,
120 constraints: chalk_ir::Constraints::empty(interner),
122 chalk_ir::ProgramClauseData(chalk_ir::Binders::new(binders, value)).intern(interner)
125 let goal: chalk_ir::GoalData<RustInterner<'tcx>> = self.goal.lower_into(interner);
126 chalk_ir::InEnvironment {
127 environment: chalk_ir::Environment {
128 clauses: chalk_ir::ProgramClauses::from_iter(interner, clauses),
130 goal: goal.intern(interner),
135 impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
136 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
137 let (predicate, binders, _named_regions) =
138 collect_bound_vars(interner, interner.tcx, self.kind());
140 let value = match predicate {
141 ty::PredicateKind::Trait(predicate) => {
142 chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
143 chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
146 ty::PredicateKind::RegionOutlives(predicate) => {
147 chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
148 chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
149 a: predicate.0.lower_into(interner),
150 b: predicate.1.lower_into(interner),
154 ty::PredicateKind::TypeOutlives(predicate) => {
155 chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
156 chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
157 ty: predicate.0.lower_into(interner),
158 lifetime: predicate.1.lower_into(interner),
162 ty::PredicateKind::Projection(predicate) => {
163 chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
164 chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
167 ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
168 GenericArgKind::Type(ty) => match ty.kind() {
169 // FIXME(chalk): In Chalk, a placeholder is WellFormed if it
170 // `FromEnv`. However, when we "lower" Params, we don't update
172 ty::Placeholder(..) => {
173 chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
176 _ => chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
177 chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
180 // FIXME(chalk): handle well formed consts
181 GenericArgKind::Const(..) => {
182 chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
184 GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
187 ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
188 chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(t)),
191 ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
192 chalk_ir::GoalData::SubtypeGoal(chalk_ir::SubtypeGoal {
193 a: a.lower_into(interner),
194 b: b.lower_into(interner),
198 // FIXME(chalk): other predicates
200 // We can defer this, but ultimately we'll want to express
201 // some of these in terms of chalk operations.
202 ty::PredicateKind::ClosureKind(..)
203 | ty::PredicateKind::Coerce(..)
204 | ty::PredicateKind::ConstEvaluatable(..)
205 | ty::PredicateKind::ConstEquate(..) => {
206 chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
208 ty::PredicateKind::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal(
209 chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))),
213 chalk_ir::GoalData::Quantified(
214 chalk_ir::QuantifierKind::ForAll,
215 chalk_ir::Binders::new(binders, value.intern(interner)),
220 impl<'tcx> LowerInto<'tcx, chalk_ir::TraitRef<RustInterner<'tcx>>>
221 for rustc_middle::ty::TraitRef<'tcx>
223 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::TraitRef<RustInterner<'tcx>> {
225 trait_id: chalk_ir::TraitId(self.def_id),
226 substitution: self.substs.lower_into(interner),
231 impl<'tcx> LowerInto<'tcx, chalk_ir::AliasEq<RustInterner<'tcx>>>
232 for rustc_middle::ty::ProjectionPredicate<'tcx>
234 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasEq<RustInterner<'tcx>> {
235 // FIXME(associated_const_equality): teach chalk about terms for alias eq.
237 ty: self.term.ty().unwrap().lower_into(interner),
238 alias: self.projection_ty.lower_into(interner),
244 // FIXME(...): Where do I add this to Chalk? I can't find it in the rustc repo anywhere.
245 impl<'tcx> LowerInto<'tcx, chalk_ir::Term<RustInterner<'tcx>>> for rustc_middle::ty::Term<'tcx> {
246 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Term<RustInterner<'tcx>> {
248 ty::Term::Ty(ty) => ty.lower_into(interner).into(),
249 ty::Term::Const(c) => c.lower_into(interner).into(),
255 impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
256 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Ty<RustInterner<'tcx>> {
257 let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i));
258 let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i));
259 let float = |f| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Float(f));
262 ty::Bool => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Bool),
263 ty::Char => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Char),
264 ty::Int(ty) => match ty {
265 ty::IntTy::Isize => int(chalk_ir::IntTy::Isize),
266 ty::IntTy::I8 => int(chalk_ir::IntTy::I8),
267 ty::IntTy::I16 => int(chalk_ir::IntTy::I16),
268 ty::IntTy::I32 => int(chalk_ir::IntTy::I32),
269 ty::IntTy::I64 => int(chalk_ir::IntTy::I64),
270 ty::IntTy::I128 => int(chalk_ir::IntTy::I128),
272 ty::Uint(ty) => match ty {
273 ty::UintTy::Usize => uint(chalk_ir::UintTy::Usize),
274 ty::UintTy::U8 => uint(chalk_ir::UintTy::U8),
275 ty::UintTy::U16 => uint(chalk_ir::UintTy::U16),
276 ty::UintTy::U32 => uint(chalk_ir::UintTy::U32),
277 ty::UintTy::U64 => uint(chalk_ir::UintTy::U64),
278 ty::UintTy::U128 => uint(chalk_ir::UintTy::U128),
280 ty::Float(ty) => match ty {
281 ty::FloatTy::F32 => float(chalk_ir::FloatTy::F32),
282 ty::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
284 ty::Adt(def, substs) => {
285 chalk_ir::TyKind::Adt(chalk_ir::AdtId(def), substs.lower_into(interner))
287 ty::Foreign(def_id) => chalk_ir::TyKind::Foreign(ForeignDefId(def_id)),
288 ty::Str => chalk_ir::TyKind::Str,
289 ty::Array(ty, len) => {
290 chalk_ir::TyKind::Array(ty.lower_into(interner), len.lower_into(interner))
292 ty::Slice(ty) => chalk_ir::TyKind::Slice(ty.lower_into(interner)),
295 chalk_ir::TyKind::Raw(ptr.mutbl.lower_into(interner), ptr.ty.lower_into(interner))
297 ty::Ref(region, ty, mutability) => chalk_ir::TyKind::Ref(
298 mutability.lower_into(interner),
299 region.lower_into(interner),
300 ty.lower_into(interner),
302 ty::FnDef(def_id, substs) => {
303 chalk_ir::TyKind::FnDef(chalk_ir::FnDefId(def_id), substs.lower_into(interner))
306 let (inputs_and_outputs, binders, _named_regions) =
307 collect_bound_vars(interner, interner.tcx, sig.inputs_and_output());
308 chalk_ir::TyKind::Function(chalk_ir::FnPointer {
309 num_binders: binders.len(interner),
310 sig: sig.lower_into(interner),
311 substitution: chalk_ir::FnSubst(chalk_ir::Substitution::from_iter(
313 inputs_and_outputs.iter().map(|ty| {
314 chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
319 ty::Dynamic(predicates, region) => chalk_ir::TyKind::Dyn(chalk_ir::DynTy {
320 bounds: predicates.lower_into(interner),
321 lifetime: region.lower_into(interner),
323 ty::Closure(def_id, substs) => {
324 chalk_ir::TyKind::Closure(chalk_ir::ClosureId(def_id), substs.lower_into(interner))
326 ty::Generator(def_id, substs, _) => chalk_ir::TyKind::Generator(
327 chalk_ir::GeneratorId(def_id),
328 substs.lower_into(interner),
330 ty::GeneratorWitness(_) => unimplemented!(),
331 ty::Never => chalk_ir::TyKind::Never,
332 ty::Tuple(types) => {
333 chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner))
335 ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)),
336 ty::Opaque(def_id, substs) => {
337 chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
338 opaque_ty_id: chalk_ir::OpaqueTyId(def_id),
339 substitution: substs.lower_into(interner),
342 // This should have been done eagerly prior to this, and all Params
343 // should have been substituted to placeholders
344 ty::Param(_) => panic!("Lowering Param when not expected."),
345 ty::Bound(db, bound) => chalk_ir::TyKind::BoundVar(chalk_ir::BoundVar::new(
346 chalk_ir::DebruijnIndex::new(db.as_u32()),
349 ty::Placeholder(_placeholder) => {
350 chalk_ir::TyKind::Placeholder(chalk_ir::PlaceholderIndex {
351 ui: chalk_ir::UniverseIndex { counter: _placeholder.universe.as_usize() },
352 idx: _placeholder.name.as_usize(),
355 ty::Infer(_infer) => unimplemented!(),
356 ty::Error(_) => chalk_ir::TyKind::Error,
362 impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
363 fn lower_into(self, interner: RustInterner<'tcx>) -> Ty<'tcx> {
364 use chalk_ir::TyKind;
366 let kind = match self.kind(interner) {
367 TyKind::Adt(struct_id, substitution) => {
368 ty::Adt(struct_id.0, substitution.lower_into(interner))
370 TyKind::Scalar(scalar) => match scalar {
371 chalk_ir::Scalar::Bool => ty::Bool,
372 chalk_ir::Scalar::Char => ty::Char,
373 chalk_ir::Scalar::Int(int_ty) => match int_ty {
374 chalk_ir::IntTy::Isize => ty::Int(ty::IntTy::Isize),
375 chalk_ir::IntTy::I8 => ty::Int(ty::IntTy::I8),
376 chalk_ir::IntTy::I16 => ty::Int(ty::IntTy::I16),
377 chalk_ir::IntTy::I32 => ty::Int(ty::IntTy::I32),
378 chalk_ir::IntTy::I64 => ty::Int(ty::IntTy::I64),
379 chalk_ir::IntTy::I128 => ty::Int(ty::IntTy::I128),
381 chalk_ir::Scalar::Uint(int_ty) => match int_ty {
382 chalk_ir::UintTy::Usize => ty::Uint(ty::UintTy::Usize),
383 chalk_ir::UintTy::U8 => ty::Uint(ty::UintTy::U8),
384 chalk_ir::UintTy::U16 => ty::Uint(ty::UintTy::U16),
385 chalk_ir::UintTy::U32 => ty::Uint(ty::UintTy::U32),
386 chalk_ir::UintTy::U64 => ty::Uint(ty::UintTy::U64),
387 chalk_ir::UintTy::U128 => ty::Uint(ty::UintTy::U128),
389 chalk_ir::Scalar::Float(float_ty) => match float_ty {
390 chalk_ir::FloatTy::F32 => ty::Float(ty::FloatTy::F32),
391 chalk_ir::FloatTy::F64 => ty::Float(ty::FloatTy::F64),
394 TyKind::Array(ty, c) => {
395 let ty = ty.lower_into(interner);
396 let c = c.lower_into(interner);
399 TyKind::FnDef(id, substitution) => ty::FnDef(id.0, substitution.lower_into(interner)),
400 TyKind::Closure(closure, substitution) => {
401 ty::Closure(closure.0, substitution.lower_into(interner))
403 TyKind::Generator(..) => unimplemented!(),
404 TyKind::GeneratorWitness(..) => unimplemented!(),
405 TyKind::Never => ty::Never,
406 TyKind::Tuple(_len, substitution) => {
407 ty::Tuple(substitution.lower_into(interner).try_as_type_list().unwrap())
409 TyKind::Slice(ty) => ty::Slice(ty.lower_into(interner)),
410 TyKind::Raw(mutbl, ty) => ty::RawPtr(ty::TypeAndMut {
411 ty: ty.lower_into(interner),
412 mutbl: mutbl.lower_into(interner),
414 TyKind::Ref(mutbl, lifetime, ty) => ty::Ref(
415 lifetime.lower_into(interner),
416 ty.lower_into(interner),
417 mutbl.lower_into(interner),
419 TyKind::Str => ty::Str,
420 TyKind::OpaqueType(opaque_ty, substitution) => {
421 ty::Opaque(opaque_ty.0, substitution.lower_into(interner))
423 TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::ProjectionTy {
424 substs: substitution.lower_into(interner),
425 item_def_id: assoc_ty.0,
427 TyKind::Foreign(def_id) => ty::Foreign(def_id.0),
428 TyKind::Error => return interner.tcx.ty_error(),
429 TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
430 universe: ty::UniverseIndex::from_usize(placeholder.ui.counter),
431 name: ty::BoundVar::from_usize(placeholder.idx),
433 TyKind::Alias(alias_ty) => match alias_ty {
434 chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy {
435 item_def_id: projection.associated_ty_id.0,
436 substs: projection.substitution.lower_into(interner),
438 chalk_ir::AliasTy::Opaque(opaque) => {
439 ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner))
442 TyKind::Function(_quantified_ty) => unimplemented!(),
443 TyKind::BoundVar(_bound) => ty::Bound(
444 ty::DebruijnIndex::from_usize(_bound.debruijn.depth() as usize),
446 var: ty::BoundVar::from_usize(_bound.index),
447 kind: ty::BoundTyKind::Anon,
450 TyKind::InferenceVar(_, _) => unimplemented!(),
451 TyKind::Dyn(_) => unimplemented!(),
453 interner.tcx.mk_ty(kind)
457 impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'tcx> {
458 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
460 ty::ReEarlyBound(_) => {
461 panic!("Should have already been substituted.");
463 ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
464 chalk_ir::DebruijnIndex::new(db.as_u32()),
468 ty::ReFree(_) => unimplemented!(),
469 ty::ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
470 ty::ReVar(_) => unimplemented!(),
471 ty::RePlaceholder(placeholder_region) => {
472 chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
473 ui: chalk_ir::UniverseIndex { counter: placeholder_region.universe.index() },
479 chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() })
482 ty::ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
487 impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> {
488 fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
489 let kind = match self.data(interner) {
490 chalk_ir::LifetimeData::BoundVar(var) => ty::ReLateBound(
491 ty::DebruijnIndex::from_u32(var.debruijn.depth()),
493 var: ty::BoundVar::from_usize(var.index),
494 kind: ty::BrAnon(var.index as u32),
497 chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
498 chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
499 universe: ty::UniverseIndex::from_usize(p.ui.counter),
500 name: ty::BoundRegionKind::BrAnon(p.idx as u32),
502 chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
503 chalk_ir::LifetimeData::Empty(ui) => {
504 ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
506 chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased,
507 chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
509 interner.tcx.mk_region(kind)
513 impl<'tcx> LowerInto<'tcx, chalk_ir::Const<RustInterner<'tcx>>> for ty::Const<'tcx> {
514 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const<RustInterner<'tcx>> {
515 let ty = self.ty().lower_into(interner);
516 let value = match self.val() {
517 ty::ConstKind::Value(val) => {
518 chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val })
520 ty::ConstKind::Bound(db, bound) => chalk_ir::ConstValue::BoundVar(
521 chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::new(db.as_u32()), bound.index()),
523 _ => unimplemented!("Const not implemented. {:?}", self),
525 chalk_ir::ConstData { ty, value }.intern(interner)
529 impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'tcx>> {
530 fn lower_into(self, interner: RustInterner<'tcx>) -> ty::Const<'tcx> {
531 let data = self.data(interner);
532 let ty = data.ty.lower_into(interner);
533 let val = match data.value {
534 chalk_ir::ConstValue::BoundVar(var) => ty::ConstKind::Bound(
535 ty::DebruijnIndex::from_u32(var.debruijn.depth()),
536 ty::BoundVar::from_u32(var.index as u32),
538 chalk_ir::ConstValue::InferenceVar(_var) => unimplemented!(),
539 chalk_ir::ConstValue::Placeholder(_p) => unimplemented!(),
540 chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned),
542 interner.tcx.mk_const(ty::ConstS { ty, val })
546 impl<'tcx> LowerInto<'tcx, chalk_ir::GenericArg<RustInterner<'tcx>>> for GenericArg<'tcx> {
547 fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::GenericArg<RustInterner<'tcx>> {
548 match self.unpack() {
549 ty::subst::GenericArgKind::Type(ty) => {
550 chalk_ir::GenericArgData::Ty(ty.lower_into(interner))
552 ty::subst::GenericArgKind::Lifetime(lifetime) => {
553 chalk_ir::GenericArgData::Lifetime(lifetime.lower_into(interner))
555 ty::subst::GenericArgKind::Const(c) => {
556 chalk_ir::GenericArgData::Const(c.lower_into(interner))
563 impl<'tcx> LowerInto<'tcx, ty::subst::GenericArg<'tcx>>
564 for &chalk_ir::GenericArg<RustInterner<'tcx>>
566 fn lower_into(self, interner: RustInterner<'tcx>) -> ty::subst::GenericArg<'tcx> {
567 match self.data(interner) {
568 chalk_ir::GenericArgData::Ty(ty) => {
569 let t: Ty<'tcx> = ty.lower_into(interner);
572 chalk_ir::GenericArgData::Lifetime(lifetime) => {
573 let r: Region<'tcx> = lifetime.lower_into(interner);
576 chalk_ir::GenericArgData::Const(c) => {
577 let c: ty::Const<'tcx> = c.lower_into(interner);
584 // We lower into an Option here since there are some predicates which Chalk
585 // doesn't have a representation for yet (as a `WhereClause`), but are so common
586 // that we just are accepting the unsoundness for now. The `Option` will
587 // eventually be removed.
588 impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>
589 for ty::Predicate<'tcx>
593 interner: RustInterner<'tcx>,
594 ) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
595 let (predicate, binders, _named_regions) =
596 collect_bound_vars(interner, interner.tcx, self.kind());
597 let value = match predicate {
598 ty::PredicateKind::Trait(predicate) => {
599 Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
601 ty::PredicateKind::RegionOutlives(predicate) => {
602 Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
603 a: predicate.0.lower_into(interner),
604 b: predicate.1.lower_into(interner),
607 ty::PredicateKind::TypeOutlives(predicate) => {
608 Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
609 ty: predicate.0.lower_into(interner),
610 lifetime: predicate.1.lower_into(interner),
613 ty::PredicateKind::Projection(predicate) => {
614 Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
616 ty::PredicateKind::WellFormed(_ty) => None,
618 ty::PredicateKind::ObjectSafe(..)
619 | ty::PredicateKind::ClosureKind(..)
620 | ty::PredicateKind::Subtype(..)
621 | ty::PredicateKind::Coerce(..)
622 | ty::PredicateKind::ConstEvaluatable(..)
623 | ty::PredicateKind::ConstEquate(..)
624 | ty::PredicateKind::TypeWellFormedFromEnv(..) => {
625 bug!("unexpected predicate {}", &self)
628 value.map(|value| chalk_ir::Binders::new(binders, value))
632 impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>>>
633 for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
637 interner: RustInterner<'tcx>,
638 ) -> chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>> {
639 // `Self` has one binder:
640 // Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>
641 // The return type has two:
642 // Binders<&[Binders<WhereClause<I>>]>
643 // This means that any variables that are escaping `self` need to be
644 // shifted in by one so that they are still escaping.
645 let predicates = ty::fold::shift_vars(interner.tcx, self, 1);
647 let self_ty = interner.tcx.mk_ty(ty::Bound(
648 // This is going to be wrapped in a binder
649 ty::DebruijnIndex::from_usize(1),
650 ty::BoundTy { var: ty::BoundVar::from_usize(0), kind: ty::BoundTyKind::Anon },
652 let where_clauses = predicates.into_iter().map(|predicate| {
653 let (predicate, binders, _named_regions) =
654 collect_bound_vars(interner, interner.tcx, predicate);
656 ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef { def_id, substs }) => {
657 chalk_ir::Binders::new(
659 chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
660 trait_id: chalk_ir::TraitId(def_id),
661 substitution: interner
663 .mk_substs_trait(self_ty, substs)
664 .lower_into(interner),
668 ty::ExistentialPredicate::Projection(predicate) => chalk_ir::Binders::new(
670 chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
671 alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
672 associated_ty_id: chalk_ir::AssocTypeId(predicate.item_def_id),
673 substitution: interner
675 .mk_substs_trait(self_ty, predicate.substs)
676 .lower_into(interner),
678 // FIXME(associated_const_equality): teach chalk about terms for alias eq.
679 ty: predicate.term.ty().unwrap().lower_into(interner),
682 ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
684 chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
685 trait_id: chalk_ir::TraitId(def_id),
686 substitution: interner
688 .mk_substs_trait(self_ty, &[])
689 .lower_into(interner),
695 // Binder for the bound variable representing the concrete underlying type.
696 let existential_binder = chalk_ir::VariableKinds::from1(
698 chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
700 let value = chalk_ir::QuantifiedWhereClauses::from_iter(interner, where_clauses);
701 chalk_ir::Binders::new(existential_binder, value)
705 impl<'tcx> LowerInto<'tcx, chalk_ir::FnSig<RustInterner<'tcx>>>
706 for ty::Binder<'tcx, ty::FnSig<'tcx>>
708 fn lower_into(self, _interner: RustInterner<'_>) -> FnSig<RustInterner<'tcx>> {
711 safety: match self.unsafety() {
712 Unsafety::Normal => chalk_ir::Safety::Safe,
713 Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
715 variadic: self.c_variadic(),
720 // We lower into an Option here since there are some predicates which Chalk
721 // doesn't have a representation for yet (as an `InlineBound`). The `Option` will
722 // eventually be removed.
723 impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>>>
724 for ty::Predicate<'tcx>
728 interner: RustInterner<'tcx>,
729 ) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
730 let (predicate, binders, _named_regions) =
731 collect_bound_vars(interner, interner.tcx, self.kind());
733 ty::PredicateKind::Trait(predicate) => Some(chalk_ir::Binders::new(
735 chalk_solve::rust_ir::InlineBound::TraitBound(
736 predicate.trait_ref.lower_into(interner),
739 ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new(
741 chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
743 ty::PredicateKind::TypeOutlives(_predicate) => None,
744 ty::PredicateKind::WellFormed(_ty) => None,
746 ty::PredicateKind::RegionOutlives(..)
747 | ty::PredicateKind::ObjectSafe(..)
748 | ty::PredicateKind::ClosureKind(..)
749 | ty::PredicateKind::Subtype(..)
750 | ty::PredicateKind::Coerce(..)
751 | ty::PredicateKind::ConstEvaluatable(..)
752 | ty::PredicateKind::ConstEquate(..)
753 | ty::PredicateKind::TypeWellFormedFromEnv(..) => {
754 bug!("unexpected predicate {}", &self)
760 impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>>>
761 for ty::TraitRef<'tcx>
765 interner: RustInterner<'tcx>,
766 ) -> chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>> {
767 chalk_solve::rust_ir::TraitBound {
768 trait_id: chalk_ir::TraitId(self.def_id),
769 args_no_self: self.substs[1..].iter().map(|arg| arg.lower_into(interner)).collect(),
774 impl<'tcx> LowerInto<'tcx, chalk_ir::Mutability> for ast::Mutability {
775 fn lower_into(self, _interner: RustInterner<'tcx>) -> chalk_ir::Mutability {
777 rustc_ast::Mutability::Mut => chalk_ir::Mutability::Mut,
778 rustc_ast::Mutability::Not => chalk_ir::Mutability::Not,
783 impl<'tcx> LowerInto<'tcx, ast::Mutability> for chalk_ir::Mutability {
784 fn lower_into(self, _interner: RustInterner<'tcx>) -> ast::Mutability {
786 chalk_ir::Mutability::Mut => ast::Mutability::Mut,
787 chalk_ir::Mutability::Not => ast::Mutability::Not,
792 impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::Polarity> for ty::ImplPolarity {
793 fn lower_into(self, _interner: RustInterner<'tcx>) -> chalk_solve::rust_ir::Polarity {
795 ty::ImplPolarity::Positive => chalk_solve::rust_ir::Polarity::Positive,
796 ty::ImplPolarity::Negative => chalk_solve::rust_ir::Polarity::Negative,
797 // FIXME(chalk) reservation impls
798 ty::ImplPolarity::Reservation => chalk_solve::rust_ir::Polarity::Negative,
802 impl<'tcx> LowerInto<'tcx, chalk_ir::Variance> for ty::Variance {
803 fn lower_into(self, _interner: RustInterner<'tcx>) -> chalk_ir::Variance {
805 ty::Variance::Covariant => chalk_ir::Variance::Covariant,
806 ty::Variance::Invariant => chalk_ir::Variance::Invariant,
807 ty::Variance::Contravariant => chalk_ir::Variance::Contravariant,
808 ty::Variance::Bivariant => unimplemented!(),
813 impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>>>
814 for ty::ProjectionPredicate<'tcx>
818 interner: RustInterner<'tcx>,
819 ) -> chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>> {
820 let (trait_ref, own_substs) = self.projection_ty.trait_ref_and_own_substs(interner.tcx);
821 chalk_solve::rust_ir::AliasEqBound {
822 trait_bound: trait_ref.lower_into(interner),
823 associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.item_def_id),
824 parameters: own_substs.iter().map(|arg| arg.lower_into(interner)).collect(),
825 value: self.term.ty().unwrap().lower_into(interner),
830 /// To collect bound vars, we have to do two passes. In the first pass, we
831 /// collect all `BoundRegionKind`s and `ty::Bound`s. In the second pass, we then
832 /// replace `BrNamed` into `BrAnon`. The two separate passes are important,
833 /// since we can only replace `BrNamed` with `BrAnon`s with indices *after* all
834 /// "real" `BrAnon`s.
836 /// It's important to note that because of prior substitution, we may have
837 /// late-bound regions, even outside of fn contexts, since this is the best way
838 /// to prep types for chalk lowering.
839 crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>(
840 interner: RustInterner<'tcx>,
843 ) -> (T, chalk_ir::VariableKinds<RustInterner<'tcx>>, BTreeMap<DefId, u32>) {
844 let mut bound_vars_collector = BoundVarsCollector::new();
845 ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector);
846 let mut parameters = bound_vars_collector.parameters;
847 let named_parameters: BTreeMap<DefId, u32> = bound_vars_collector
851 .map(|(i, def_id)| (def_id, (i + parameters.len()) as u32))
854 let mut bound_var_substitutor = NamedBoundVarSubstitutor::new(tcx, &named_parameters);
855 let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor);
857 for var in named_parameters.values() {
858 parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
861 (0..parameters.len()).for_each(|i| {
864 .or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters));
868 chalk_ir::VariableKinds::from_iter(interner, parameters.into_iter().map(|(_, v)| v));
870 (new_ty, binders, named_parameters)
873 crate struct BoundVarsCollector<'tcx> {
874 binder_index: ty::DebruijnIndex,
875 crate parameters: BTreeMap<u32, chalk_ir::VariableKind<RustInterner<'tcx>>>,
876 crate named_parameters: Vec<DefId>,
879 impl<'tcx> BoundVarsCollector<'tcx> {
880 crate fn new() -> Self {
882 binder_index: ty::INNERMOST,
883 parameters: BTreeMap::new(),
884 named_parameters: vec![],
889 impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
890 fn visit_binder<T: TypeFoldable<'tcx>>(
893 ) -> ControlFlow<Self::BreakTy> {
894 self.binder_index.shift_in(1);
895 let result = t.super_visit_with(self);
896 self.binder_index.shift_out(1);
900 fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
902 ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
903 match self.parameters.entry(bound_ty.var.as_u32()) {
904 Entry::Vacant(entry) => {
905 entry.insert(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General));
907 Entry::Occupied(entry) => match entry.get() {
908 chalk_ir::VariableKind::Ty(_) => {}
917 t.super_visit_with(self)
920 fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
922 ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
923 ty::BoundRegionKind::BrNamed(def_id, _name) => {
924 if !self.named_parameters.iter().any(|d| *d == def_id) {
925 self.named_parameters.push(def_id);
929 ty::BoundRegionKind::BrAnon(var) => match self.parameters.entry(var) {
930 Entry::Vacant(entry) => {
931 entry.insert(chalk_ir::VariableKind::Lifetime);
933 Entry::Occupied(entry) => match entry.get() {
934 chalk_ir::VariableKind::Lifetime => {}
939 ty::BoundRegionKind::BrEnv => unimplemented!(),
942 ty::ReEarlyBound(_re) => {
943 // FIXME(chalk): jackh726 - I think we should always have already
944 // substituted away `ReEarlyBound`s for `ReLateBound`s, but need to confirm.
951 r.super_visit_with(self)
955 /// This is used to replace `BoundRegionKind::BrNamed` with `BoundRegionKind::BrAnon`.
956 /// Note: we assume that we will always have room for more bound vars. (i.e. we
957 /// won't ever hit the `u32` limit in `BrAnon`s).
958 struct NamedBoundVarSubstitutor<'a, 'tcx> {
960 binder_index: ty::DebruijnIndex,
961 named_parameters: &'a BTreeMap<DefId, u32>,
964 impl<'a, 'tcx> NamedBoundVarSubstitutor<'a, 'tcx> {
965 fn new(tcx: TyCtxt<'tcx>, named_parameters: &'a BTreeMap<DefId, u32>) -> Self {
966 NamedBoundVarSubstitutor { tcx, binder_index: ty::INNERMOST, named_parameters }
970 impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
971 fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
975 fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: Binder<'tcx, T>) -> Binder<'tcx, T> {
976 self.binder_index.shift_in(1);
977 let result = t.super_fold_with(self);
978 self.binder_index.shift_out(1);
982 fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
984 ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
985 ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
987 let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
988 return self.tcx.mk_region(ty::ReLateBound(index, new_br));
990 None => panic!("Missing `BrNamed`."),
992 ty::BrEnv => unimplemented!(),
998 r.super_fold_with(self)
1002 /// Used to substitute `Param`s with placeholders. We do this since Chalk
1003 /// have a notion of `Param`s.
1004 crate struct ParamsSubstitutor<'tcx> {
1006 binder_index: ty::DebruijnIndex,
1007 list: Vec<rustc_middle::ty::ParamTy>,
1008 next_ty_placeholder: usize,
1009 crate params: rustc_data_structures::fx::FxHashMap<usize, rustc_middle::ty::ParamTy>,
1010 crate named_regions: BTreeMap<DefId, u32>,
1013 impl<'tcx> ParamsSubstitutor<'tcx> {
1014 crate fn new(tcx: TyCtxt<'tcx>, next_ty_placeholder: usize) -> Self {
1017 binder_index: ty::INNERMOST,
1019 next_ty_placeholder,
1020 params: rustc_data_structures::fx::FxHashMap::default(),
1021 named_regions: BTreeMap::default(),
1026 impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
1027 fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
1031 fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: Binder<'tcx, T>) -> Binder<'tcx, T> {
1032 self.binder_index.shift_in(1);
1033 let result = t.super_fold_with(self);
1034 self.binder_index.shift_out(1);
1038 fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
1040 ty::Param(param) => match self.list.iter().position(|r| r == ¶m) {
1041 Some(idx) => self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
1042 universe: ty::UniverseIndex::from_usize(0),
1043 name: ty::BoundVar::from_usize(idx),
1046 self.list.push(param);
1047 let idx = self.list.len() - 1 + self.next_ty_placeholder;
1048 self.params.insert(idx, param);
1049 self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
1050 universe: ty::UniverseIndex::from_usize(0),
1051 name: ty::BoundVar::from_usize(idx),
1055 _ => t.super_fold_with(self),
1059 fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
1061 // FIXME(chalk) - jackh726 - this currently isn't hit in any tests,
1062 // since canonicalization will already change these to canonical
1063 // variables (ty::ReLateBound).
1064 ty::ReEarlyBound(_re) => match self.named_regions.get(&_re.def_id) {
1066 let br = ty::BoundRegion {
1067 var: ty::BoundVar::from_u32(*idx),
1068 kind: ty::BrAnon(*idx),
1070 self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
1073 let idx = self.named_regions.len() as u32;
1075 ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) };
1076 self.named_regions.insert(_re.def_id, idx);
1077 self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
1081 _ => r.super_fold_with(self),
1086 crate struct ReverseParamsSubstitutor<'tcx> {
1088 params: rustc_data_structures::fx::FxHashMap<usize, rustc_middle::ty::ParamTy>,
1091 impl<'tcx> ReverseParamsSubstitutor<'tcx> {
1094 params: rustc_data_structures::fx::FxHashMap<usize, rustc_middle::ty::ParamTy>,
1096 Self { tcx, params }
1100 impl<'tcx> TypeFolder<'tcx> for ReverseParamsSubstitutor<'tcx> {
1101 fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
1105 fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
1107 ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name }) => {
1108 match self.params.get(&name.as_usize()) {
1109 Some(param) => self.tcx.mk_ty(ty::Param(*param)),
1114 _ => t.super_fold_with(self),
1119 /// Used to collect `Placeholder`s.
1120 crate struct PlaceholdersCollector {
1121 universe_index: ty::UniverseIndex,
1122 crate next_ty_placeholder: usize,
1123 crate next_anon_region_placeholder: u32,
1126 impl PlaceholdersCollector {
1127 crate fn new() -> Self {
1128 PlaceholdersCollector {
1129 universe_index: ty::UniverseIndex::ROOT,
1130 next_ty_placeholder: 0,
1131 next_anon_region_placeholder: 0,
1136 impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
1137 fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
1139 ty::Placeholder(p) if p.universe == self.universe_index => {
1140 self.next_ty_placeholder = self.next_ty_placeholder.max(p.name.as_usize() + 1);
1146 t.super_visit_with(self)
1149 fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
1151 ty::RePlaceholder(p) if p.universe == self.universe_index => {
1152 if let ty::BoundRegionKind::BrAnon(anon) = p.name {
1153 self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
1160 r.super_visit_with(self)