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, hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,
))); )));
let output = tcx.types.i32; // `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
// `unsafe fn(unsafe fn(*mut i8) -> (), unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig( let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
vec![try_fn_ty, i8p, catch_fn_ty].into_iter(), vec![try_fn_ty, i8p, catch_fn_ty].into_iter(),
output, tcx.types.i32,
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::Rust, 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 /// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
/// contained unbound variables by shifting these variables outwards. /// 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() { match self.kind() {
&PredicateKind::ForAll(binder) => binder, &PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom), &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. // may contain unbound variables. We therefore do this manually.
// //
// FIXME(lcnr): Find out why exactly this is the case :) // 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() { if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let trait_ref = bound_predicate.map_bound(|_| pred.trait_ref); let trait_ref = bound_predicate.map_bound(|_| pred.trait_ref);
// Don't print +Sized, but rather +?Sized if absent. // 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>, interner: &RustInterner<'tcx>,
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> { ) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
let clauses = self.environment.into_iter().map(|predicate| { let clauses = self.environment.into_iter().map(|predicate| {
let (predicate, binders, _named_regions) = let (predicate, binders, _named_regions) = collect_bound_vars(
collect_bound_vars(interner, interner.tcx, &predicate.bound_atom(interner.tcx)); interner,
interner.tcx,
&predicate.bound_atom_with_opt_escaping(interner.tcx),
);
let consequence = match predicate { let consequence = match predicate {
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))) 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> { 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>> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
let (predicate, binders, _named_regions) = let (predicate, binders, _named_regions) = collect_bound_vars(
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx)); interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate { let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => { ty::PredicateAtom::Trait(predicate, _) => {
@ -653,8 +659,11 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
self, self,
interner: &RustInterner<'tcx>, interner: &RustInterner<'tcx>,
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> { ) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) = let (predicate, binders, _named_regions) = collect_bound_vars(
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx)); interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
let value = match predicate { let value = match predicate {
ty::PredicateAtom::Trait(predicate, _) => { ty::PredicateAtom::Trait(predicate, _) => {
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner))) 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, self,
interner: &RustInterner<'tcx>, interner: &RustInterner<'tcx>,
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> { ) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
let (predicate, binders, _named_regions) = let (predicate, binders, _named_regions) = collect_bound_vars(
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx)); interner,
interner.tcx,
&self.bound_atom_with_opt_escaping(interner.tcx),
);
match predicate { match predicate {
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new( ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
binders, binders,