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
44 changes: 34 additions & 10 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,42 @@ impl<'tcx> InferCtxt<'tcx> {
) {
assert!(self.tcx.assumptions_on_binders());
assert!(self.next_trait_solver());

let constraint = self.get_solver_region_constraint();
debug!(?constraint);
let constraint = region_constraint::destructure_type_outlives_constraints_in_root(
self,
constraint,
&assumptions,
);
use LeafRegionConstraint::*;

let solver_constraint = self.get_solver_region_constraint();
debug!(?solver_constraint);
let region_constraint::RootDestructuredConstraints { constraint, failing_leafs } =
region_constraint::destructure_type_outlives_constraints_in_root(
self,
solver_constraint,
&assumptions,
);
debug!(?constraint);

if constraint.is_false() {
match failing_leafs.first() {
Some(PlaceholderTyOutlives(_a, _b, span)) => {
self.dcx()
.struct_span_err(
*span,
"unable to satisfy constraints because it cannot be proven",
)
.emit();
}
Some(AliasTyOutlivesViaEnv(_, span)) => {
self.dcx()
.struct_span_err(
*span,
"unable to satisfy constraints because it cannot be proven",
)
.emit();
}
_ => {
unreachable!()
}
}
}

// FIXME(-Zassumptions-on-binders): actually implement OR as an OR
for c in constraint.and_constraint.0.into_iter().chain(
constraint
Expand All @@ -284,8 +310,6 @@ impl<'tcx> InferCtxt<'tcx> {
.into_iter()
.flat_map(|and_constraint| and_constraint.0.into_iter()),
) {
use LeafRegionConstraint::*;

match c {
Ambiguity(span) => {
self.dcx()
Expand Down
53 changes: 35 additions & 18 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,12 @@ fn pull_region_outlives_constraints_out_of_universe<
RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint))
}

#[derive_where(Debug; I: Interner, S)]
pub struct RootDestructuredConstraints<I: Interner, S: Clone + std::fmt::Debug> {
pub constraint: RegionConstraint<I, S>,
pub failing_leafs: Vec<LeafRegionConstraint<I, S>>,
}

/// Converts type outlives constraints into region outlives constraints. This assumes the *complete* set of
/// assumptions are known. This should not be called until the end of type checking.
///
Expand All @@ -848,33 +854,41 @@ pub fn destructure_type_outlives_constraints_in_root<
infcx: &Infcx,
constraint: RegionConstraint<I, S>,
assumptions: &Assumptions<I>,
) -> RegionConstraint<I, S> {
) -> RootDestructuredConstraints<I, S> {
use LeafRegionConstraint::*;

let destructure_and = |and: &And<I, S>| {
let mut failing_leafs: Vec<LeafRegionConstraint<I, S>> = vec![];
let mut destructure_and = |and: &And<I, S>| {
debug!("rewriting and: {:?}", and);
let mut destructured_constraints = Vec::new();
for c in &and.0 {
match c {
Ambiguity(_) | RegionOutlives(..) => {
destructured_constraints.push(Or::new_leaf(c.clone()))
}
PlaceholderTyOutlives(ty, r, span) => destructured_constraints.push(Or::new(
regions_outlived_by_placeholder(*ty, assumptions, infcx.cx()).map(
move |assumption_r| {
And::new([RegionOutlives(assumption_r, *r, span.clone())])
},
),
)),
PlaceholderTyOutlives(ty, r, span) => {
let contents =
Or::new(regions_outlived_by_placeholder(*ty, assumptions, infcx.cx()).map(
move |assumption_r| {
And::new([RegionOutlives(assumption_r, *r, span.clone())])
},
));
if contents.is_false() {
failing_leafs.push(c.clone());
}
destructured_constraints.push(contents)
}
AliasTyOutlivesViaEnv(bound_outlives, span) => {
destructured_constraints.push(
alias_outlives_candidates_from_assumptions(
infcx,
*bound_outlives,
assumptions,
)
.with_spans(span.clone()),
);
let content = alias_outlives_candidates_from_assumptions(
infcx,
*bound_outlives,
assumptions,
)
.with_spans(span.clone());
if content.is_false() {
failing_leafs.push(c.clone());
}
destructured_constraints.push(content);
}
}
}
Expand All @@ -893,7 +907,10 @@ pub fn destructure_type_outlives_constraints_in_root<
.into_iter()
.fold(Or::new_false(), |acc, c| Or::build_or(acc, destructure_and(&c)));

RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint))
RootDestructuredConstraints {
constraint: RegionConstraint::new_from_or(Or::build_and(and_constraint, or_constraint)),
failing_leafs,
}
}

/// Converts type outlives constraints into either region outlives constraints, or type outlives
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/assumptions_on_binders/region_outlives_to_false.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ compile-flags: -Zassumptions-on-binders -Znext-solver=globally

#![feature(generic_const_items)]

const FAIL<'a, T>: &'a T = todo!();
//~^ ERROR: unable to satisfy constraints because it cannot be proven
fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: unable to satisfy constraints because it cannot be proven
--> $DIR/region_outlives_to_false.rs:5:20
|
LL | const FAIL<'a, T>: &'a T = todo!();
| ^^^^^

error: aborting due to 1 previous error

3 changes: 2 additions & 1 deletion tests/ui/assumptions_on_binders/test-infra-works.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ check-pass
//@ compile-flags: -Zassumptions-on-binders -Znext-solver=globally

#![feature(test_binder_constraints, non_lifetime_binders)]
Expand Down Expand Up @@ -53,6 +52,7 @@ trait Trait {
core::test_binder_constraints! {
impl<T: Trait> {
forall<'a> {
//~^ ERROR: unable to satisfy constraints because it cannot be proven
for<> T::Assoc: 'a
} expect {
or {
Expand All @@ -71,6 +71,7 @@ core::test_binder_constraints! {
core::test_binder_constraints! {
impl<T: Trait> {
forall<'a> {
//~^ ERROR: unable to satisfy constraints because it cannot be proven
predicates T::Assoc: 'a
} expect {
or {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/assumptions_on_binders/test-infra-works.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unable to satisfy constraints because it cannot be proven
--> $DIR/test-infra-works.rs:54:9
|
LL | forall<'a> {
| ^^^^^^

error: unable to satisfy constraints because it cannot be proven
--> $DIR/test-infra-works.rs:73:9
|
LL | forall<'a> {
| ^^^^^^

error: aborting due to 2 previous errors

Loading