Skip to content

Commit

Permalink
Add some new tests with amusing diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 3, 2022
1 parent 80c7b61 commit 6807d37
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 4 deletions.
@@ -1,4 +1,3 @@

#![feature(type_alias_impl_trait)]

type Foo<'a, 'b> = impl std::fmt::Debug;
Expand All @@ -7,4 +6,4 @@ fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
(i, i) //~^ ERROR concrete type differs from previous
}

fn main() {}
fn main() {}
@@ -1,11 +1,11 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:1
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:5:1
|
LL | fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&'a i32`, got `&'b i32`
|
note: previous use here
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:1
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:5:1
|
LL | fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/type-alias-impl-trait/nested.rs
@@ -0,0 +1,17 @@
#![feature(type_alias_impl_trait)]

type Foo = impl std::fmt::Debug;
type Bar = impl Trait<Foo>;

trait Trait<T> {}

impl<T, U> Trait<T> for U {}

fn bar() -> Bar {
42
}

fn main() {
println!("{:?}", bar());
//~^ ERROR `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` doesn't implement `Debug`
}
12 changes: 12 additions & 0 deletions src/test/ui/type-alias-impl-trait/nested.stderr
@@ -0,0 +1,12 @@
error[E0277]: `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` doesn't implement `Debug`
--> $DIR/nested.rs:15:22
|
LL | println!("{:?}", bar());
| ^^^^^ `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>`
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
10 changes: 10 additions & 0 deletions src/test/ui/type-alias-impl-trait/self-referential-2.rs
@@ -0,0 +1,10 @@
#![feature(type_alias_impl_trait)]

type Foo = impl std::fmt::Debug;
type Bar = impl PartialEq<Foo>;

fn bar() -> Bar {
42_i32 //~ ERROR can't compare `i32` with `impl Debug`
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/type-alias-impl-trait/self-referential-2.stderr
@@ -0,0 +1,11 @@
error[E0277]: can't compare `i32` with `impl Debug`
--> $DIR/self-referential-2.rs:7:5
|
LL | 42_i32
| ^^^^^^ no implementation for `i32 == impl Debug`
|
= help: the trait `PartialEq<impl Debug>` is not implemented for `i32`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
14 changes: 14 additions & 0 deletions src/test/ui/type-alias-impl-trait/self-referential-3.rs
@@ -0,0 +1,14 @@
// run-pass
#![feature(type_alias_impl_trait)]

type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + std::fmt::Debug;

fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
i
}

fn main() {
let meh = 42;
let muh = 42;
assert_eq!(bar(&meh), bar(&muh));
}
13 changes: 13 additions & 0 deletions src/test/ui/type-alias-impl-trait/self-referential.rs
@@ -0,0 +1,13 @@
#![feature(type_alias_impl_trait)]

type Bar<'a, 'b> = impl PartialEq<Bar<'b, 'a>> + std::fmt::Debug;

fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
i //~ ERROR can't compare `&i32` with `impl PartialEq<Opaque
}

fn main() {
let meh = 42;
let muh = 69;
assert_eq!(bar(&meh), bar(&meh));
}
11 changes: 11 additions & 0 deletions src/test/ui/type-alias-impl-trait/self-referential.stderr
@@ -0,0 +1,11 @@
error[E0277]: can't compare `&i32` with `impl PartialEq<Opaque(DefId(0:6 ~ self_referential[5b7d]::Bar::{opaque#0}), [ReFree(DefId(0:7 ~ self_referential[5b7d]::bar), BrNamed(DefId(0:8 ~ self_referential[5b7d]::bar::'a), 'a)), ReEarlyBound(0, 'b)])> + Debug`
--> $DIR/self-referential.rs:6:5
|
LL | i
| ^ no implementation for `&i32 == impl PartialEq<Opaque(DefId(0:6 ~ self_referential[5b7d]::Bar::{opaque#0}), [ReFree(DefId(0:7 ~ self_referential[5b7d]::bar), BrNamed(DefId(0:8 ~ self_referential[5b7d]::bar::'a), 'a)), ReEarlyBound(0, 'b)])> + Debug`
|
= help: the trait `PartialEq<impl PartialEq<Opaque(DefId(0:6 ~ self_referential[5b7d]::Bar::{opaque#0}), [ReFree(DefId(0:7 ~ self_referential[5b7d]::bar), BrNamed(DefId(0:8 ~ self_referential[5b7d]::bar::'a), 'a)), ReEarlyBound(0, 'b)])> + Debug>` is not implemented for `&i32`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 6807d37

Please sign in to comment.