Skip to content

Commit 471830b

Browse files
migrate inferred_outlives_of to Clause
1 parent 2fa796a commit 471830b

File tree

7 files changed

+21
-29
lines changed

7 files changed

+21
-29
lines changed

compiler/rustc_hir_analysis/src/outlives/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir as hir;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_middle::query::Providers;
55
use rustc_middle::ty::subst::GenericArgKind;
6-
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
6+
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
77
use rustc_span::symbol::sym;
88
use rustc_span::Span;
99

@@ -17,7 +17,7 @@ pub fn provide(providers: &mut Providers) {
1717
*providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers };
1818
}
1919

20-
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::ClauseKind<'_>, Span)] {
20+
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clause<'_>, Span)] {
2121
let id = tcx.hir().local_def_id_to_hir_id(item_def_id);
2222

2323
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst)
@@ -52,7 +52,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
5252
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
5353
let mut pred: Vec<String> = predicates
5454
.iter()
55-
.map(|(out_pred, _)| match out_pred {
55+
.map(|(out_pred, _)| match out_pred.kind().skip_binder() {
5656
ty::ClauseKind::RegionOutlives(p) => p.to_string(),
5757
ty::ClauseKind::TypeOutlives(p) => p.to_string(),
5858
err => bug!("unexpected clause {:?}", err),
@@ -104,13 +104,15 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
104104
|(ty::OutlivesPredicate(kind1, region2), &span)| {
105105
match kind1.unpack() {
106106
GenericArgKind::Type(ty1) => Some((
107-
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
107+
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2))
108+
.to_predicate(tcx),
108109
span,
109110
)),
110111
GenericArgKind::Lifetime(region1) => Some((
111112
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
112113
region1, *region2,
113-
)),
114+
))
115+
.to_predicate(tcx),
114116
span,
115117
)),
116118
GenericArgKind::Const(_) => {

compiler/rustc_lint/src/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1984,12 +1984,12 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
19841984

19851985
impl ExplicitOutlivesRequirements {
19861986
fn lifetimes_outliving_lifetime<'tcx>(
1987-
inferred_outlives: &'tcx [(ty::ClauseKind<'tcx>, Span)],
1987+
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
19881988
def_id: DefId,
19891989
) -> Vec<ty::Region<'tcx>> {
19901990
inferred_outlives
19911991
.iter()
1992-
.filter_map(|(clause, _)| match *clause {
1992+
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
19931993
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
19941994
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
19951995
_ => None,
@@ -2000,12 +2000,12 @@ impl ExplicitOutlivesRequirements {
20002000
}
20012001

20022002
fn lifetimes_outliving_type<'tcx>(
2003-
inferred_outlives: &'tcx [(ty::ClauseKind<'tcx>, Span)],
2003+
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
20042004
index: u32,
20052005
) -> Vec<ty::Region<'tcx>> {
20062006
inferred_outlives
20072007
.iter()
2008-
.filter_map(|(clause, _)| match *clause {
2008+
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
20092009
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
20102010
a.is_param(index).then_some(b)
20112011
}

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ define_tables! {
376376
attr_flags: Table<DefIndex, AttrFlags>,
377377
def_path_hashes: Table<DefIndex, DefPathHash>,
378378
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
379-
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::ClauseKind<'static>, Span)>>,
379+
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
380380
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
381381
associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
382382
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ rustc_queries! {
647647

648648
/// Returns the inferred outlives predicates (e.g., for `struct
649649
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
650-
query inferred_outlives_of(key: DefId) -> &'tcx [(ty::ClauseKind<'tcx>, Span)] {
650+
query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
651651
desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
652652
cache_on_disk_if { key.is_local() }
653653
separate_provide_extern

compiler/rustc_middle/src/query/on_disk_cache.rs

-7
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Clause<'tcx>, S
805805
}
806806
}
807807

808-
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::ClauseKind<'tcx>, Span)] {
809-
#[inline]
810-
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
811-
RefDecodable::decode(d)
812-
}
813-
}
814-
815808
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [rustc_ast::InlineAsmTemplatePiece] {
816809
#[inline]
817810
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {

compiler/rustc_middle/src/ty/codec.rs

-10
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,6 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [(ty::Claus
386386
}
387387
}
388388

389-
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
390-
for [(ty::ClauseKind<'tcx>, Span)]
391-
{
392-
fn decode(decoder: &mut D) -> &'tcx Self {
393-
decoder.interner().arena.alloc_from_iter(
394-
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
395-
)
396-
}
397-
}
398-
399389
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
400390
for ty::List<ty::BoundVariableKind>
401391
{

compiler/rustc_middle/src/ty/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ pub struct CratePredicatesMap<'tcx> {
731731
/// predicate of its outlive bounds. If an item has no outlives
732732
/// bounds, it will have no entry.
733733
// FIXME(clause): should this be a `Clause`?
734-
pub predicates: FxHashMap<DefId, &'tcx [(ClauseKind<'tcx>, Span)]>,
734+
pub predicates: FxHashMap<DefId, &'tcx [(Clause<'tcx>, Span)]>,
735735
}
736736

737737
impl<'tcx> Predicate<'tcx> {
@@ -1272,6 +1272,13 @@ impl<'tcx> ToPredicate<'tcx> for Clause<'tcx> {
12721272
}
12731273
}
12741274

1275+
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ClauseKind<'tcx> {
1276+
#[inline(always)]
1277+
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
1278+
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(self))).expect_clause()
1279+
}
1280+
}
1281+
12751282
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
12761283
#[inline(always)]
12771284
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {

0 commit comments

Comments
 (0)