Skip to content

Commit 7e43275

Browse files
committed
???????????????????????
1 parent f10b38e commit 7e43275

File tree

42 files changed

+198
-155
lines changed

Some content is hidden

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

42 files changed

+198
-155
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;
6+
use rustc_middle::ty::{self, TyCtxt};
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(param_env: ty::ParamEnv<'tcx>) -> Self {
72+
pub fn new(tcx: TyCtxt<'tcx>, 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(param_env));
80+
env.add_outlives_bounds(None, explicit_outlives_bounds(tcx, param_env));
8181

8282
env
8383
}

src/librustc_infer/infer/outlives/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ pub mod obligations;
55
pub mod verify;
66

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

1010
pub fn explicit_outlives_bounds<'tcx>(
11+
tcx: TyCtxt<'tcx>,
1112
param_env: ty::ParamEnv<'tcx>,
1213
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1314
debug!("explicit_outlives_bounds()");
1415
param_env
1516
.caller_bounds
1617
.into_iter()
17-
.filter_map(|pred| pred.ignore_qualifiers().no_bound_vars())
18+
.filter_map(move |pred| pred.ignore_qualifiers(tcx).no_bound_vars())
1819
.filter_map(|pred| match pred.kind() {
1920
ty::PredicateKind::Projection(..)
2021
| ty::PredicateKind::Trait(..)

src/librustc_infer/infer/outlives/verify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
331331
compare_ty: impl Fn(Ty<'tcx>) -> bool,
332332
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
333333
) -> impl Iterator<Item = ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
334+
let tcx = self.tcx;
334335
predicates
335-
.filter_map(|p| p.to_opt_type_outlives())
336+
.filter_map(move |p| p.to_opt_type_outlives(tcx))
336337
.filter_map(|p| p.no_bound_vars())
337338
.filter(move |p| compare_ty(p.0))
338339
}

src/librustc_infer/traits/util.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ fn predicate_obligation<'tcx>(
145145
}
146146

147147
impl Elaborator<'tcx> {
148-
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
149-
FilterToTraits::new(self)
148+
pub fn filter_to_traits(self) -> FilterToTraits<'tcx, Self> {
149+
FilterToTraits::new(self.visited.tcx, self)
150150
}
151151

152152
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
@@ -293,7 +293,7 @@ impl Iterator for Elaborator<'tcx> {
293293
// Supertrait iterator
294294
///////////////////////////////////////////////////////////////////////////
295295

296-
pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
296+
pub type Supertraits<'tcx> = FilterToTraits<'tcx, Elaborator<'tcx>>;
297297

298298
pub fn supertraits<'tcx>(
299299
tcx: TyCtxt<'tcx>,
@@ -315,22 +315,23 @@ pub fn transitive_bounds<'tcx>(
315315

316316
/// A filter around an iterator of predicates that makes it yield up
317317
/// just trait references.
318-
pub struct FilterToTraits<I> {
318+
pub struct FilterToTraits<'tcx, I> {
319+
tcx: TyCtxt<'tcx>,
319320
base_iterator: I,
320321
}
321322

