Skip to content

Commit f3aca55

Browse files
Rollup merge of #163159 - lcnr:inductive-cycles-ambig, r=oli-obk
treat inductive cycles as ambig We needed inductive cycles to be `NoSolution` for proper `ParamEnv` normalization. With #158643 this is no longer necessary, so lets make the stabilization of the new solver as small as possible. r? types
2 parents 4ae1ff3 + 622fd6a commit f3aca55

19 files changed

Lines changed: 138 additions & 89 deletions

‎compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,10 @@ where
460460
// Relating types is always unproductive. If we were to map proof trees to
461461
// corecursive functions as explained in #136824, relating types never
462462
// introduces a constructor which could cause the recursion to be guarded.
463-
GoalSource::TypeRelating => PathKind::Inductive,
463+
//
464+
// FIXME(-Znext-solver=coinductive): For now we treat all inductive cycles as
465+
// `Unknown`. See the comment in `fn initial_provisional_result`.
466+
GoalSource::TypeRelating => PathKind::Unknown,
464467
// These goal sources are likely unproductive and can be changed to
465468
// `PathKind::Inductive`. Keeping them as unknown until we're confident
466469
// about this and have an example where it is necessary.

‎compiler/rustc_next_trait_solver/src/solve/search_graph.rs‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::convert::Infallible;
22
use std::marker::PhantomData;
33

4+
use rustc_type_ir::Interner;
45
use rustc_type_ir::search_graph::{self, PathKind};
56
use rustc_type_ir::solve::{AccessedOpaques, Certainty, NoSolution, QueryResult, RerunResultExt};
6-
use rustc_type_ir::{Interner, MayBeErased, TypingMode};
77

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

‎tests/ui/assumptions_on_binders/placeholder-assumptions-issue-157840.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn foo<'a, T>()
1010
where
1111
T: Proj<'a, Assoc = fn(<T as Proj>::Assoc)>,
1212
(): Trait<<T as Proj<'a>>::Assoc>,
13-
//~^ ERROR the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
13+
//~^ ERROR overflow evaluating the requirement `(): Trait<<T as Proj<'a>>::Assoc>`
1414
{
1515
}
1616

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
error[E0277]: the trait bound `(): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not satisfied
1+
error[E0275]: overflow evaluating the requirement `(): Trait<<T as Proj<'a>>::Assoc>`
22
--> $DIR/placeholder-assumptions-issue-157840.rs:12:9
33
|
44
LL | (): Trait<<T as Proj<'a>>::Assoc>,
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>` is not implemented for `()`
6-
|
7-
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
8-
|
9-
LL | (): Trait<<T as Proj<'a>>::Assoc>, (): Trait<fn(for<'a> fn(<T as Proj<'a>>::Assoc))>
10-
| +++++++++++++++++++++++++++++++++++++++++++++++++
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116

127
error: aborting due to 1 previous error
138

14-
For more information about this error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0275`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0275]: overflow evaluating the requirement `for<'b> T: Proj<'b>`
2+
--> $DIR/find-param-recursion-issue-152716.rs:15:1
3+
|
4+
LL | / fn foo<T>()
5+
LL | |
6+
LL | | where
7+
LL | | T: for<'a> Proj<'a, Assoc = for<'b> fn(<T as Proj<'b>>::Assoc)>,
8+
LL | | (): Trait<<T as Proj<'static>>::Assoc>
9+
| |__________________________________________^
10+
|
11+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`find_param_recursion_issue_152716`)
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0275`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0275]: overflow evaluating the requirement `(): Trait<<T as Proj<'static>>::Assoc>`
2+
--> $DIR/find-param-recursion-issue-152716.rs:19:9
3+
|
4+
LL | (): Trait<<T as Proj<'static>>::Assoc>
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0275`.

‎tests/ui/traits/next-solver/find-param-recursion-issue-152716.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//@ compile-flags: -Znext-solver
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
24

35
// Regression test for <https://github.com/rust-lang/rust/issues/152716>.
46
//
@@ -11,10 +13,11 @@ trait Proj<'a> {
1113
type Assoc;
1214
}
1315
fn foo<T>()
16+
//[current]~^ ERROR: overflow evaluating the requirement `for<'b> T: Proj<'b>`
1417
where
1518
T: for<'a> Proj<'a, Assoc = for<'b> fn(<T as Proj<'b>>::Assoc)>,
1619
(): Trait<<T as Proj<'static>>::Assoc>
17-
//~^ ERROR: the trait bound `(): Trait<fn(for<'b> fn(<T as Proj<'b>>::Assoc))>` is not satisfied
20+
//[next]~^ ERROR: overflow evaluating the requirement `(): Trait<<T as Proj<'static>>::Assoc>`
1821
{
1922
}
2023

‎tests/ui/traits/next-solver/find-param-recursion-issue-152716.stderr‎

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
2+
--> $DIR/recursive-self-normalization-2.rs:16:1
3+
|
4+
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0275`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
2+
--> $DIR/recursive-self-normalization-2.rs:16:1
3+
|
4+
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0275]: overflow evaluating the requirement `<T as Foo2>::Assoc2 == _`
8+
--> $DIR/recursive-self-normalization-2.rs:16:1
9+
|
10+
LL | fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)