1use std::fmt;
2use std::ops::Index;
34use rustc_index::{IndexSlice, IndexVec};
5use rustc_middle::mir::ConstraintCategory;
6use rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo};
7use rustc_span::Span;
8use tracing::debug;
910use crate::type_check::Locations;
1112pub(crate) mod graph;
1314/// A set of NLL region constraints. These include "outlives"
15/// constraints of the form `R1: R2`. Each constraint is identified by
16/// a unique `OutlivesConstraintIndex` and you can index into the set
17/// (`constraint_set[i]`) to access the constraint details.
18#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for OutlivesConstraintSet<'tcx> {
#[inline]
fn clone(&self) -> OutlivesConstraintSet<'tcx> {
OutlivesConstraintSet {
outlives: ::core::clone::Clone::clone(&self.outlives),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for OutlivesConstraintSet<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OutlivesConstraintSet", "outlives", &&self.outlives)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::default::Default for OutlivesConstraintSet<'tcx> {
#[inline]
fn default() -> OutlivesConstraintSet<'tcx> {
OutlivesConstraintSet {
outlives: ::core::default::Default::default(),
}
}
}Default)]
19pub(crate) struct OutlivesConstraintSet<'tcx> {
20 outlives: IndexVec<OutlivesConstraintIndex, OutlivesConstraint<'tcx>>,
21}
2223impl<'tcx> OutlivesConstraintSet<'tcx> {
24pub(crate) fn push(&mut self, constraint: OutlivesConstraint<'tcx>) {
25{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/constraints/mod.rs:25",
"rustc_borrowck::constraints", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/constraints/mod.rs"),
::tracing_core::__macro_support::Option::Some(25u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::constraints"),
::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!("OutlivesConstraintSet::push({0:?})",
constraint) as &dyn Value))])
});
} else { ; }
};debug!("OutlivesConstraintSet::push({:?})", constraint);
26if constraint.sup == constraint.sub {
27// 'a: 'a is pretty uninteresting
28return;
29 }
30self.outlives.push(constraint);
31 }
3233/// Constructs a "normal" graph from the constraint set; the graph makes it
34 /// easy to find the constraints affecting a particular region.
35 ///
36 /// N.B., this graph contains a "frozen" view of the current
37 /// constraints. Any new constraints added to the `OutlivesConstraintSet`
38 /// after the graph is built will not be present in the graph.
39pub(crate) fn graph(&self, num_region_vars: usize) -> graph::NormalConstraintGraph {
40 graph::ConstraintGraph::new(graph::Normal, self, num_region_vars)
41 }
4243/// Like `graph`, but constraints a reverse graph where `R1: R2`
44 /// represents an edge `R2 -> R1`.
45pub(crate) fn reverse_graph(&self, num_region_vars: usize) -> graph::ReverseConstraintGraph {
46 graph::ConstraintGraph::new(graph::Reverse, self, num_region_vars)
47 }
4849pub(crate) fn outlives(
50&self,
51 ) -> &IndexSlice<OutlivesConstraintIndex, OutlivesConstraint<'tcx>> {
52&self.outlives
53 }
54}
5556impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
57type Output = OutlivesConstraint<'tcx>;
5859fn index(&self, i: OutlivesConstraintIndex) -> &Self::Output {
60&self.outlives[i]
61 }
62}
6364#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for OutlivesConstraint<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for OutlivesConstraint<'tcx> {
#[inline]
fn clone(&self) -> OutlivesConstraint<'tcx> {
let _: ::core::clone::AssertParamIsClone<RegionVid>;
let _: ::core::clone::AssertParamIsClone<Locations>;
let _: ::core::clone::AssertParamIsClone<Span>;
let _: ::core::clone::AssertParamIsClone<ConstraintCategory<'tcx>>;
let _:
::core::clone::AssertParamIsClone<VarianceDiagInfo<TyCtxt<'tcx>>>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for OutlivesConstraint<'tcx> {
#[inline]
fn eq(&self, other: &OutlivesConstraint<'tcx>) -> bool {
self.from_closure == other.from_closure && self.sup == other.sup &&
self.sub == other.sub && self.locations == other.locations
&& self.span == other.span &&
self.category == other.category &&
self.variance_info == other.variance_info
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for OutlivesConstraint<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<RegionVid>;
let _: ::core::cmp::AssertParamIsEq<Locations>;
let _: ::core::cmp::AssertParamIsEq<Span>;
let _: ::core::cmp::AssertParamIsEq<ConstraintCategory<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<VarianceDiagInfo<TyCtxt<'tcx>>>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq)]
65pub struct OutlivesConstraint<'tcx> {
66// NB. The ordering here is not significant for correctness, but
67 // it is for convenience. Before we dump the constraints in the
68 // debugging logs, we sort them, and we'd like the "super region"
69 // to be first, etc. (In particular, span should remain last.)
70/// The region SUP must outlive SUB...
71pub sup: RegionVid,
7273/// Region that must be outlived.
74pub sub: RegionVid,
7576/// Where did this constraint arise?
77pub locations: Locations,
7879/// The `Span` associated with the creation of this constraint.
80 /// This should be used in preference to obtaining the span from
81 /// `locations`, since the `locations` may give a poor span
82 /// in some cases (e.g. converting a constraint from a promoted).
83pub span: Span,
8485/// What caused this constraint?
86pub category: ConstraintCategory<'tcx>,
8788/// Variance diagnostic information
89pub variance_info: VarianceDiagInfo<TyCtxt<'tcx>>,
9091/// If this constraint is promoted from closure requirements.
92pub from_closure: bool,
93}
9495impl<'tcx> fmt::Debugfor OutlivesConstraint<'tcx> {
96fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
97formatter.write_fmt(format_args!("({0:?}: {1:?}) due to {2:?} ({3:?}) ({4:?})",
self.sup, self.sub, self.locations, self.variance_info,
self.category))write!(
98formatter,
99"({:?}: {:?}) due to {:?} ({:?}) ({:?})",
100self.sup, self.sub, self.locations, self.variance_info, self.category,
101 )102 }
103}
104105impl ::std::fmt::Debug for OutlivesConstraintIndex {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("OutlivesConstraintIndex({0})",
self.as_u32()))
}
}rustc_index::newtype_index! {
106#[debug_format = "OutlivesConstraintIndex({})"]
107pub(crate) struct OutlivesConstraintIndex {}
108}109110impl ::std::fmt::Debug for ConstraintSccIndex {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
fmt.write_fmt(format_args!("ConstraintSccIndex({0})", self.as_u32()))
}
}rustc_index::newtype_index! {
111#[orderable]
112 #[debug_format = "ConstraintSccIndex({})"]
113pub struct ConstraintSccIndex {}
114}