Review comments

This commit is contained in:
Jack Huey 2020-10-11 17:14:07 -04:00
parent dd5c9bf139
commit 11d62aa284
4 changed files with 36 additions and 13 deletions

View File

@ -718,11 +718,10 @@ fn get_rust_try_fn<'ll, 'tcx>(
hir::Unsafety::Unsafe,
Abi::Rust,
)));
let output = tcx.types.i32;
// `unsafe fn(unsafe fn(*mut i8) -> (), unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
vec![try_fn_ty, i8p, catch_fn_ty].into_iter(),
output,
tcx.types.i32,
false,
hir::Unsafety::Unsafe,
Abi::Rust,

View File

@ -1056,9 +1056,21 @@ impl<'tcx> Predicate<'tcx> {
}
}
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
/// `Atom`, then it is not allowed to contain escaping bound vars.
pub fn bound_atom(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => {
assert!(!atom.has_escaping_bound_vars());
Binder::dummy(atom)
}
}
}
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
/// contained unbound variables by shifting these variables outwards.
pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
pub fn bound_atom_with_opt_escaping(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),

View File

@ -618,7 +618,7 @@ pub trait PrettyPrinter<'tcx>:
// may contain unbound variables. We therefore do this manually.
//
// FIXME(lcnr): Find out why exactly this is the case :)
let bound_predicate = predicate.bound_atom(self.tcx());
let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx());
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let trait_ref = bound_predicate.map_bound(|_| pred.trait_ref);
// Don't print +Sized, but rather +?Sized if absent.

View File

@ -81,8 +81,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
interner: &RustInterner<'tcx>,
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
let clauses = self.environment.into_iter().map(|predicate| {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate.bound_atom(interner.tcx));
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&predicate.bound_atom_with_opt_escaping(interner.tcx),
);
let consequence = match predicate {
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
@ -133,8 +136,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => {
@ -653,8 +659,11 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => {
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
@ -762,8 +771,11 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
self,
interner: &RustInterner<'tcx>,
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
let (predicate, binders, _named_regions) = collect_bound_vars(
interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
match predicate {
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
binders,