Make inferred_outlives_crate return Clause
This commit is contained in:
parent
c372b14701
commit
537488efd6
9 changed files with 49 additions and 39 deletions
|
@ -33,7 +33,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
|
||||||
use rustc_middle::mir::mono::Linkage;
|
use rustc_middle::mir::mono::Linkage;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
||||||
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, IsSuggestable, Ty, TyCtxt};
|
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, IsSuggestable, ToPredicate, Ty, TyCtxt};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
|
@ -1366,12 +1366,14 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
|
||||||
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
|
"predicates_defined_on: inferred_outlives_of({:?}) = {:?}",
|
||||||
def_id, inferred_outlives,
|
def_id, inferred_outlives,
|
||||||
);
|
);
|
||||||
|
let inferred_outlives_iter =
|
||||||
|
inferred_outlives.iter().map(|(clause, span)| ((*clause).to_predicate(tcx), *span));
|
||||||
if result.predicates.is_empty() {
|
if result.predicates.is_empty() {
|
||||||
result.predicates = inferred_outlives;
|
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
|
||||||
} else {
|
} else {
|
||||||
result.predicates = tcx
|
result.predicates = tcx.arena.alloc_from_iter(
|
||||||
.arena
|
result.predicates.into_iter().copied().chain(inferred_outlives_iter),
|
||||||
.alloc_from_iter(result.predicates.iter().chain(inferred_outlives).copied());
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
|
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
*providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers };
|
*providers = Providers { inferred_outlives_of, inferred_outlives_crate, ..*providers };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate<'_>, Span)] {
|
fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Clause<'_>, Span)] {
|
||||||
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
|
let id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
|
||||||
|
|
||||||
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization()
|
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization()
|
||||||
|
@ -50,12 +50,10 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
|
||||||
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
|
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
|
||||||
let mut pred: Vec<String> = predicates
|
let mut pred: Vec<String> = predicates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(out_pred, _)| match out_pred.kind().skip_binder() {
|
.map(|(out_pred, _)| match out_pred {
|
||||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(p)) => {
|
ty::Clause::RegionOutlives(p) => p.to_string(),
|
||||||
p.to_string()
|
ty::Clause::TypeOutlives(p) => p.to_string(),
|
||||||
}
|
err => bug!("unexpected clause {:?}", err),
|
||||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(p)) => p.to_string(),
|
|
||||||
err => bug!("unexpected predicate {:?}", err),
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
pred.sort();
|
pred.sort();
|
||||||
|
@ -103,19 +101,11 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
|
||||||
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
|(ty::OutlivesPredicate(kind1, region2), &span)| {
|
||||||
match kind1.unpack() {
|
match kind1.unpack() {
|
||||||
GenericArgKind::Type(ty1) => Some((
|
GenericArgKind::Type(ty1) => Some((
|
||||||
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
|
ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)),
|
||||||
ty::OutlivesPredicate(ty1, *region2),
|
|
||||||
)))
|
|
||||||
.to_predicate(tcx),
|
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
GenericArgKind::Lifetime(region1) => Some((
|
GenericArgKind::Lifetime(region1) => Some((
|
||||||
ty::Binder::dummy(ty::PredicateKind::Clause(
|
ty::Clause::RegionOutlives(ty::OutlivesPredicate(region1, *region2)),
|
||||||
ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
|
||||||
region1, *region2,
|
|
||||||
)),
|
|
||||||
))
|
|
||||||
.to_predicate(tcx),
|
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
GenericArgKind::Const(_) => {
|
GenericArgKind::Const(_) => {
|
||||||
|
|
|
@ -2046,16 +2046,13 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
|
||||||
|
|
||||||
impl ExplicitOutlivesRequirements {
|
impl ExplicitOutlivesRequirements {
|
||||||
fn lifetimes_outliving_lifetime<'tcx>(
|
fn lifetimes_outliving_lifetime<'tcx>(
|
||||||
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
|
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
) -> Vec<ty::Region<'tcx>> {
|
) -> Vec<ty::Region<'tcx>> {
|
||||||
inferred_outlives
|
inferred_outlives
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
.filter_map(|(clause, _)| match *clause {
|
||||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
ty::Clause::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
|
||||||
a,
|
|
||||||
b,
|
|
||||||
))) => match *a {
|
|
||||||
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
|
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
@ -2065,16 +2062,15 @@ impl ExplicitOutlivesRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lifetimes_outliving_type<'tcx>(
|
fn lifetimes_outliving_type<'tcx>(
|
||||||
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
|
inferred_outlives: &'tcx [(ty::Clause<'tcx>, Span)],
|
||||||
index: u32,
|
index: u32,
|
||||||
) -> Vec<ty::Region<'tcx>> {
|
) -> Vec<ty::Region<'tcx>> {
|
||||||
inferred_outlives
|
inferred_outlives
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
.filter_map(|(clause, _)| match *clause {
|
||||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
ty::Clause::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||||
a,
|
a.is_param(index).then_some(b)
|
||||||
b,
|
}
|
||||||
))) => a.is_param(index).then_some(b),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -353,7 +353,7 @@ define_tables! {
|
||||||
explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
|
explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
|
||||||
generics_of: Table<DefIndex, LazyValue<ty::Generics>>,
|
generics_of: Table<DefIndex, LazyValue<ty::Generics>>,
|
||||||
// As an optimization, a missing entry indicates an empty `&[]`.
|
// As an optimization, a missing entry indicates an empty `&[]`.
|
||||||
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
|
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
|
||||||
super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
|
super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
|
||||||
type_of: Table<DefIndex, LazyValue<Ty<'static>>>,
|
type_of: Table<DefIndex, LazyValue<Ty<'static>>>,
|
||||||
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
|
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
|
||||||
|
|
|
@ -562,7 +562,7 @@ rustc_queries! {
|
||||||
|
|
||||||
/// Returns the inferred outlives predicates (e.g., for `struct
|
/// Returns the inferred outlives predicates (e.g., for `struct
|
||||||
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
|
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
|
||||||
query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||||
desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
|
|
|
@ -345,6 +345,14 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [(ty::Clause<'tcx>, Span)] {
|
||||||
|
fn decode(decoder: &mut D) -> &'tcx Self {
|
||||||
|
decoder.interner().arena.alloc_from_iter(
|
||||||
|
(0..decoder.read_usize()).map(|_| Decodable::decode(decoder)).collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
|
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
|
||||||
for ty::List<ty::BoundVariableKind>
|
for ty::List<ty::BoundVariableKind>
|
||||||
{
|
{
|
||||||
|
|
|
@ -734,7 +734,7 @@ pub struct CratePredicatesMap<'tcx> {
|
||||||
/// For each struct with outlive bounds, maps to a vector of the
|
/// For each struct with outlive bounds, maps to a vector of the
|
||||||
/// predicate of its outlive bounds. If an item has no outlives
|
/// predicate of its outlive bounds. If an item has no outlives
|
||||||
/// bounds, it will have no entry.
|
/// bounds, it will have no entry.
|
||||||
pub predicates: FxHashMap<DefId, &'tcx [(Predicate<'tcx>, Span)]>,
|
pub predicates: FxHashMap<DefId, &'tcx [(Clause<'tcx>, Span)]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Predicate<'tcx> {
|
impl<'tcx> Predicate<'tcx> {
|
||||||
|
@ -1167,6 +1167,13 @@ impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Clause<'tcx> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||||
|
tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_index::vec::{Idx, IndexVec};
|
||||||
use crate::middle::exported_symbols::ExportedSymbol;
|
use crate::middle::exported_symbols::ExportedSymbol;
|
||||||
use crate::mir::Body;
|
use crate::mir::Body;
|
||||||
use crate::ty::{
|
use crate::ty::{
|
||||||
self, Const, FnSig, GeneratorDiagnosticData, GenericPredicates, Predicate, TraitRef, Ty,
|
self, Clause, Const, FnSig, GeneratorDiagnosticData, GenericPredicates, Predicate, TraitRef, Ty,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ParameterizedOverTcx: 'static {
|
pub trait ParameterizedOverTcx: 'static {
|
||||||
|
@ -121,6 +121,7 @@ parameterized_over_tcx! {
|
||||||
TraitRef,
|
TraitRef,
|
||||||
Const,
|
Const,
|
||||||
Predicate,
|
Predicate,
|
||||||
|
Clause,
|
||||||
GeneratorDiagnosticData,
|
GeneratorDiagnosticData,
|
||||||
Body,
|
Body,
|
||||||
ExportedSymbol,
|
ExportedSymbol,
|
||||||
|
|
|
@ -818,6 +818,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||||
|
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
|
||||||
|
RefDecodable::decode(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [rustc_ast::InlineAsmTemplatePiece] {
|
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [rustc_ast::InlineAsmTemplatePiece] {
|
||||||
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
|
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
|
||||||
RefDecodable::decode(d)
|
RefDecodable::decode(d)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue