Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::{
set_aliases_to_non_rigid,
};

#[derive_where(Clone, Debug; I: Interner)]
#[derive_where(Clone; I: Interner)]
pub struct Assumptions<I: Interner> {
pub type_outlives: Vec<Binder<I, OutlivesClause<I, I::Ty>>>,
/// Known `'a: 'b` assumptions, stored as an edge from the outliving region to the
Expand All @@ -70,6 +70,15 @@ pub struct Assumptions<I: Interner> {
pub inverse_region_outlives: TransitiveRelation<Region<I>>,
}

impl<I: Interner> std::fmt::Debug for Assumptions<I> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
f.debug_struct("Assumptions")
.field("type_outlives", &self.type_outlives)
.field("region_graph", &"elided")
.finish()
}
}

impl<I: Interner> Assumptions<I> {
pub fn empty() -> Self {
Self {
Expand Down Expand Up @@ -156,10 +165,10 @@ impl<I: Interner> Assumptions<I> {
}
}

#[derive_where(Clone, Hash, PartialEq, Eq, Debug; I: Interner, S)]
#[derive_where(Clone, Hash, PartialEq, Eq; I: Interner, S)]
#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)]
#[cfg_attr(feature = "nightly", derive(StableHash_NoContext))]
pub enum LeafRegionConstraint<I: Interner, S: Clone + std::fmt::Debug = ()> {
pub enum LeafRegionConstraint<I: Interner, S: Clone = ()> {
Ambiguity(S),
RegionOutlives(Region<I>, Region<I>, S),
/// Requirement that a (potentially higher ranked) alias outlives some (potentially higher ranked)
Expand All @@ -184,6 +193,23 @@ pub enum LeafRegionConstraint<I: Interner, S: Clone + std::fmt::Debug = ()> {
PlaceholderTyOutlives(I::Ty, Region<I>, S),
}

impl<I: Interner, S: Clone> std::fmt::Debug for LeafRegionConstraint<I, S> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
Self::Ambiguity(_span) => write!(f, "Ambiguity"),
Self::RegionOutlives(r1, r2, _span) => {
f.debug_tuple("RegionOutlives").field(r1).field(r2).finish()
}
Self::AliasTyOutlivesViaEnv(bound_outlives, _span) => {
f.debug_tuple("AliasTyOutlivesViaEnv").field(bound_outlives).finish()
}
Self::PlaceholderTyOutlives(ty, r, _span) => {
f.debug_tuple("PlaceholderTyOutlives").field(ty).field(r).finish()
}
}
}
}

impl<I: Interner> LeafRegionConstraint<I> {
pub fn with_span<S: Clone + std::fmt::Debug + Eq + std::hash::Hash>(
self,
Expand Down
10 changes: 2 additions & 8 deletions tests/ui/assumptions_on_binders/test-infra-fails-properly.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ LL | forall<'a> where 'b: 'a {
= note: expected: RegionOutlives(
'b/#0,
'c/#1,
$DIR/test-infra-fails-properly.rs:64:17: 64:23 (#0),
)
= note: actual: RegionOutlives(
'c/#1,
'static,
$DIR/test-infra-fails-properly.rs:59:9: 59:15 (#0),
)

error: bound type test binder constraint must be alias (it's a AliasTyOutlivesViaEnv)
Expand Down Expand Up @@ -110,9 +108,7 @@ LL | ambiguity
|
= note: expected: And(
[
Ambiguity(
$DIR/test-infra-fails-properly.rs:91:13: 91:22 (#0),
),
Ambiguity,
],
)
= note: actual: And(
Expand All @@ -135,9 +131,7 @@ LL | forall<'a> where 'a: 'static {
)
= note: actual: And(
[
Ambiguity(
$DIR/test-infra-fails-properly.rs:99:9: 99:15 (#0),
),
Ambiguity,
],
)

Expand Down
Loading