Skip to content

Commit

Permalink
Also test under next solver
Browse files Browse the repository at this point in the history
(cherry picked from commit 03fa9b8)
  • Loading branch information
oli-obk authored and cuviper committed Jun 14, 2024
1 parent 85ca09b commit f1dd097
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 10 deletions.
9 changes: 9 additions & 0 deletions tests/ui/impl-trait/recursive-bound-eval.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0282]: type annotations needed
--> $DIR/recursive-bound-eval.rs:20:13
|
LL | move || recursive_fn().parse()
| ^^^^^^^^^^^^^^ cannot infer type

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0282`.
6 changes: 5 additions & 1 deletion tests/ui/impl-trait/recursive-bound-eval.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Test that we can evaluate nested obligations when invoking methods on recursive calls on
//! an RPIT.

//@ check-pass
//@revisions: next current
//@[next] compile-flags: -Znext-solver

//@[current] check-pass

pub trait Parser<E> {
fn parse(&self) -> E;
Expand All @@ -15,6 +18,7 @@ impl<E, T: Fn() -> E> Parser<E> for T {

pub fn recursive_fn<E>() -> impl Parser<E> {
move || recursive_fn().parse()
//[next]~^ ERROR: type annotations needed
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
--> $DIR/issue-84660-unsoundness.rs:23:1
--> $DIR/issue-84660-unsoundness.rs:28:1
|
LL | impl<In, Out> Trait<Bar, In> for Out {
| ------------------------------------ first implementation here
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0284]: type annotations needed: cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
--> $DIR/issue-84660-unsoundness.rs:22:37
|
LL | fn convert(_i: In) -> Self::Out {
| _____________________________________^
LL | |
LL | | unreachable!();
LL | | }
| |_____^ cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`

error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
--> $DIR/issue-84660-unsoundness.rs:28:1
|
LL | impl<In, Out> Trait<Bar, In> for Out {
| ------------------------------------ first implementation here
...
LL | impl<In, Out> Trait<(), In> for Out {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0119, E0284.
For more information about an error, try `rustc --explain E0119`.
8 changes: 7 additions & 1 deletion tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Another example from issue #84660, this time weaponized as a safe transmute: an opaque type in an
// impl header being accepted was used to create unsoundness.

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

#![feature(type_alias_impl_trait)]

trait Foo {}
Expand All @@ -16,11 +20,13 @@ trait Trait<T, In> {
impl<In, Out> Trait<Bar, In> for Out {
type Out = Out;
fn convert(_i: In) -> Self::Out {
//[next]~^ ERROR: cannot satisfy `<Out as Trait<Bar, In>>::Out == ()`
unreachable!();
}
}

impl<In, Out> Trait<(), In> for Out { //~ ERROR conflicting implementations of trait `Trait<Bar, _>`
impl<In, Out> Trait<(), In> for Out {
//~^ ERROR conflicting implementations of trait `Trait<Bar, _>`
type Out = In;
fn convert(i: In) -> Self::Out {
i
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `(): Foo<FooX>` is not satisfied
--> $DIR/nested-tait-inference.rs:12:13
--> $DIR/nested-tait-inference.rs:17:13
|
LL | fn foo() -> impl Foo<FooX> {
| ^^^^^^^^^^^^^^ the trait `Foo<FooX>` is not implemented for `()`
Expand Down
13 changes: 9 additions & 4 deletions tests/ui/type-alias-impl-trait/nested-tait-inference.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#![feature(type_alias_impl_trait)]
#![allow(dead_code)]

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@[next] check-pass

use std::fmt::Debug;

type FooX = impl Debug;

trait Foo<A> { }
trait Foo<A> {}

impl Foo<()> for () { }
impl Foo<()> for () {}

fn foo() -> impl Foo<FooX> {
//~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
// FIXME(type-alias-impl-trait): We could probably make this work.
()
}

fn main() { }
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `(): Foo<FooX>` is not satisfied
--> $DIR/nested-tait-inference2.rs:13:13
--> $DIR/nested-tait-inference2.rs:17:13
|
LL | fn foo() -> impl Foo<FooX> {
| ^^^^^^^^^^^^^^ the trait `Foo<FooX>` is not implemented for `()`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0284]: type annotations needed: cannot satisfy `impl Foo<FooX> == ()`
--> $DIR/nested-tait-inference2.rs:19:5
|
LL | ()
| ^^ cannot satisfy `impl Foo<FooX> == ()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0284`.
7 changes: 6 additions & 1 deletion tests/ui/type-alias-impl-trait/nested-tait-inference2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![feature(type_alias_impl_trait)]
#![allow(dead_code)]

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

use std::fmt::Debug;

type FooX = impl Debug;
Expand All @@ -11,8 +15,9 @@ impl Foo<()> for () {}
impl Foo<u32> for () {}

fn foo() -> impl Foo<FooX> {
//~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
()
//[next]~^ ERROR: cannot satisfy `impl Foo<FooX> == ()`
}

fn main() {}

0 comments on commit f1dd097

Please sign in to comment.