Skip to content

Commit 6807d37

Browse files
committed
Add some new tests with amusing diagnostics
1 parent 80c7b61 commit 6807d37

9 files changed

+91
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#![feature(type_alias_impl_trait)]
32

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

10-
fn main() {}
9+
fn main() {}

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: concrete type differs from previous defining opaque type use
2-
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:1
2+
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:5:1
33
|
44
LL | fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&'a i32`, got `&'b i32`
66
|
77
note: previous use here
8-
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:1
8+
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:5:1
99
|
1010
LL | fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl std::fmt::Debug;
4+
type Bar = impl Trait<Foo>;
5+
6+
trait Trait<T> {}
7+
8+
impl<T, U> Trait<T> for U {}
9+
10+
fn bar() -> Bar {
11+
42
12+
}
13+
14+
fn main() {
15+
println!("{:?}", bar());
16+
//~^ ERROR `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` doesn't implement `Debug`
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` doesn't implement `Debug`
2+
--> $DIR/nested.rs:15:22
3+
|
4+
LL | println!("{:?}", bar());
5+
| ^^^^^ `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
6+
|
7+
= help: the trait `Debug` is not implemented for `impl Trait<Opaque(DefId(0:4 ~ nested[14f6]::Foo::{opaque#0}), [])>`
8+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl std::fmt::Debug;
4+
type Bar = impl PartialEq<Foo>;
5+
6+
fn bar() -> Bar {
7+
42_i32 //~ ERROR can't compare `i32` with `impl Debug`
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0277]: can't compare `i32` with `impl Debug`
2+
--> $DIR/self-referential-2.rs:7:5
3+
|
4+
LL | 42_i32
5+
| ^^^^^^ no implementation for `i32 == impl Debug`
6+
|
7+
= help: the trait `PartialEq<impl Debug>` is not implemented for `i32`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
#![feature(type_alias_impl_trait)]
3+
4+
type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + std::fmt::Debug;
5+
6+
fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
7+
i
8+
}
9+
10+
fn main() {
11+
let meh = 42;
12+
let muh = 42;
13+
assert_eq!(bar(&meh), bar(&muh));
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Bar<'a, 'b> = impl PartialEq<Bar<'b, 'a>> + std::fmt::Debug;
4+
5+
fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
6+
i //~ ERROR can't compare `&i32` with `impl PartialEq<Opaque
7+
}
8+
9+
fn main() {
10+
let meh = 42;
11+
let muh = 69;
12+
assert_eq!(bar(&meh), bar(&meh));
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
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`
2+
--> $DIR/self-referential.rs:6:5
3+
|
4+
LL | i
5+
| ^ 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`
6+
|
7+
= 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`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)