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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 28 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 25 additions & 27 deletions
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

0 commit comments

Comments
 (0)