summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_traits/src/chalk/lowering.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_traits/src/chalk/lowering.rs')
-rw-r--r--compiler/rustc_traits/src/chalk/lowering.rs127
1 files changed, 73 insertions, 54 deletions
diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs
index 45d5ea93d..c4ab86e9e 100644
--- a/compiler/rustc_traits/src/chalk/lowering.rs
+++ b/compiler/rustc_traits/src/chalk/lowering.rs
@@ -89,24 +89,32 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
}
- ty::PredicateKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
- chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
- ),
- ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds(
- chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
- a: predicate.0.lower_into(interner),
- b: predicate.1.lower_into(interner),
- }),
- ),
- ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds(
- chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
- ty: predicate.0.lower_into(interner),
- lifetime: predicate.1.lower_into(interner),
- }),
- ),
- ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds(
- chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
- ),
+ ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
+ chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Trait(
+ predicate.trait_ref.lower_into(interner),
+ ))
+ }
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
+ chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::LifetimeOutlives(
+ chalk_ir::LifetimeOutlives {
+ a: predicate.0.lower_into(interner),
+ b: predicate.1.lower_into(interner),
+ },
+ ))
+ }
+ ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
+ chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::TypeOutlives(
+ chalk_ir::TypeOutlives {
+ ty: predicate.0.lower_into(interner),
+ lifetime: predicate.1.lower_into(interner),
+ },
+ ))
+ }
+ ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
+ chalk_ir::DomainGoal::Holds(chalk_ir::WhereClause::AliasEq(
+ predicate.lower_into(interner),
+ ))
+ }
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
ty::GenericArgKind::Type(ty) => chalk_ir::DomainGoal::WellFormed(
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
@@ -121,6 +129,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::ConstEvaluatable(..)
+ | ty::PredicateKind::Ambiguous
| ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", predicate),
};
let value = chalk_ir::ProgramClauseImplication {
@@ -148,12 +157,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
- ty::PredicateKind::Trait(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
))
}
- ty::PredicateKind::RegionOutlives(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
@@ -161,7 +170,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
}),
))
}
- ty::PredicateKind::TypeOutlives(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
@@ -169,7 +178,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
}),
))
}
- ty::PredicateKind::Projection(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)),
))
@@ -212,6 +221,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::ConstEvaluatable(..)
+ | ty::PredicateKind::Ambiguous
| ty::PredicateKind::ConstEquate(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
@@ -411,7 +421,11 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
TyKind::Closure(closure, substitution) => {
ty::Closure(closure.0, substitution.lower_into(interner))
}
- TyKind::Generator(..) => unimplemented!(),
+ TyKind::Generator(generator, substitution) => ty::Generator(
+ generator.0,
+ substitution.lower_into(interner),
+ ast::Movability::Static,
+ ),
TyKind::GeneratorWitness(..) => unimplemented!(),
TyKind::Never => ty::Never,
TyKind::Tuple(_len, substitution) => {
@@ -498,18 +512,15 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
ty::BoundRegion {
var: ty::BoundVar::from_usize(var.index),
- kind: ty::BrAnon(var.index as u32),
+ kind: ty::BrAnon(var.index as u32, None),
},
),
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
universe: ty::UniverseIndex::from_usize(p.ui.counter),
- name: ty::BoundRegionKind::BrAnon(p.idx as u32),
+ name: ty::BoundRegionKind::BrAnon(p.idx as u32, None),
}),
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
- chalk_ir::LifetimeData::Empty(_) => {
- bug!("Chalk should not have been passed an empty lifetime.")
- }
chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased,
chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
};
@@ -546,7 +557,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'t
chalk_ir::ConstValue::Placeholder(_p) => unimplemented!(),
chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned),
};
- interner.tcx.mk_const(ty::ConstS { ty, kind })
+ interner.tcx.mk_const(kind, ty)
}
}
@@ -602,22 +613,22 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
let value = match predicate {
- ty::PredicateKind::Trait(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
}
- ty::PredicateKind::RegionOutlives(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
a: predicate.0.lower_into(interner),
b: predicate.1.lower_into(interner),
}))
}
- ty::PredicateKind::TypeOutlives(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => {
Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
}))
}
- ty::PredicateKind::Projection(predicate) => {
+ ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
}
ty::PredicateKind::WellFormed(_ty) => None,
@@ -628,6 +639,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
+ | ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("unexpected predicate {}", &self)
}
@@ -637,7 +649,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
}
impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>>>
- for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>
+ for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>
{
fn lower_into(
self,
@@ -692,7 +704,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
trait_id: chalk_ir::TraitId(def_id),
substitution: interner
.tcx
- .mk_substs_trait(self_ty, &[])
+ .mk_substs_trait(self_ty, [])
.lower_into(interner),
}),
),
@@ -737,26 +749,31 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, self.kind());
match predicate {
- ty::PredicateKind::Trait(predicate) => Some(chalk_ir::Binders::new(
- binders,
- chalk_solve::rust_ir::InlineBound::TraitBound(
- predicate.trait_ref.lower_into(interner),
- ),
- )),
- ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new(
- binders,
- chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
- )),
- ty::PredicateKind::TypeOutlives(_predicate) => None,
+ ty::PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
+ Some(chalk_ir::Binders::new(
+ binders,
+ chalk_solve::rust_ir::InlineBound::TraitBound(
+ predicate.trait_ref.lower_into(interner),
+ ),
+ ))
+ }
+ ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => {
+ Some(chalk_ir::Binders::new(
+ binders,
+ chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)),
+ ))
+ }
+ ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_predicate)) => None,
ty::PredicateKind::WellFormed(_ty) => None,
- ty::PredicateKind::RegionOutlives(..)
+ ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::ConstEvaluatable(..)
| ty::PredicateKind::ConstEquate(..)
+ | ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
bug!("unexpected predicate {}", &self)
}
@@ -933,7 +950,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
}
}
- ty::BoundRegionKind::BrAnon(var) => match self.parameters.entry(var) {
+ ty::BoundRegionKind::BrAnon(var, _) => match self.parameters.entry(var) {
Entry::Vacant(entry) => {
entry.insert(chalk_ir::VariableKind::Lifetime);
}
@@ -991,13 +1008,13 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
Some(idx) => {
- let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
+ let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) };
return self.tcx.mk_region(ty::ReLateBound(index, new_br));
}
None => panic!("Missing `BrNamed`."),
},
ty::BrEnv => unimplemented!(),
- ty::BrAnon(_) => {}
+ ty::BrAnon(..) => {}
},
_ => (),
};
@@ -1072,14 +1089,16 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
Some(idx) => {
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(*idx),
- kind: ty::BrAnon(*idx),
+ kind: ty::BrAnon(*idx, None),
};
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
}
None => {
let idx = self.named_regions.len() as u32;
- let br =
- ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) };
+ let br = ty::BoundRegion {
+ var: ty::BoundVar::from_u32(idx),
+ kind: ty::BrAnon(idx, None),
+ };
self.named_regions.insert(_re.def_id, idx);
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
}
@@ -1156,7 +1175,7 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
match *r {
ty::RePlaceholder(p) if p.universe == self.universe_index => {
- if let ty::BoundRegionKind::BrAnon(anon) = p.name {
+ if let ty::BoundRegionKind::BrAnon(anon, _) = p.name {
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
}
}