Skip to content

Commit 4fe5ebb

Browse files
committed
stop using ignore_qualifiers_with_unbound_vars everywhere
1 parent a4bb0b1 commit 4fe5ebb

File tree

38 files changed

+171
-265
lines changed

38 files changed

+171
-265
lines changed

src/librustc_infer/infer/outlives/env.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::infer::{GenericKind, InferCtxt};
33
use crate::traits::query::OutlivesBound;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_hir as hir;
6-
use rustc_middle::ty::{self, TyCtxt};
6+
use rustc_middle::ty;
77

88
use super::explicit_outlives_bounds;
99

@@ -69,15 +69,15 @@ pub struct OutlivesEnvironment<'tcx> {
6969
pub type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>;
7070

7171
impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
72-
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
72+
pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self {
7373
let mut env = OutlivesEnvironment {
7474
param_env,
7575
free_region_map: Default::default(),
7676
region_bound_pairs_map: Default::default(),
7777
region_bound_pairs_accum: vec![],
7878
};
7979

80-
env.add_outlives_bounds(None, explicit_outlives_bounds(tcx, param_env));
80+
env.add_outlives_bounds(None, explicit_outlives_bounds(param_env));
8181

8282
env
8383
}

src/librustc_infer/infer/outlives/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ pub mod obligations;
55
pub mod verify;
66

77
use rustc_middle::traits::query::OutlivesBound;
8-
use rustc_middle::ty::{self, TyCtxt};
8+
use rustc_middle::ty;
99

