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
5 changes: 4 additions & 1 deletion compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ where
// Relating types is always unproductive. If we were to map proof trees to
// corecursive functions as explained in #136824, relating types never
// introduces a constructor which could cause the recursion to be guarded.
GoalSource::TypeRelating => PathKind::Inductive,
//
// FIXME(-Znext-solver=coinductive): For now we treat all inductive cycles as
// `Unknown`. See the comment in `fn initial_provisional_result`.
GoalSource::TypeRelating => PathKind::Unknown,
// These goal sources are likely unproductive and can be changed to
// `PathKind::Inductive`. Keeping them as unknown until we're confident
// about this and have an example where it is necessary.
Expand Down
34 changes: 13 additions & 21 deletions compiler/rustc_next_trait_solver/src/solve/search_graph.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::convert::Infallible;
use std::marker::PhantomData;

use rustc_type_ir::Interner;
use rustc_type_ir::search_graph::{self, PathKind};
use rustc_type_ir::solve::{AccessedOpaques, Certainty, NoSolution, QueryResult, RerunResultExt};
use rustc_type_ir::{Interner, MayBeErased, TypingMode};

use crate::canonical::response_no_constraints_raw;
use crate::delegate::SolverDelegate;
Expand Down Expand Up @@ -52,29 +52,21 @@ where
PathKind::Unknown | PathKind::ForcedAmbiguity => {
response_no_constraints(cx, input, Certainty::overflow(false))
}
// Even though we know these cycles to be unproductive, we still return
// overflow during coherence. This is both as we are not 100% confident in
// the implementation yet and any incorrect errors would be unsound there.
// Even though we know some cycles to be unproductive, we still treat them
// as unknown for now. This is both as we are not 100% confident in the
// implementation yet and any incorrect errors would be unsound there.
//
// The affected cases are also fairly artificial and not necessarily desirable
// so keeping this as ambiguity is fine for now.
//
// See `tests/ui/traits/next-solver/cycles/unproductive-in-coherence.rs` for an
// example where this would matter. We likely should change these cycles to `NoSolution`
// even in coherence once this is a bit more settled.
PathKind::Inductive => match input.typing_mode.0 {
TypingMode::Coherence => {
response_no_constraints(cx, input, Certainty::overflow(false))
}
TypingMode::Typeck { .. }
| TypingMode::PostTypeckUntilBorrowck { .. }
| TypingMode::Reflection
| TypingMode::PostBorrowck { .. }
| TypingMode::PostAnalysis
| TypingMode::Codegen
| TypingMode::ErasedNotCoherence(MayBeErased) => {
(Err(NoSolution), AccessedOpaques::default())
}
},
// See `tests/ui/traits/next-solver/cycles/unproductive-in-coherence.rs` and
// `tests/ui/traits/next-solver/overflow/recursive-self-normalization-simple.rs`
// for examples where this would matter.
//
// FIXME(-Znext-solver=coinductive): Long term, we probably do want to
// return `NoSolution` here. This should happen separately from the
// stabilization of the new solver.
PathKind::Inductive => unreachable!(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn foo<'a, T>()
where
T: Proj<'a, Assoc = fn(<T as Proj>::Assoc)>,
(): Trait<<T as Proj<'a>>::Assoc>,
//~^ ERROR the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
//~^ ERROR overflow evaluating the requirement `(): Trait<<T as Proj<'a>>::Assoc>`
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
error[E0277]: the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
error[E0275]: overflow evaluating the requirement `(): Trait<<T as Proj<'a>>::Assoc>`
--> $DIR/placeholder-assumptions-issue-157840.rs:12:9
|
LL | (): Trait<<T as Proj<'a>>::Assoc>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not implemented for `()`
|
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
|
LL | (): Trait<<T as Proj<'a>>::Assoc>, (): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>
| +++++++++++++++++++++++++++++++++++++++++++++++++
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0275]: overflow evaluating the requirement `for<'b> T: Proj<'b>`
--> $DIR/find-param-recursion-issue-152716.rs:15:1
|
LL | / fn foo<T>()
LL | |
LL | | where
LL | | T: for<'a> Proj<'a, Assoc = for<'b> fn(<T as Proj<'b>>::Assoc)>,
LL | | (): Trait<<T as Proj<'static>>::Assoc>
| |__________________________________________^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`find_param_recursion_issue_152716`)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `(): Trait<<T as Proj<'static>>::Assoc>`
--> $DIR/find-param-recursion-issue-152716.rs:19:9
|
LL | (): Trait<<T as Proj<'static>>::Assoc>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// Regression test for <https://github.com/rust-lang/rust/issues/152716>.
//
Expand All @@ -11,10 +13,11 @@ trait Proj<'a> {
type Assoc;
}
fn foo<T>()
//[current]~^ ERROR: overflow evaluating the requirement `for<'b> T: Proj<'b>`
where
T: for<'a> Proj<'a, Assoc = for<'b> fn(<T as Proj<'b>>::Assoc)>,
(): Trait<<T as Proj<'static>>::Assoc>
//~^ ERROR: the trait bound `(): Trait<fn(for<'b> fn(<T as Proj<'b>>::Assoc))>` is not satisfied
//[next]~^ ERROR: overflow evaluating the requirement `(): Trait<<T as Proj<'static>>::Assoc>`
{
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
--> $DIR/recursive-self-normalization-2.rs:16:1
|
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
--> $DIR/recursive-self-normalization-2.rs:16:1
|
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0275]: overflow evaluating the requirement `<T as Foo2>::Assoc2 == _`
--> $DIR/recursive-self-normalization-2.rs:16:1
|
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

trait Foo1 {
type Assoc1;
Expand All @@ -12,8 +14,9 @@ trait Bar {}
fn needs_bar<S: Bar>() {}

fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
//~^ ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
//[next]~| ERROR overflow evaluating the requirement `<T as Foo2>::Assoc2 == _`
needs_bar::<T::Assoc1>();
//~^ ERROR: the trait bound `<T as Foo1>::Assoc1: Bar` is not satisfied
}

fn main() {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _`
--> $DIR/recursive-self-normalization-simple.rs:15:1
|
LL | fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _`
--> $DIR/recursive-self-normalization-simple.rs:15:1
|
LL | fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// A variant of `recursive-self-normalization.rs` which passes if
// we treat inductive cycles as `NoSolution` in the trait solver.

trait Foo {
type Assoc;
}

trait Bar {}
fn needs_bar<S: Bar>() {}

fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
//~^ ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _`
--> $DIR/recursive-self-normalization.rs:12:1
|
LL | fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _`
--> $DIR/recursive-self-normalization.rs:12:1
|
LL | fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ compile-flags: -Znext-solver
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

trait Foo {
type Assoc;
Expand All @@ -8,8 +10,8 @@ trait Bar {}
fn needs_bar<S: Bar>() {}

fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
//~^ ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
needs_bar::<T::Assoc>();
//~^ ERROR the trait bound `<T as Foo>::Assoc: Bar` is not satisfied
}

fn main() {}

This file was deleted.

Loading