rustc_infer/infer/outlives/
mod.rs1use std::iter;
4
5use rustc_data_structures::undo_log::UndoLogs;
6use rustc_middle::traits::query::OutlivesBound;
7use rustc_middle::ty;
8use tracing::instrument;
9
10use self::env::OutlivesEnvironment;
11use super::region_constraints::{RegionConstraintData, UndoLog};
12use super::{InferCtxt, RegionResolutionError};
13use crate::infer::free_regions::RegionRelations;
14use crate::infer::lexical_region_resolve;
15use crate::infer::region_constraints::ConstraintKind;
16
17pub mod env;
18pub mod obligations;
19pub mod test_type_match;
20pub(crate) mod verify;
21
22{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("explicit_outlives_bounds",
"rustc_infer::infer::outlives", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/d080e7dff1b0fc54541545252818f8cccf995d05/compiler/rustc_infer/src/infer/outlives/mod.rs"),
::tracing_core::__macro_support::Option::Some(22u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: _ = loop {};
return __tracing_attr_fake_return;
}
{
param_env.caller_bounds().into_iter().filter_map(ty::Clause::as_region_outlives_clause).filter_map(ty::Binder::no_bound_vars).map(|ty::OutlivesClause(r_a,
r_b)| OutlivesBound::RegionSubRegion(r_b, r_a))
}
}
}#[instrument(level = "debug", skip(param_env))]
23pub fn explicit_outlives_bounds<'tcx>(
24 param_env: ty::ParamEnv<'tcx>,
25) -> impl Iterator<Item = OutlivesBound<'tcx>> {
26 param_env
27 .caller_bounds()
28 .into_iter()
29 .filter_map(ty::Clause::as_region_outlives_clause)
30 .filter_map(ty::Binder::no_bound_vars)
31 .map(|ty::OutlivesClause(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a))
32}
33
34impl<'tcx> InferCtxt<'tcx> {
35 #[must_use]
43 pub fn resolve_regions_with_outlives_env(
44 &self,
45 outlives_env: &OutlivesEnvironment<'tcx>,
46 ) -> Vec<RegionResolutionError<'tcx>> {
47 self.process_registered_region_obligations(outlives_env);
48
49 let mut storage = {
50 let mut inner = self.inner.borrow_mut();
51 let inner = &mut *inner;
52 if !(self.tainted_by_errors().is_some() ||
inner.region_obligations.is_empty()) {
{
::core::panicking::panic_fmt(format_args!("region_obligations not empty: {0:#?}",
inner.region_obligations));
}
};assert!(
53 self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
54 "region_obligations not empty: {:#?}",
55 inner.region_obligations,
56 );
57 if !!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log) {
::core::panicking::panic("assertion failed: !UndoLogs::<UndoLog<\'_>>::in_snapshot(&inner.undo_log)")
};assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
58 inner.region_constraint_storage.take().expect("regions already resolved")
59 };
60
61 storage.data.constraints = storage
62 .data
63 .constraints
64 .iter()
65 .flat_map(|(constraint, origin)| {
66 constraint.iter_outlives().zip(iter::repeat_with(|| origin.clone()))
67 })
68 .collect();
69
70 if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions {
73 storage.data.constraints.retain(|(c, _)| match c.kind {
74 ConstraintKind::RegSubReg => !outlives_env
75 .higher_ranked_assumptions()
76 .contains(&ty::OutlivesClause(c.sup.into(), c.sub)),
77
78 ConstraintKind::VarSubVar
79 | ConstraintKind::RegSubVar
80 | ConstraintKind::VarSubReg => true,
81
82 ConstraintKind::VarEqVar | ConstraintKind::VarEqReg | ConstraintKind::RegEqReg => {
83 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
84 }
85 });
86 }
87
88 let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
89
90 let (lexical_region_resolutions, errors) =
91 lexical_region_resolve::resolve(region_rels, storage.var_infos, storage.data);
92
93 let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
94 if !old_value.is_none() {
::core::panicking::panic("assertion failed: old_value.is_none()")
};assert!(old_value.is_none());
95
96 errors
97 }
98
99 pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx> {
110 if !self.inner.borrow().region_obligations.is_empty() {
{
::core::panicking::panic_fmt(format_args!("region_obligations not empty: {0:#?}",
self.inner.borrow().region_obligations));
}
};assert!(
111 self.inner.borrow().region_obligations.is_empty(),
112 "region_obligations not empty: {:#?}",
113 self.inner.borrow().region_obligations
114 );
115 if !self.inner.borrow().region_assumptions.is_empty() {
{
::core::panicking::panic_fmt(format_args!("region_assumptions not empty: {0:#?}",
self.inner.borrow().region_assumptions));
}
};assert!(
116 self.inner.borrow().region_assumptions.is_empty(),
117 "region_assumptions not empty: {:#?}",
118 self.inner.borrow().region_assumptions
119 );
120
121 self.inner.borrow_mut().unwrap_region_constraints().take_and_reset_data()
122 }
123
124 pub fn with_region_constraints<R>(
126 &self,
127 op: impl FnOnce(&RegionConstraintData<'tcx>) -> R,
128 ) -> R {
129 let mut inner = self.inner.borrow_mut();
130 op(inner.unwrap_region_constraints().data())
131 }
132}