1010
pub fn explicit_outlives_bounds<'tcx>(
11-
tcx: TyCtxt<'tcx>,
1211
param_env: ty::ParamEnv<'tcx>,
1312
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1413
debug!("explicit_outlives_bounds()");
1514
param_env
1615
.caller_bounds
1716
.into_iter()
18-
.filter_map(move |pred| pred.ignore_qualifiers_with_unbound_vars(tcx).no_bound_vars())
17+
.filter_map(|pred| pred.ignore_qualifiers().no_bound_vars())
1918
.filter_map(|pred| match pred.kind() {
2019
ty::PredicateKind::Projection(..)
2120
| ty::PredicateKind::Trait(..)

src/librustc_infer/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Elaborator<'tcx> {
138138
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
139139
let tcx = self.visited.tcx;
140140

141-
match obligation.predicate.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind() {
141+
match obligation.predicate.ignore_qualifiers().skip_binder().kind() {
142142
ty::PredicateKind::ForAll(_) => {
143143
bug!("unexpected predicate: {:?}", obligation.predicate)
144144
}

src/librustc_lint/builtin.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12141214
for &(predicate, span) in predicates.predicates {
12151215
// We don't actually look inside of the predicate,
12161216
// so it is safe to skip this binder here.
1217-
let predicate_kind_name = match predicate.ignore_qualifiers_with_unbound_vars(cx.tcx).skip_binder().kind() {
1217+
let predicate_kind_name = match predicate.ignore_qualifiers().skip_binder().kind() {
12181218
Trait(..) => "Trait",
12191219
TypeOutlives(..) |
12201220
RegionOutlives(..) => "Lifetime",
@@ -1499,38 +1499,32 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
14991499

15001500
impl ExplicitOutlivesRequirements {
15011501
fn lifetimes_outliving_lifetime<'tcx>(
1502-
tcx: TyCtxt<'tcx>,
15031502
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
15041503
index: u32,
15051504
) -> Vec<ty::Region<'tcx>> {
15061505
inferred_outlives
15071506
.iter()
1508-
.filter_map(|(pred, _)| {
1509-
match pred.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind() {
1510-
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
1511-
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
1512-
_ => None,
1513-
},
1507+
.filter_map(|(pred, _)| match pred.ignore_qualifiers().skip_binder().kind() {
1508+
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
1509+
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
15141510
_ => None,
1515-
}
1511+
},
1512+
_ => None,
15161513
})
15171514
.collect()
15181515
}
15191516

15201517
fn lifetimes_outliving_type<'tcx>(
1521-
tcx: TyCtxt<'tcx>,
15221518
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
15231519
index: u32,
15241520
) -> Vec<ty::Region<'tcx>> {
15251521
inferred_outlives
15261522
.iter()
1527-
.filter_map(|(pred, _)| {
1528-
match pred.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind() {
1529-
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
1530-
a.is_param(index).then_some(b)
1531-
}
1532-
_ => None,
1523+
.filter_map(|(pred, _)| match pred.ignore_qualifiers().skip_binder().kind() {
1524+
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
1525+
a.is_param(index).then_some(b)
15331526
}
1527+
_ => None,
15341528
})
15351529
.collect()
15361530
}
@@ -1547,10 +1541,10 @@ impl ExplicitOutlivesRequirements {
15471541

15481542
match param.kind {
15491543
hir::GenericParamKind::Lifetime { .. } => {
1550-
Self::lifetimes_outliving_lifetime(tcx, inferred_outlives, index)
1544+
Self::lifetimes_outliving_lifetime(inferred_outlives, index)
15511545
}
15521546
hir::GenericParamKind::Type { .. } => {
1553-
Self::lifetimes_outliving_type(tcx, inferred_outlives, index)
1547+
Self::lifetimes_outliving_type(inferred_outlives, index)
15541548
}
15551549
hir::GenericParamKind::Const { .. } => Vec::new(),
15561550
}
@@ -1702,11 +1696,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
17021696
cx.tcx.named_region(predicate.lifetime.hir_id)
17031697
{
17041698
(
1705-
Self::lifetimes_outliving_lifetime(
1706-
cx.tcx,
1707-
inferred_outlives,
1708-
index,
1709-
),
1699+
Self::lifetimes_outliving_lifetime(inferred_outlives, index),
17101700
&predicate.bounds,
17111701
predicate.span,
17121702
)
@@ -1722,11 +1712,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
17221712
if let Res::Def(DefKind::TyParam, def_id) = path.res {
17231713
let index = ty_generics.param_def_id_to_index[&def_id];
17241714
(
1725-
Self::lifetimes_outliving_type(
1726-
cx.tcx,
1727-
inferred_outlives,
1728-
index,
1729-
),
1715+
Self::lifetimes_outliving_type(inferred_outlives, index),
17301716
&predicate.bounds,
17311717
predicate.span,
17321718
)

src/librustc_lint/unused.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
147147
let mut has_emitted = false;
148148
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
149149
// We only look at the `DefId`, so it is safe to skip the binder here.
150-
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate
151-
.ignore_qualifiers_with_unbound_vars(cx.tcx)
152-
.skip_binder()
153-
.kind()
150+
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
151+
predicate.ignore_qualifiers().skip_binder().kind()
154152
{
155153
let def_id = poly_trait_predicate.trait_ref.def_id;
156154
let descr_pre =

src/librustc_middle/ty/print/pretty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ pub trait PrettyPrinter<'tcx>:
575575
for predicate in bounds.predicates {
576576
// Note: We can't use `to_opt_poly_trait_ref` here as `predicate`
577577
// may contain unbound variables. We therefore do this manually.
578+
//
579+
// FIXME(lcnr): Find out why exactly this is the case :)
578580
if let ty::PredicateKind::Trait(pred, _) = predicate
579581
.ignore_qualifiers_with_unbound_vars(self.tcx())
580582
.skip_binder()

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
579579
if let (Some(f), Some(ty::RegionKind::ReStatic)) =
580580
(self.to_error_region(fr), self.to_error_region(outlived_fr))
581581
{
582-
if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
582+
if let Some((&ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
583583
.infcx
584584
.tcx
585585
.is_suitable_region(f)
@@ -592,16 +592,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
592592
//
593593
// eg. check for `impl Trait + 'static` instead of `impl Trait`.
594594
let has_static_predicate = {
595-
let predicates_of = self.infcx.tcx.predicates_of(*did);
595+
let predicates_of = self.infcx.tcx.predicates_of(did);
596596
let bounds = predicates_of.instantiate(self.infcx.tcx, substs);
597597

598598
let mut found = false;
599599
for predicate in bounds.predicates {
600600
if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
601-
predicate
602-
.ignore_qualifiers_with_unbound_vars(self.infcx.tcx)
603-
.skip_binder()
604-
.kind()
601+
predicate.ignore_qualifiers().skip_binder().kind()
605602
{
606603
if let ty::RegionKind::ReStatic = r {
607604
found = true;
@@ -628,7 +625,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
628625
diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str));
629626
} else {
630627
// Otherwise, we should suggest adding a constraint on the return type.
631-
let span = self.infcx.tcx.def_span(*did);
628+
let span = self.infcx.tcx.def_span(did);
632629
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
633630
let suggestable_fr_name = if fr_name.was_named() {
634631
fr_name.to_string()

src/librustc_mir/borrow_check/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
274274

275275
// Insert the facts we know from the predicates. Why? Why not.
276276
let param_env = self.param_env;
277-
self.add_outlives_bounds(outlives::explicit_outlives_bounds(self.infcx.tcx, param_env));
277+
self.add_outlives_bounds(outlives::explicit_outlives_bounds(param_env));
278278

279279
// Finally:
280280
// - outlives is reflexive, so `'r: 'r` for every region `'r`

src/librustc_mir/transform/qualify_min_const_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
2323
loop {
2424
let predicates = tcx.predicates_of(current);
2525
for (predicate, _) in predicates.predicates {
26-
match predicate.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind() {
26+
match predicate.ignore_qualifiers().skip_binder().kind() {
2727
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
2828
ty::PredicateKind::RegionOutlives(_)
2929
| ty::PredicateKind::TypeOutlives(_)

src/librustc_privacy/lib.rs

+25-27
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,33 @@ where
8484
|| (!self.def_id_visitor.shallow() && substs.visit_with(self))
8585
}
8686

87+
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> bool {
88+
match predicate.kind() {
89+
&ty::PredicateKind::ForAll(pred) => {
90+
// This visitor does not care about bound regions as we only
91+
// look at `DefId`s.
92+
self.visit_predicate(*pred.skip_binder())
93+
}
94+
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
95+
self.visit_trait(trait_ref)
96+
}
97+
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
98+
ty.visit_with(self)
99+
|| self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx()))
100+
}
101+
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
102+
ty.visit_with(self)
103+
}
104+
ty::PredicateKind::RegionOutlives(..) => false,
105+
_ => bug!("unexpected predicate: {:?}", predicate),
106+
}
107+
}
108+
87109
fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool {
88110
let ty::GenericPredicates { parent: _, predicates } = predicates;
89-
for (predicate, _span) in predicates {
90-
// This visitor does not care about bound regions.
91-
match predicate
92-
.ignore_qualifiers_with_unbound_vars(self.def_id_visitor.tcx())
93-
.skip_binder()
94-
.kind()
95-
{
96-
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
97-
if self.visit_trait(trait_ref) {
98-
return true;
99-
}
100-
}
101-
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
102-
if ty.visit_with(self) {
103-
return true;
104-
}
105-
if self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx())) {
106-
return true;
107-
}
108-
}
109-
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
110-
if ty.visit_with(self) {
111-
return true;
112-
}
113-
}
114-
ty::PredicateKind::RegionOutlives(..) => {}
115-
_ => bug!("unexpected predicate: {:?}", predicate),
111+
for &(predicate, _span) in predicates {
112+
if self.visit_predicate(predicate) {
113+
return true;
116114
}
117115
}
118116
false

src/librustc_trait_selection/opaque_types.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11601160

11611161
for predicate in &bounds.predicates {
11621162
if let ty::PredicateKind::Projection(projection) =
1163-
predicate.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind()
1163+
predicate.ignore_qualifiers().skip_binder().kind()
11641164
{
11651165
if projection.ty.references_error() {
11661166
// No point on adding these obligations since there's a type error involved.
@@ -1259,8 +1259,7 @@ crate fn required_region_bounds(
12591259
traits::elaborate_predicates(tcx, predicates)
12601260
.filter_map(|obligation| {
12611261
debug!("required_region_bounds(obligation={:?})", obligation);
1262-
match obligation.predicate.ignore_qualifiers_with_unbound_vars(tcx).skip_binder().kind()
1263-
{
1262+
match obligation.predicate.ignore_qualifiers().skip_binder().kind() {
12641263
ty::PredicateKind::Projection(..)
12651264
| ty::PredicateKind::Trait(..)
12661265
| ty::PredicateKind::Subtype(..)

src/librustc_trait_selection/traits/auto_trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ impl AutoTraitFinder<'tcx> {
418418
ty::PredicateKind::Trait(new_trait, _),
419419
ty::PredicateKind::Trait(old_trait, _),
420420
) = (
421-
new_pred.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind(),
422-
old_pred.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind(),
421+
new_pred.ignore_qualifiers().skip_binder().kind(),
422+
old_pred.ignore_qualifiers().skip_binder().kind(),
423423
) {
424424
if new_trait.def_id() == old_trait.def_id() {
425425
let new_substs = new_trait.trait_ref.substs;
@@ -639,7 +639,7 @@ impl AutoTraitFinder<'tcx> {
639639
// We check this by calling is_of_param on the relevant types
640640
// from the various possible predicates
641641

642-
match predicate.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind() {
642+
match predicate.ignore_qualifiers().skip_binder().kind() {
643643
&ty::PredicateKind::Trait(p, _) => {
644644
if self.is_param_no_infer(p.trait_ref.substs)
645645
&& !only_projections

src/librustc_trait_selection/traits/error_reporting/mod.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
255255
return;
256256
}
257257

258-
match obligation
259-
.predicate
260-
.ignore_qualifiers_with_unbound_vars(tcx)
261-
.skip_binder()
262-
.kind()
263-
{
258+
match obligation.predicate.ignore_qualifiers().skip_binder().kind() {
264259
ty::PredicateKind::ForAll(_) => {
265260
bug!("unexpected predicate: {:?}", obligation.predicate)
266261
}
@@ -1070,8 +1065,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10701065

10711066
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
10721067
let (cond, error) = match (
1073-
cond.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind(),
1074-
error.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind(),
1068+
cond.ignore_qualifiers().skip_binder().kind(),
1069+
error.ignore_qualifiers().skip_binder().kind(),
10751070
) {
10761071
(ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(error, _)) => {
10771072
(cond, ty::Binder::bind(error))
@@ -1083,11 +1078,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10831078
};
10841079

10851080
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
1086-
if let &ty::PredicateKind::Trait(implication, _) = obligation
1087-
.predicate
1088-
.ignore_qualifiers_with_unbound_vars(self.tcx)
1089-
.skip_binder()
1090-
.kind()
1081+
if let &ty::PredicateKind::Trait(implication, _) =
1082+
obligation.predicate.ignore_qualifiers().skip_binder().kind()
10911083
{
10921084
let error = error.to_poly_trait_ref();
10931085
let implication = ty::Binder::bind(implication).to_poly_trait_ref();
@@ -1169,7 +1161,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
11691161
// this can fail if the problem was higher-ranked, in which
11701162
// cause I have no idea for a good error message.
11711163
if let &ty::PredicateKind::Projection(data) =
1172-
predicate.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind()
1164+
predicate.ignore_qualifiers().skip_binder().kind()
11731165
{
11741166
let mut selcx = SelectionContext::new(self);
11751167
let (data, _) = self.replace_bound_vars_with_fresh_vars(
@@ -1462,11 +1454,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14621454
return;
14631455
}
14641456

1465-
let mut err = match predicate
1466-
.ignore_qualifiers_with_unbound_vars(self.tcx)
1467-
.skip_binder()
1468-
.kind()
1469-
{
1457+
let mut err = match predicate.ignore_qualifiers().skip_binder().kind() {
14701458
&ty::PredicateKind::Trait(data, _) => {
14711459
let trait_ref = ty::Binder::bind(data.trait_ref);
14721460
let self_ty = trait_ref.skip_binder().self_ty();
@@ -1720,7 +1708,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17201708
obligation: &PredicateObligation<'tcx>,
17211709
) {
17221710
let (pred, item_def_id, span) = match (
1723-
obligation.predicate.ignore_qualifiers_with_unbound_vars(self.tcx).skip_binder().kind(),
1711+
obligation.predicate.ignore_qualifiers().skip_binder().kind(),
17241712
obligation.cause.code.peel_derives(),
17251713
) {
17261714
(

0 commit comments

Comments
 (0)