Skip to content

Commit 476bd53

Browse files
committed
Cleanup
1 parent 7f24c21 commit 476bd53

File tree

9 files changed

+25
-66
lines changed

9 files changed

+25
-66
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
541541
span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
542542
}
543543
};
544-
let predicate = predicate.rebind(atom).potentially_quantified(self.tcx);
544+
let predicate = predicate.rebind(atom).to_predicate(self.tcx);
545545

546546
Obligation::new(cause.clone(), param_env, predicate)
547547
})

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,16 +1070,6 @@ impl<'tcx> Predicate<'tcx> {
10701070
self.inner.binder.skip_binder()
10711071
}
10721072

1073-
/// Returns the inner `PredicateAtom`.
1074-
///
1075-
/// Note that this method does not check if the predicate has unbound variables.
1076-
///
1077-
/// Rebinding the returned atom can causes the previously bound variables
1078-
/// to end up at the wrong binding level.
1079-
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
1080-
self.inner.binder.skip_binder()
1081-
}
1082-
10831073
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
10841074
/// `Atom`, then it is not allowed to contain escaping bound vars.
10851075
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
@@ -1089,12 +1079,6 @@ impl<'tcx> Predicate<'tcx> {
10891079
pub fn bound_atom_ref(self) -> &'tcx Binder<PredicateAtom<'tcx>> {
10901080
&self.inner.binder
10911081
}
1092-
1093-
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
1094-
/// contained unbound variables by shifting these variables outwards.
1095-
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1096-
self.inner.binder
1097-
}
10981082
}
10991083

11001084
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
@@ -1160,13 +1144,6 @@ pub enum PredicateAtom<'tcx> {
11601144
TypeWellFormedFromEnv(Ty<'tcx>),
11611145
}
11621146

1163-
impl<'tcx> Binder<PredicateAtom<'tcx>> {
1164-
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
1165-
pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1166-
self.to_predicate(tcx)
1167-
}
1168-
}
1169-
11701147
/// The crate outlives map is computed during typeck and contains the
11711148
/// outlives of every item in the local crate. You should not use it
11721149
/// directly, because to do so will make your pass dependent on the
@@ -1254,7 +1231,7 @@ impl<'tcx> Predicate<'tcx> {
12541231
let substs = trait_ref.skip_binder().substs;
12551232
let pred = self.skip_binders();
12561233
let new = pred.subst(tcx, substs);
1257-
if new != pred { ty::Binder::bind(new).potentially_quantified(tcx) } else { self }
1234+
if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self }
12581235
}
12591236
}
12601237

@@ -1409,27 +1386,25 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
14091386

14101387
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
14111388
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1412-
self.value
1413-
.map_bound(|value| PredicateAtom::Trait(value, self.constness))
1414-
.potentially_quantified(tcx)
1389+
self.value.map_bound(|value| PredicateAtom::Trait(value, self.constness)).to_predicate(tcx)
14151390
}
14161391
}
14171392

14181393
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
14191394
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1420-
self.map_bound(PredicateAtom::RegionOutlives).potentially_quantified(tcx)
1395+
self.map_bound(PredicateAtom::RegionOutlives).to_predicate(tcx)
14211396
}
14221397
}
14231398

14241399
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
14251400
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1426-
self.map_bound(PredicateAtom::TypeOutlives).potentially_quantified(tcx)
1401+
self.map_bound(PredicateAtom::TypeOutlives).to_predicate(tcx)
14271402
}
14281403
}
14291404

14301405
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14311406
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1432-
self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx)
1407+
self.map_bound(PredicateAtom::Projection).to_predicate(tcx)
14331408
}
14341409
}
14351410

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ pub trait PrettyPrinter<'tcx>:
627627
// may contain unbound variables. We therefore do this manually.
628628
//
629629
// FIXME(lcnr): Find out why exactly this is the case :)
630-
let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx());
630+
let bound_predicate = predicate.bound_atom();
631631
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
632632
let trait_ref = bound_predicate.rebind(pred.trait_ref);
633633
// Don't print +Sized, but rather +?Sized if absent.

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ 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) = collect_bound_vars(
85-
interner,
86-
interner.tcx,
87-
predicate.bound_atom_with_opt_escaping(interner.tcx),
88-
);
84+
let (predicate, binders, _named_regions) =
85+
collect_bound_vars(interner, interner.tcx, predicate.bound_atom());
8986
let consequence = match predicate {
9087
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
9188
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
@@ -136,11 +133,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
136133

137134
impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
138135
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'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-
);
136+
let (predicate, binders, _named_regions) =
137+
collect_bound_vars(interner, interner.tcx, self.bound_atom());
144138

145139
let value = match predicate {
146140
ty::PredicateAtom::Trait(predicate, _) => {
@@ -573,11 +567,8 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
573567
self,
574568
interner: &RustInterner<'tcx>,
575569
) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
576-
let (predicate, binders, _named_regions) = collect_bound_vars(
577-
interner,
578-
interner.tcx,
579-
self.bound_atom_with_opt_escaping(interner.tcx),
580-
);
570+
let (predicate, binders, _named_regions) =
571+
collect_bound_vars(interner, interner.tcx, self.bound_atom());
581572
let value = match predicate {
582573
ty::PredicateAtom::Trait(predicate, _) => {
583574
Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)))
@@ -707,11 +698,8 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
707698
self,
708699
interner: &RustInterner<'tcx>,
709700
) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> {
710-
let (predicate, binders, _named_regions) = collect_bound_vars(
711-
interner,
712-
interner.tcx,
713-
self.bound_atom_with_opt_escaping(interner.tcx),
714-
);
701+
let (predicate, binders, _named_regions) =
702+
collect_bound_vars(interner, interner.tcx, self.bound_atom());
715703
match predicate {
716704
ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new(
717705
binders,

compiler/rustc_typeck/src/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
544544
self.infcx.instantiate_opaque_types(id, self.body_id, self.param_env, ty, span);
545545
let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty();
546546
for o in impl_trait_ret_ty.obligations {
547-
match o.predicate.skip_binders_unchecked() {
547+
match o.predicate.bound_atom().skip_binder() {
548548
ty::PredicateAtom::Trait(t, constness) => {
549549
let pred = ty::PredicateAtom::Trait(
550550
ty::TraitPredicate {

compiler/rustc_typeck/src/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19491949
let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
19501950
ty::OutlivesPredicate(ty, re_root_empty),
19511951
));
1952-
predicates.insert((predicate.potentially_quantified(tcx), span));
1952+
predicates.insert((predicate.to_predicate(tcx), span));
19531953
}
19541954
}
19551955

@@ -1993,7 +1993,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19931993
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
19941994
ty::OutlivesPredicate(ty, region),
19951995
))
1996-
.potentially_quantified(tcx),
1996+
.to_predicate(tcx),
19971997
lifetime.span,
19981998
));
19991999
}

compiler/rustc_typeck/src/outlives/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
3030
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
3131
let mut pred: Vec<String> = predicates
3232
.iter()
33-
.map(|(out_pred, _)| {
34-
let binder = out_pred.bound_atom();
35-
match binder.skip_binder() {
36-
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
37-
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
38-
err => bug!("unexpected predicate {:?}", err),
39-
}
33+
.map(|(out_pred, _)| match out_pred.bound_atom().skip_binder() {
34+
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
35+
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
36+
err => bug!("unexpected predicate {:?}", err),
4037
})
4138
.collect();
4239
pred.sort();

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
16861686
.filter_map(|bound| {
16871687
// Note: The substs of opaque types can contain unbound variables,
16881688
// meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
1689-
let bound_predicate = bound.bound_atom_with_opt_escaping(cx.tcx);
1689+
let bound_predicate = bound.bound_atom();
16901690
let trait_ref = match bound_predicate.skip_binder() {
16911691
ty::PredicateAtom::Trait(tr, _constness) => {
16921692
bound_predicate.rebind(tr.trait_ref)
@@ -1711,7 +1711,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
17111711
.iter()
17121712
.filter_map(|bound| {
17131713
if let ty::PredicateAtom::Projection(proj) =
1714-
bound.bound_atom_with_opt_escaping(cx.tcx).skip_binder()
1714+
bound.bound_atom().skip_binder()
17151715
{
17161716
if proj.projection_ty.trait_ref(cx.tcx)
17171717
== trait_ref.skip_binder()

src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
115115
.filter(|p| !p.is_global())
116116
.filter_map(|obligation| {
117117
// Note that we do not want to deal with qualified predicates here.
118-
let binder = obligation.predicate.bound_atom();
119-
match binder.skip_binder() {
118+
match obligation.predicate.bound_atom().skip_binder() {
120119
ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => {
121120
if pred.def_id() == sized_trait {
122121
return None;

0 commit comments

Comments
 (0)