1use rustc_data_structures::fx::FxIndexMap;
2use rustc_hir::def::DefKind;
3use rustc_hir::def_id::DefId;
4use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};
5use rustc_span::Span;
6use tracing::debug;
78use super::explicit::ExplicitPredicatesMap;
9use super::utils::*;
1011/// Infer predicates for the items in the crate.
12///
13/// `global_inferred_outlives`: this is initially the empty map that
14/// was generated by walking the items in the crate. This will
15/// now be filled with inferred predicates.
16pub(super) fn infer_predicates(
17 tcx: TyCtxt<'_>,
18) -> FxIndexMap<DefId, ty::EarlyBinder<'_, RequiredPredicates<'_>>> {
19{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:19",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(19u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("infer_predicates")
as &dyn Value))])
});
} else { ; }
};debug!("infer_predicates");
2021let mut explicit_map = ExplicitPredicatesMap::new();
2223let mut global_inferred_outlives = FxIndexMap::default();
2425// If new predicates were added then we need to re-calculate
26 // all crates since there could be new implied predicates.
27for i in 0.. {
28let mut predicates_added = ::alloc::vec::Vec::new()vec![];
2930// Visit all the crates and infer predicates
31for id in tcx.hir_free_items() {
32let item_did = id.owner_id;
3334{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:34",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(34u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("InferVisitor::visit_item(item={0:?})",
item_did) as &dyn Value))])
});
} else { ; }
};debug!("InferVisitor::visit_item(item={:?})", item_did);
3536let mut item_required_predicates = RequiredPredicates::default();
37match tcx.def_kind(item_did) {
38 DefKind::Union | DefKind::Enum | DefKind::Struct => {
39let adt_def = tcx.adt_def(item_did.to_def_id());
4041// Iterate over all fields in item_did
42for field_def in adt_def.all_fields() {
43// Calculating the predicate requirements necessary
44 // for item_did.
45 //
46 // For field of type &'a T (reference) or Adt
47 // (struct/enum/union) there will be outlive
48 // requirements for adt_def.
49let field_ty =
50 tcx.type_of(field_def.did).instantiate_identity().skip_norm_wip();
51let field_span = tcx.def_span(field_def.did);
52 insert_required_predicates_to_be_wf(
53 tcx,
54 field_ty,
55 field_span,
56&global_inferred_outlives,
57&mut item_required_predicates,
58&mut explicit_map,
59 );
60 }
61 }
6263 DefKind::TyAlias if tcx.type_alias_is_lazy(item_did) => {
64 insert_required_predicates_to_be_wf(
65 tcx,
66 tcx.type_of(item_did).instantiate_identity().skip_norm_wip(),
67 tcx.def_span(item_did),
68&global_inferred_outlives,
69&mut item_required_predicates,
70&mut explicit_map,
71 );
72 }
7374_ => {}
75 };
7677// If new predicates were added (`local_predicate_map` has more
78 // predicates than the `global_inferred_outlives`), the new predicates
79 // might result in implied predicates for their parent types.
80 // Therefore mark `predicates_added` as true and which will ensure
81 // we walk the crates again and re-calculate predicates for all
82 // items.
83let item_predicates_len: usize = global_inferred_outlives
84 .get(&item_did.to_def_id())
85 .map_or(0, |p| p.as_ref().skip_binder().len());
86if item_required_predicates.len() > item_predicates_len {
87 predicates_added.push(item_did);
88 global_inferred_outlives
89 .insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
90 }
91 }
9293if predicates_added.is_empty() {
94// We've reached a fixed point.
95break;
96 } else if !tcx.recursion_limit().value_within_limit(i) {
97let msg = if let &[id] = &predicates_added[..] {
98::alloc::__export::must_use({
::alloc::fmt::format(format_args!("overflow computing implied lifetime bounds for `{0}`",
tcx.def_path_str(id)))
})format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)99 } else {
100"overflow computing implied lifetime bounds".to_string()
101 };
102 tcx.dcx()
103 .struct_span_fatal(
104 predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
105 msg,
106 )
107 .emit();
108 }
109 }
110111global_inferred_outlives112}
113114fn insert_required_predicates_to_be_wf<'tcx>(
115 tcx: TyCtxt<'tcx>,
116 ty: Ty<'tcx>,
117 span: Span,
118 global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
119 required_predicates: &mut RequiredPredicates<'tcx>,
120 explicit_map: &mut ExplicitPredicatesMap<'tcx>,
121) {
122for arg in ty.walk() {
123let leaf_ty = match arg.kind() {
124 GenericArgKind::Type(ty) => ty,
125126// No predicates from lifetimes or constants, except potentially
127 // constants' types, but `walk` will get to them as well.
128GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
129 };
130131match *leaf_ty.kind() {
132 ty::Ref(region, rty, _) => {
133// The type is `&'a T` which means that we will have
134 // a predicate requirement of `T: 'a` (`T` outlives `'a`).
135 //
136 // We also want to calculate potential predicates for the `T`.
137{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:137",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(137u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Ref")
as &dyn Value))])
});
} else { ; }
};debug!("Ref");
138 insert_outlives_predicate(tcx, rty.into(), region, span, required_predicates);
139 }
140141 ty::Adt(def, args) => {
142// For ADTs (structs/enums/unions), we check inferred and explicit predicates.
143{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:143",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(143u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Adt")
as &dyn Value))])
});
} else { ; }
};debug!("Adt");
144 check_inferred_predicates(
145 tcx,
146 def.did(),
147 args,
148 global_inferred_outlives,
149 required_predicates,
150 );
151 check_explicit_predicates(
152 tcx,
153 def.did(),
154 args,
155 required_predicates,
156 explicit_map,
157None,
158 );
159 }
160161 ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
162// This corresponds to a type like `Type<'a, T>`.
163 // We check inferred and explicit predicates.
164{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:164",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(164u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Free")
as &dyn Value))])
});
} else { ; }
};debug!("Free");
165 check_inferred_predicates(
166 tcx,
167 def_id,
168 args,
169 global_inferred_outlives,
170 required_predicates,
171 );
172 check_explicit_predicates(
173 tcx,
174 def_id,
175 args,
176 required_predicates,
177 explicit_map,
178None,
179 );
180 }
181182 ty::Dynamic(obj, ..) => {
183// This corresponds to `dyn Trait<..>`. In this case, we should
184 // use the explicit predicates as well.
185{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:185",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(185u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Dynamic")
as &dyn Value))])
});
} else { ; }
};debug!("Dynamic");
186if let Some(ex_trait_ref) = obj.principal() {
187// Here, we are passing the type `usize` as a
188 // placeholder value with the function
189 // `with_self_ty`, since there is no concrete type
190 // `Self` for a `dyn Trait` at this
191 // stage. Therefore when checking explicit
192 // predicates in `check_explicit_predicates` we
193 // need to ignore checking the explicit_map for
194 // Self type.
195let args = ex_trait_ref.with_self_ty(tcx, tcx.types.usize).skip_binder().args;
196 check_explicit_predicates(
197 tcx,
198 ex_trait_ref.skip_binder().def_id,
199 args,
200 required_predicates,
201 explicit_map,
202Some(tcx.types.self_param),
203 );
204 }
205 }
206207 ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => {
208// This corresponds to a type like `<() as Trait<'a, T>>::Type`.
209 // We only use the explicit predicates of the trait but
210 // not the ones of the associated type itself.
211{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:211",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(211u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Projection")
as &dyn Value))])
});
} else { ; }
};debug!("Projection");
212 check_explicit_predicates(
213 tcx,
214 tcx.parent(def_id),
215 args,
216 required_predicates,
217 explicit_map,
218None,
219 );
220 }
221222// FIXME(inherent_associated_types): Use the explicit predicates from the parent impl.
223ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {}
224225_ => {}
226 }
227 }
228}
229230/// Check the explicit predicates declared on the type.
231///
232/// ### Example
233///
234/// ```ignore (illustrative)
235/// struct Outer<'a, T> {
236/// field: Inner<T>,
237/// }
238///
239/// struct Inner<U> where U: 'static, U: Outer {
240/// // ...
241/// }
242/// ```
243/// Here, we should fetch the explicit predicates, which
244/// will give us `U: 'static` and `U: Outer`. The latter we
245/// can ignore, but we will want to process `U: 'static`,
246/// applying the instantiation as above.
247fn check_explicit_predicates<'tcx>(
248 tcx: TyCtxt<'tcx>,
249 def_id: DefId,
250 args: &[GenericArg<'tcx>],
251 required_predicates: &mut RequiredPredicates<'tcx>,
252 explicit_map: &mut ExplicitPredicatesMap<'tcx>,
253 ignored_self_ty: Option<Ty<'tcx>>,
254) {
255{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:255",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(255u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_explicit_predicates(def_id={0:?}, args={1:?}, explicit_map={2:?}, required_predicates={3:?}, ignored_self_ty={4:?})",
def_id, args, explicit_map, required_predicates,
ignored_self_ty) as &dyn Value))])
});
} else { ; }
};debug!(
256"check_explicit_predicates(def_id={:?}, \
257 args={:?}, \
258 explicit_map={:?}, \
259 required_predicates={:?}, \
260 ignored_self_ty={:?})",
261 def_id, args, explicit_map, required_predicates, ignored_self_ty,
262 );
263let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id);
264265for (outlives_predicate, &span) in explicit_predicates.as_ref().skip_binder() {
266{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:266",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(266u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("outlives_predicate = {0:?}",
outlives_predicate) as &dyn Value))])
});
} else { ; }
};debug!("outlives_predicate = {outlives_predicate:?}");
267268// Careful: If we are inferring the effects of a `dyn Trait<..>`
269 // type, then when we look up the predicates for `Trait`,
270 // we may find some that reference `Self`. e.g., perhaps the
271 // definition of `Trait` was:
272 //
273 // ```
274 // trait Trait<'a, T> where Self: 'a { .. }
275 // ```
276 //
277 // we want to ignore such predicates here, because
278 // there is no type parameter for them to affect. Consider
279 // a struct containing `dyn Trait`:
280 //
281 // ```
282 // struct MyStruct<'x, X> { field: Box<dyn Trait<'x, X>> }
283 // ```
284 //
285 // The `where Self: 'a` predicate refers to the *existential, hidden type*
286 // that is represented by the `dyn Trait`, not to the `X` type parameter
287 // (or any other generic parameter) declared on `MyStruct`.
288 //
289 // Note that we do this check for self **before** applying `args`. In the
290 // case that `args` come from a `dyn Trait` type, our caller will have
291 // included `Self = usize` as the value for `Self`. If we were
292 // to apply the args, and not filter this predicate, we might then falsely
293 // conclude that e.g., `X: 'x` was a reasonable inferred requirement.
294 //
295 // Another similar case is where we have an inferred
296 // requirement like `<Self as Trait>::Foo: 'b`. We presently
297 // ignore such requirements as well (cc #54467)-- though
298 // conceivably it might be better if we could extract the `Foo
299 // = X` binding from the object type (there must be such a
300 // binding) and thus infer an outlives requirement that `X:
301 // 'b`.
302if let Some(self_ty) = ignored_self_ty
303 && let GenericArgKind::Type(ty) = outlives_predicate.0.kind()
304 && ty.walk().any(|arg| arg == self_ty.into())
305 {
306{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:306",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(306u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("skipping self ty = {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};debug!("skipping self ty = {ty:?}");
307continue;
308 }
309310let predicate =
311 explicit_predicates.rebind(*outlives_predicate).instantiate(tcx, args).skip_norm_wip();
312{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs:312",
"rustc_hir_analysis::outlives::implicit_infer",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs"),
::tracing_core::__macro_support::Option::Some(312u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::outlives::implicit_infer"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("predicate = {0:?}",
predicate) as &dyn Value))])
});
} else { ; }
};debug!("predicate = {predicate:?}");
313 insert_outlives_predicate(tcx, predicate.0, predicate.1, span, required_predicates);
314 }
315}
316317/// Check the inferred predicates declared on the type.
318///
319/// ### Example
320///
321/// ```ignore (illustrative)
322/// struct Outer<'a, T> {
323/// outer: Inner<'a, T>,
324/// }
325///
326/// struct Inner<'b, U> {
327/// inner: &'b U,
328/// }
329/// ```
330///
331/// Here, when processing the type of field `outer`, we would request the
332/// set of implicit predicates computed for `Inner` thus far. This will
333/// initially come back empty, but in next round we will get `U: 'b`.
334/// We then apply the instantiation `['b => 'a, U => T]` and thus get the
335/// requirement that `T: 'a` holds for `Outer`.
336fn check_inferred_predicates<'tcx>(
337 tcx: TyCtxt<'tcx>,
338 def_id: DefId,
339 args: ty::GenericArgsRef<'tcx>,
340 global_inferred_outlives: &FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
341 required_predicates: &mut RequiredPredicates<'tcx>,
342) {
343// Load the current set of inferred and explicit predicates from `global_inferred_outlives`
344 // and filter the ones that are `TypeOutlives`.
345346let Some(predicates) = global_inferred_outlives.get(&def_id) else {
347return;
348 };
349350for (&predicate, &span) in predicates.as_ref().skip_binder() {
351// `predicate` is `U: 'b` in the example above.
352 // So apply the instantiation to get `T: 'a`.
353let ty::OutlivesPredicate(arg, region) =
354 predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip();
355 insert_outlives_predicate(tcx, arg, region, span, required_predicates);
356 }
357}