Skip to content

Commit 11d62aa

Browse files
committed
Review comments
1 parent dd5c9bf commit 11d62aa

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,10 @@ fn get_rust_try_fn<'ll, 'tcx>(
718718
hir::Unsafety::Unsafe,
719719
Abi::Rust,
720720
)));
721-
let output = tcx.types.i32;
722-
// `unsafe fn(unsafe fn(*mut i8) -> (), unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
721+
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
723722
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
724723
vec![try_fn_ty, i8p, catch_fn_ty].into_iter(),
725-
output,
724+
tcx.types.i32,
726725
false,
727726
hir::Unsafety::Unsafe,
728727
Abi::Rust,

compiler/rustc_middle/src/ty/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,21 @@ impl<'tcx> Predicate<'tcx> {
10561056
}
10571057
}
10581058

1059+
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
1060+
/// `Atom`, then it is not allowed to contain escaping bound vars.
1061+
pub fn bound_atom(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1062+
match self.kind() {
1063+
&PredicateKind::ForAll(binder) => binder,
1064+
&PredicateKind::Atom(atom) => {
1065+
assert!(!atom.has_escaping_bound_vars());
1066+
Binder::dummy(atom)
1067+
}
1068+
}
1069+
}
1070+
10591071
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
10601072
/// contained unbound variables by shifting these variables outwards.
1061-
pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1073+
pub fn bound_atom_with_opt_escaping(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
10621074
match self.kind() {
10631075
&PredicateKind::ForAll(binder) => binder,
10641076
&PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),

compiler/rustc_middle/src/ty/print/pretty.rs

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

compiler/rustc_traits/src/chalk/lowering.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
8181
interner: &RustInterner<'tcx>,
8282
) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> {
8383
let clauses = self.environment.into_iter().map(|predicate| {
84-
let (predicate, binders, _named_regions) =
85-
collect_bound_vars(interner, interner.tcx, &predicate.bound_atom(interner.tcx));
84+
let (predicate, binders, _named_regions) = collect_bound_vars(
85+
interner,
86+
interner.tcx,
87+
&predicate.bound_atom_with_opt_escaping(interner.tcx),
88+
);
8689
let consequence = match predicate {
8790
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
8891
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<'
133136

134137
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
135138
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
136-
let (predicate, binders, _named_regions) =
137-
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
139+
let (predicate, binders, _named_regions) = collect_bound_vars(
140+
interner,
141+
interner.tcx,
142+
&self.bound_atom_with_opt_escaping(interner.tcx),
143+
);
138144

139145
let value = match predicate {
140146
ty::PredicateAtom::Trait(predicate, _) => {
@@ -653,8 +659,11 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
653659
self,
654660
interner: &RustInterner<'tcx>,
655661
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
656-
let (predicate, binders, _named_regions) =
657-
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
662+
let (predicate, binders, _named_regions) = collect_bound_vars(
663+
interner,
664+
interner.tcx,
665+
&self.bound_atom_with_opt_escaping(interner.tcx),
666+
);
658667
let value = match predicate {
659668
ty::PredicateAtom::Trait(predicate, _) => {
660669
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
762771
self,
763772
interner: &RustInterner<'tcx>,
764773
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
765-
let (predicate, binders, _named_regions) =
766-
collect_bound_vars(interner, interner.tcx, &self.bound_atom(interner.tcx));
774+
let (predicate, binders, _named_regions) = collect_bound_vars(
775+
interner,
776+
interner.tcx,
777+
&self.bound_atom_with_opt_escaping(interner.tcx),
778+
);
767779
match predicate {
768780
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
769781
binders,

0 commit comments

Comments
 (0)