rustc_borrowck/constraints/
mod.rs1use std::fmt;
2use std::ops::Index;
3
4use rustc_index::{IndexSlice, IndexVec};
5use rustc_middle::mir::ConstraintCategory;
6use rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo};
7use rustc_span::Span;
8use tracing::debug;
9
10use crate::type_check::Locations;
11
12pub(crate) mod graph;
13
14#[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}
22
23impl<'tcx> OutlivesConstraintSet<'tcx> {
24 pub(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 /rustc-dev/a69a63265cfd9e006d43137f98301b8d274ad4c9/compiler/rustc_borrowck/src/constraints/mod.rs:25",
"rustc_borrowck::constraints", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/a69a63265cfd9e006d43137f98301b8d274ad4c9/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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("OutlivesConstraintSet::push({0:?})",
constraint) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("OutlivesConstraintSet::push({:?})", constraint);
26 if constraint.sup == constraint.sub {
27 return;
29 }
30 self.outlives.push(constraint);
31 }
32
33 pub(crate) fn graph(&self, num_region_vars: usize) -> graph::NormalConstraintGraph {
40 graph::ConstraintGraph::new(graph::Normal, self, num_region_vars)
41 }
42
43 pub(crate) fn reverse_graph(&self, num_region_vars: usize) -> graph::ReverseConstraintGraph {
46 graph::ConstraintGraph::new(graph::Reverse, self, num_region_vars)
47 }
48
49 pub(crate) fn outlives(
50 &self,
51 ) -> &IndexSlice<OutlivesConstraintIndex, OutlivesConstraint<'tcx>> {
52 &self.outlives
53 }
54}
55
56impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
57 type Output = OutlivesConstraint<'tcx>;
58
59 fn index(&self, i: OutlivesConstraintIndex) -> &Self::Output {
60 &self.outlives[i]
61 }
62}
63
64#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for OutlivesConstraint<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for OutlivesConstraint<'tcx> { }
#[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::marker::StructuralPartialEq for OutlivesConstraint<'tcx> {
}
#[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_fields_are_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 pub sup: RegionVid,
72
73 pub sub: RegionVid,
75
76 pub locations: Locations,
78
79 pub span: Span,
84
85 pub category: ConstraintCategory<'tcx>,
87
88 pub variance_info: VarianceDiagInfo<TyCtxt<'tcx>>,
90
91 pub from_closure: bool,
93}
94
95impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
96 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
97 formatter.write_fmt(format_args!("({0:?}: {1:?}) due to {2:?} ({3:?}) ({4:?}) (span: {5:?})",
self.sup, self.sub, self.locations, self.variance_info, self.category,
self.span))write!(
98 formatter,
99 "({:?}: {:?}) due to {:?} ({:?}) ({:?}) (span: {:?})",
100 self.sup, self.sub, self.locations, self.variance_info, self.category, self.span,
101 )
102 }
103}
104
105#[automatically_derived]
impl ::core::marker::Copy for OutlivesConstraintIndex { }
impl OutlivesConstraintIndex {
#[doc = r" Maximum value the index can take, as a `u32`."]
pub(crate) const MAX_AS_U32: u32 = 0xFFFF_FF00;
#[doc = r" Maximum value the index can take."]
pub(crate) const MAX: Self = Self::from_u32(0xFFFF_FF00);
#[doc = r" Zero value of the index."]
pub(crate) const ZERO: Self = Self::from_u32(0);
#[doc = r" Creates a new index from a given `usize`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub(crate) const fn from_usize(value: usize) -> Self {
if !(value <= (0xFFFF_FF00 as usize)) {
::core::panicking::panic("assertion failed: value <= (0xFFFF_FF00 as usize)")
};
unsafe { Self::from_u32_unchecked(value as u32) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub(crate) const fn from_u32(value: u32) -> Self {
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u16`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub(crate) const fn from_u16(value: u16) -> Self {
let value = value as u32;
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc =
r" The provided value must be less than or equal to the maximum value for the newtype."]
#[doc =
r" Providing a value outside this range is undefined due to layout restrictions."]
#[doc = r""]
#[doc = r" Prefer using `from_u32`."]
#[inline]
pub(crate) const unsafe fn from_u32_unchecked(value: u32) -> Self {
Self {
private_use_as_methods_instead: unsafe {
std::mem::transmute(value)
},
}
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub(crate) const fn index(self) -> usize { self.as_usize() }
#[doc = r" Extracts the value of this index as a `u32`."]
#[inline]
pub(crate) const fn as_u32(self) -> u32 {
unsafe { std::mem::transmute(self.private_use_as_methods_instead) }
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub(crate) const fn as_usize(self) -> usize { self.as_u32() as usize }
}
impl std::ops::Add<usize> for OutlivesConstraintIndex {
type Output = Self;
#[inline]
fn add(self, other: usize) -> Self {
Self::from_usize(self.index() + other)
}
}
impl std::ops::AddAssign<usize> for OutlivesConstraintIndex {
#[inline]
fn add_assign(&mut self, other: usize) { *self = *self + other; }
}
impl rustc_index::Idx for OutlivesConstraintIndex {
#[inline]
fn new(value: usize) -> Self { Self::from_usize(value) }
#[inline]
fn index(self) -> usize { self.as_usize() }
}
impl From<OutlivesConstraintIndex> for u32 {
#[inline]
fn from(v: OutlivesConstraintIndex) -> u32 { v.as_u32() }
}
impl From<OutlivesConstraintIndex> for usize {
#[inline]
fn from(v: OutlivesConstraintIndex) -> usize { v.as_usize() }
}
impl From<usize> for OutlivesConstraintIndex {
#[inline]
fn from(value: usize) -> Self { Self::from_usize(value) }
}
impl From<u32> for OutlivesConstraintIndex {
#[inline]
fn from(value: u32) -> Self { Self::from_u32(value) }
}
impl ::std::cmp::Eq for OutlivesConstraintIndex {}
impl ::std::cmp::PartialEq for OutlivesConstraintIndex {
fn eq(&self, other: &Self) -> bool { self.as_u32().eq(&other.as_u32()) }
}
impl ::std::marker::StructuralPartialEq for OutlivesConstraintIndex {}
impl ::std::hash::Hash for OutlivesConstraintIndex {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.as_u32().hash(state)
}
}
impl ::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({})"]
107 pub(crate) struct OutlivesConstraintIndex {}
108}
109
110#[automatically_derived]
impl ::core::marker::Copy for ConstraintSccIndex { }
impl ConstraintSccIndex {
#[doc = r" Maximum value the index can take, as a `u32`."]
pub const MAX_AS_U32: u32 = 0xFFFF_FF00;
#[doc = r" Maximum value the index can take."]
pub const MAX: Self = Self::from_u32(0xFFFF_FF00);
#[doc = r" Zero value of the index."]
pub const ZERO: Self = Self::from_u32(0);
#[doc = r" Creates a new index from a given `usize`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_usize(value: usize) -> Self {
if !(value <= (0xFFFF_FF00 as usize)) {
::core::panicking::panic("assertion failed: value <= (0xFFFF_FF00 as usize)")
};
unsafe { Self::from_u32_unchecked(value as u32) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_u32(value: u32) -> Self {
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u16`."]
#[doc = r""]
#[doc = r" # Panics"]
#[doc = r""]
#[doc = r" Will panic if `value` exceeds `MAX`."]
#[inline]
pub const fn from_u16(value: u16) -> Self {
let value = value as u32;
if !(value <= 0xFFFF_FF00) {
::core::panicking::panic("assertion failed: value <= 0xFFFF_FF00")
};
unsafe { Self::from_u32_unchecked(value) }
}
#[doc = r" Creates a new index from a given `u32`."]
#[doc = r""]
#[doc = r" # Safety"]
#[doc = r""]
#[doc =
r" The provided value must be less than or equal to the maximum value for the newtype."]
#[doc =
r" Providing a value outside this range is undefined due to layout restrictions."]
#[doc = r""]
#[doc = r" Prefer using `from_u32`."]
#[inline]
pub const unsafe fn from_u32_unchecked(value: u32) -> Self {
Self {
private_use_as_methods_instead: unsafe {
std::mem::transmute(value)
},
}
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub const fn index(self) -> usize { self.as_usize() }
#[doc = r" Extracts the value of this index as a `u32`."]
#[inline]
pub const fn as_u32(self) -> u32 {
unsafe { std::mem::transmute(self.private_use_as_methods_instead) }
}
#[doc = r" Extracts the value of this index as a `usize`."]
#[inline]
pub const fn as_usize(self) -> usize { self.as_u32() as usize }
}
impl std::ops::Add<usize> for ConstraintSccIndex {
type Output = Self;
#[inline]
fn add(self, other: usize) -> Self {
Self::from_usize(self.index() + other)
}
}
impl std::ops::AddAssign<usize> for ConstraintSccIndex {
#[inline]
fn add_assign(&mut self, other: usize) { *self = *self + other; }
}
impl rustc_index::Idx for ConstraintSccIndex {
#[inline]
fn new(value: usize) -> Self { Self::from_usize(value) }
#[inline]
fn index(self) -> usize { self.as_usize() }
}
impl ::std::iter::Step for ConstraintSccIndex {
#[inline]
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
<usize as
::std::iter::Step>::steps_between(&Self::index(*start),
&Self::index(*end))
}
#[inline]
fn forward_checked(start: Self, u: usize) -> Option<Self> {
Self::index(start).checked_add(u).map(Self::from_usize)
}
#[inline]
fn backward_checked(start: Self, u: usize) -> Option<Self> {
Self::index(start).checked_sub(u).map(Self::from_usize)
}
#[inline]
fn forward_overflowing(start: Self, u: usize) -> (Self, bool) {
let (s, o) = Self::index(start).overflowing_add(u);
(Self::from_usize(s), o)
}
#[inline]
fn backward_overflowing(start: Self, u: usize) -> (Self, bool) {
let (s, o) = Self::index(start).overflowing_sub(u);
(Self::from_usize(s), o)
}
}
impl ::std::cmp::Ord for ConstraintSccIndex {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.as_u32().cmp(&other.as_u32())
}
}
impl ::std::cmp::PartialOrd for ConstraintSccIndex {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl From<ConstraintSccIndex> for u32 {
#[inline]
fn from(v: ConstraintSccIndex) -> u32 { v.as_u32() }
}
impl From<ConstraintSccIndex> for usize {
#[inline]
fn from(v: ConstraintSccIndex) -> usize { v.as_usize() }
}
impl From<usize> for ConstraintSccIndex {
#[inline]
fn from(value: usize) -> Self { Self::from_usize(value) }
}
impl From<u32> for ConstraintSccIndex {
#[inline]
fn from(value: u32) -> Self { Self::from_u32(value) }
}
impl ::std::cmp::Eq for ConstraintSccIndex {}
impl ::std::cmp::PartialEq for ConstraintSccIndex {
fn eq(&self, other: &Self) -> bool { self.as_u32().eq(&other.as_u32()) }
}
impl ::std::marker::StructuralPartialEq for ConstraintSccIndex {}
impl ::std::hash::Hash for ConstraintSccIndex {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.as_u32().hash(state)
}
}
impl ::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({})"]
113 pub struct ConstraintSccIndex {}
114}