Skip to content

Commit 53c5310

Browse files
More work
1 parent 729ee29 commit 53c5310

File tree

61 files changed

+184
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+184
-163
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
126126
}
127127
_ => bug!(),
128128
};
129-
let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
130-
.to_predicate(self.tcx());
129+
// This predicate may have escaping bound vars,
130+
// e.g. if we have `for<'a: 'a> ..`.
131+
let pred = ty::Binder::bind_with_vars(
132+
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
133+
ty::List::empty(),
134+
)
135+
.to_predicate(self.tcx());
131136
(pred, span)
132137
}))
133138
}
@@ -715,7 +720,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
715720
ast_bounds.iter(),
716721
bounds,
717722
projection_ty.bound_vars(),
718-
projection_ty.skip_binder_predicates(),
723+
projection_ty.skip_binder_with_predicates().1,
719724
only_self_bounds,
720725
);
721726
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
851851
});
852852

853853
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
854-
let trait_ref = this.instantiate_binder_with_fresh_vars(
854+
// FIXME(non_lifetime_binders): We could check these predicates hold.
855+
let (trait_ref, _) = this.instantiate_binder_and_predicates_with_fresh_vars(
855856
this.span,
856857
infer::LateBoundRegionConversionTime::FnCall,
857858
poly_trait_ref,

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::infer::CombinedSnapshot;
77
use rustc_middle::ty::fold::FnMutDelegate;
88
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
99
use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable};
10+
use rustc_span::DUMMY_SP;
1011

1112
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
1213
/// Checks whether `for<..> sub <: for<..> sup` holds.
@@ -74,7 +75,12 @@ impl<'tcx> InferCtxt<'tcx> {
7475
where
7576
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
7677
{
77-
assert_eq!(binder.skip_binder_predicates(), ty::List::empty());
78+
if !binder.skip_binder_with_predicates().1.is_empty() {
79+
self.tcx.sess.delay_span_bug(
80+
DUMMY_SP,
81+
"binder instantiated with placeholders ignoring predicates",
82+
);
83+
}
7884

7985
if let Some(inner) = binder.no_bound_vars() {
8086
return inner;

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use self::SubregionOrigin::*;
77
pub use self::ValuePairs::*;
88
pub use combine::ObligationEmittingRelation;
99
use rustc_data_structures::undo_log::UndoLogs;
10+
use rustc_span::DUMMY_SP;
1011

1112
use self::opaque_types::OpaqueTypeStorage;
1213
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
@@ -1446,7 +1447,11 @@ impl<'tcx> InferCtxt<'tcx> {
14461447
where
14471448
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
14481449
{
1449-
assert_eq!(value.skip_binder_predicates(), ty::List::empty());
1450+
if !value.skip_binder_with_predicates().1.is_empty() {
1451+
self.tcx
1452+
.sess
1453+
.delay_span_bug(DUMMY_SP, "binder instantiated with infer ignoring predicates");
1454+
}
14501455

14511456
if let Some(inner) = value.no_bound_vars() {
14521457
return inner;

compiler/rustc_infer/src/infer/nll_relate/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ where
263263
where
264264
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
265265
{
266-
assert_eq!(binder.skip_binder_predicates(), ty::List::empty());
266+
assert_eq!(binder.skip_binder_with_predicates().1, ty::List::empty());
267267

268268
if let Some(inner) = binder.no_bound_vars() {
269269
return inner;
@@ -313,7 +313,7 @@ where
313313
where
314314
T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
315315
{
316-
assert_eq!(binder.skip_binder_predicates(), ty::List::empty());
316+
assert_eq!(binder.skip_binder_with_predicates().1, ty::List::empty());
317317

318318
if let Some(inner) = binder.no_bound_vars() {
319319
return inner;

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
7777
for (pred, pred_span) in
7878
cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied()
7979
{
80-
let predicate = infcx.instantiate_binder_with_placeholders(pred.kind());
80+
// FIXME(non_lifetime_binders): We could assume the predicates in this binder.
81+
let (predicate, _) =
82+
infcx.instantiate_binder_and_assumptions_with_placeholders(pred.kind());
8183
let ty::ClauseKind::Projection(proj) = predicate else {
8284
continue;
8385
};

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
12901290
nop_lift! {predicate; Clause<'a> => Clause<'tcx>}
12911291

12921292
nop_list_lift! {type_lists; Ty<'a> => Ty<'tcx>}
1293+
nop_list_lift! {clauses; Clause<'a> => Clause<'tcx>}
12931294
nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
12941295
nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariableKind}
12951296

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ impl<'tcx> TyCtxt<'tcx> {
322322
value: Binder<'tcx, T>,
323323
delegate: impl BoundVarReplacerDelegate<'tcx>,
324324
) -> (T, &'tcx ty::List<ty::Clause<'tcx>>) {
325-
let preds = value.skip_binder_predicates();
326-
self.replace_escaping_bound_vars_uncached((value.skip_binder(), preds), delegate)
325+
self.replace_escaping_bound_vars_uncached(value.skip_binder_with_predicates(), delegate)
327326
}
328327

329328
/// Replaces any late-bound regions bound in `value` with

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'tcx> Clause<'tcx> {
823823
// 1) Self: Bar1<'a, '^0.0> -> Self: Bar1<'a, '^0.1>
824824
let (shifted_pred, shifted_bound_clauses) = tcx.shift_bound_var_indices(
825825
trait_bound_vars.len(),
826-
(bound_pred.skip_binder(), bound_pred.skip_binder_predicates()),
826+
bound_pred.skip_binder_with_predicates(),
827827
);
828828
// 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1>
829829
let new = EarlyBinder::bind(shifted_pred).instantiate(tcx, trait_ref.skip_binder().args);
@@ -832,7 +832,7 @@ impl<'tcx> Clause<'tcx> {
832832
tcx.mk_bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars));
833833

834834
let binder_predicates = tcx.mk_clauses_from_iter(
835-
trait_ref.skip_binder_predicates().into_iter().chain(shifted_bound_clauses),
835+
trait_ref.skip_binder_with_predicates().1.into_iter().chain(shifted_bound_clauses),
836836
);
837837

838838
// FIXME: Is it really perf sensitive to use reuse_or_mk_predicate here?

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> TypeSuperFoldable<TyCtxt<'tcx>> for ty
585585
self,
586586
folder: &mut F,
587587
) -> Result<Self, F::Error> {
588-
self.try_map_bound(|ty| ty.try_fold_with(folder))
588+
let bound_vars = self.bound_vars();
589+
let (value, bound_predicates) = self.skip_binder_with_predicates().try_fold_with(folder)?;
590+
Ok(ty::Binder::bind_with_vars_and_predicates(value, bound_vars, bound_predicates))
589591
}
590592
}
591593

@@ -596,7 +598,9 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeSuperVisitable<TyCtxt<'tcx>>
596598
&self,
597599
visitor: &mut V,
598600
) -> ControlFlow<V::BreakTy> {
599-
self.as_ref().skip_binder().visit_with(visitor)
601+
let (val, predicates) = self.as_ref().skip_binder_with_predicates();
602+
val.visit_with(visitor)?;
603+
predicates.visit_with(visitor)
600604
}
601605
}
602606

0 commit comments

Comments
 (0)