322-
impl<I> FilterToTraits<I> {
323-
fn new(base: I) -> FilterToTraits<I> {
324-
FilterToTraits { base_iterator: base }
323+
impl<'tcx, I> FilterToTraits<'tcx, I> {
324+
fn new(tcx: TyCtxt<'tcx>, base: I) -> FilterToTraits<'tcx, I> {
325+
FilterToTraits { tcx, base_iterator: base }
325326
}
326327
}
327328

328-
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
329+
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<'tcx, I> {
329330
type Item = ty::PolyTraitRef<'tcx>;
330331

331332
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
332333
while let Some(obligation) = self.base_iterator.next() {
333-
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
334+
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref(self.tcx) {
334335
return Some(data);
335336
}
336337
}

src/librustc_lint/builtin.rs

Lines changed: 17 additions & 7 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().skip_binder().kind() {
1217+
let predicate_kind_name = match predicate.ignore_qualifiers(cx.tcx).skip_binder().kind() {
12181218
Trait(..) => "Trait",
12191219
TypeOutlives(..) |
12201220
RegionOutlives(..) => "Lifetime",
@@ -1499,12 +1499,13 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
14991499

15001500
impl ExplicitOutlivesRequirements {
15011501
fn lifetimes_outliving_lifetime<'tcx>(
1502+
tcx: TyCtxt<'tcx>,
15021503
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
15031504
index: u32,
15041505
) -> Vec<ty::Region<'tcx>> {
15051506
inferred_outlives
15061507
.iter()
1507-
.filter_map(|(pred, _)| match pred.ignore_qualifiers().skip_binder().kind() {
1508+
.filter_map(|(pred, _)| match pred.ignore_qualifiers(tcx).skip_binder().kind() {
15081509
&ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
15091510
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
15101511
_ => None,
@@ -1515,12 +1516,13 @@ impl ExplicitOutlivesRequirements {
15151516
}
15161517

15171518
fn lifetimes_outliving_type<'tcx>(
1519+
tcx: TyCtxt<'tcx>,
15181520
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
15191521
index: u32,
15201522
) -> Vec<ty::Region<'tcx>> {
15211523
inferred_outlives
15221524
.iter()
1523-
.filter_map(|(pred, _)| match pred.ignore_qualifiers().skip_binder().kind() {
1525+
.filter_map(|(pred, _)| match pred.ignore_qualifiers(tcx).skip_binder().kind() {
15241526
&ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
15251527
a.is_param(index).then_some(b)
15261528
}
@@ -1541,10 +1543,10 @@ impl ExplicitOutlivesRequirements {
15411543

15421544
match param.kind {
15431545
hir::GenericParamKind::Lifetime { .. } => {
1544-
Self::lifetimes_outliving_lifetime(inferred_outlives, index)
1546+
Self::lifetimes_outliving_lifetime(tcx, inferred_outlives, index)
15451547
}
15461548
hir::GenericParamKind::Type { .. } => {
1547-
Self::lifetimes_outliving_type(inferred_outlives, index)
1549+
Self::lifetimes_outliving_type(tcx, inferred_outlives, index)
15481550
}
15491551
hir::GenericParamKind::Const { .. } => Vec::new(),
15501552
}
@@ -1696,7 +1698,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
16961698
cx.tcx.named_region(predicate.lifetime.hir_id)
16971699
{
16981700
(
1699-
Self::lifetimes_outliving_lifetime(inferred_outlives, index),
1701+
Self::lifetimes_outliving_lifetime(
1702+
cx.tcx,
1703+
inferred_outlives,
1704+
index,
1705+
),
17001706
&predicate.bounds,
17011707
predicate.span,
17021708
)
@@ -1712,7 +1718,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
17121718
if let Res::Def(DefKind::TyParam, def_id) = path.res {
17131719
let index = ty_generics.param_def_id_to_index[&def_id];
17141720
(
1715-
Self::lifetimes_outliving_type(inferred_outlives, index),
1721+
Self::lifetimes_outliving_type(
1722+
cx.tcx,
1723+
inferred_outlives,
1724+
index,
1725+
),
17161726
&predicate.bounds,
17171727
predicate.span,
17181728
)

src/librustc_lint/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
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.
150150
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
151-
predicate.ignore_qualifiers().skip_binder().kind()
151+
predicate.ignore_qualifiers(cx.tcx).skip_binder().kind()
152152
{
153153
let def_id = poly_trait_predicate.trait_ref.def_id;
154154
let descr_pre =

src/librustc_middle/ty/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<'tcx> Predicate<'tcx> {
10421042
}
10431043

10441044
/// Skips `PredicateKind::ForAll`.
1045-
pub fn ignore_qualifiers(self) -> Binder<Predicate<'tcx>> {
1045+
pub fn ignore_qualifiers(self, tcx: TyCtxt<'tcx>) -> Binder<Predicate<'tcx>> {
10461046
match self.kind() {
10471047
&PredicateKind::ForAll(binder) => binder,
10481048
ty::PredicateKind::Projection(..)
@@ -1054,12 +1054,7 @@ impl<'tcx> Predicate<'tcx> {
10541054
| ty::PredicateKind::TypeOutlives(..)
10551055
| ty::PredicateKind::ConstEvaluatable(..)
10561056
| ty::PredicateKind::ConstEquate(..)
1057-
| ty::PredicateKind::RegionOutlives(..) => {
1058-
// We can't use `Binder::dummy` here, as predicates can
1059-
// contain unbound variables in rare cases, for example when
1060-
// dealing with opaque types.
1061-
Binder::bind(self)
1062-
}
1057+
| ty::PredicateKind::RegionOutlives(..) => Binder::wrap_nonbinding(tcx, self),
10631058
}
10641059
}
10651060

@@ -1434,8 +1429,8 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14341429
}
14351430

14361431
impl<'tcx> Predicate<'tcx> {
1437-
pub fn to_opt_poly_trait_ref(self) -> Option<PolyTraitRef<'tcx>> {
1438-
self.ignore_qualifiers()
1432+
pub fn to_opt_poly_trait_ref(self, tcx: TyCtxt<'tcx>) -> Option<PolyTraitRef<'tcx>> {
1433+
self.ignore_qualifiers(tcx)
14391434
.map_bound(|pred| match pred.kind() {
14401435
&PredicateKind::Trait(ref t, _) => Some(t.trait_ref),
14411436
PredicateKind::Projection(..)
@@ -1452,8 +1447,11 @@ impl<'tcx> Predicate<'tcx> {
14521447
.transpose()
14531448
}
14541449

1455-
pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
1456-
self.ignore_qualifiers()
1450+
pub fn to_opt_type_outlives(
1451+
self,
1452+
tcx: TyCtxt<'tcx>,
1453+
) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
1454+
self.ignore_qualifiers(tcx)
14571455
.map_bound(|pred| match pred.kind() {
14581456
&PredicateKind::TypeOutlives(data) => Some(data),
14591457
PredicateKind::Trait(..)

src/librustc_middle/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub trait PrettyPrinter<'tcx>:
573573
let mut is_sized = false;
574574
p!(write("impl"));
575575
for predicate in bounds.predicates {
576-
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
576+
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref(self.tcx()) {
577577
// Don't print +Sized, but rather +?Sized if absent.
578578
if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() {
579579
is_sized = true;

src/librustc_middle/ty/sty.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ impl<T> Binder<T> {
864864
Binder(value)
865865
}
866866

867+
/// Wraps `value` in a binder without actually binding any currently
868+
/// unbound variables.
869+
pub fn wrap_nonbinding(tcx: TyCtxt<'tcx>, value: T) -> Binder<T>
870+
where
871+
T: TypeFoldable<'tcx>,
872+
{
873+
if value.has_escaping_bound_vars() {
874+
Binder::bind(super::fold::shift_vars(tcx, &value, 1))
875+
} else {
876+
Binder::dummy(value)
877+
}
878+
}
879+
867880
/// Skips the binder and returns the "bound" value. This is a
868881
/// risky thing to do because it's easy to get confused about
869882
/// De Bruijn indices and the like. It is usually better to

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
598598
let mut found = false;
599599
for predicate in bounds.predicates {
600600
if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
601-
predicate.ignore_qualifiers().skip_binder().kind()
601+
predicate.ignore_qualifiers(self.infcx.tcx).skip_binder().kind()
602602
{
603603
if let ty::RegionKind::ReStatic = r {
604604
found = true;

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(param_env));
277+
self.add_outlives_bounds(outlives::explicit_outlives_bounds(self.infcx.tcx, 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
@@ -24,7 +24,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
2424
let predicates = tcx.predicates_of(current);
2525
for (predicate, _) in predicates.predicates {
2626
// TODO: forall
27-
match predicate.ignore_qualifiers().skip_binder().kind() {
27+
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
2828
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
2929
ty::PredicateKind::RegionOutlives(_)
3030
| ty::PredicateKind::TypeOutlives(_)

src/librustc_privacy/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ where
8888
let ty::GenericPredicates { parent: _, predicates } = predicates;
8989
for (predicate, _span) in predicates {
9090
// This visitor does not care about bound regions.
91-
match predicate.ignore_qualifiers().skip_binder().kind() {
91+
match predicate.ignore_qualifiers(self.def_id_visitor.tcx()).skip_binder().kind() {
9292
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
9393
if self.visit_trait(trait_ref) {
9494
return true;

src/librustc_trait_selection/opaque_types.rs

Lines changed: 2 additions & 2 deletions
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().skip_binder().kind()
1163+
predicate.ignore_qualifiers(tcx).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,7 +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().skip_binder().kind() {
1262+
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
12631263
ty::PredicateKind::Projection(..)
12641264
| ty::PredicateKind::Trait(..)
12651265
| ty::PredicateKind::Subtype(..)

src/librustc_trait_selection/traits/auto_trait.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,19 @@ impl AutoTraitFinder<'tcx> {
407407
/// under which a type implements an auto trait. A trait predicate involving
408408
/// a HRTB means that the type needs to work with any choice of lifetime,
409409
/// not just one specific lifetime (e.g., `'static`).
410-
fn add_user_pred<'c>(
410+
fn add_user_pred(
411411
&self,
412-
user_computed_preds: &mut FxHashSet<ty::Predicate<'c>>,
413-
new_pred: ty::Predicate<'c>,
412+
user_computed_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
413+
new_pred: ty::Predicate<'tcx>,
414414
) {
415415
let mut should_add_new = true;
416416
user_computed_preds.retain(|&old_pred| {
417417
if let (
418418
ty::PredicateKind::Trait(new_trait, _),
419419
ty::PredicateKind::Trait(old_trait, _),
420420
) = (
421-
new_pred.ignore_qualifiers().skip_binder().kind(),
422-
old_pred.ignore_qualifiers().skip_binder().kind(),
421+
new_pred.ignore_qualifiers(self.tcx).skip_binder().kind(),
422+
old_pred.ignore_qualifiers(self.tcx).skip_binder().kind(),
423423
) {
424424
if new_trait.def_id() == old_trait.def_id() {
425425
let new_substs = new_trait.trait_ref.substs;
@@ -640,7 +640,7 @@ impl AutoTraitFinder<'tcx> {
640640
// from the various possible predicates
641641

642642
// TODO: forall
643-
match predicate.ignore_qualifiers().skip_binder().kind() {
643+
match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
644644
&ty::PredicateKind::Trait(p, _) => {
645645
if self.is_param_no_infer(p.trait_ref.substs)
646646
&& !only_projections

0 commit comments

Comments
 (0)