Add UI tests for diagnostics comparing types

They highlight how types are displayed in those cases, and will show
how the current output is altered by the next patch.
This commit is contained in:
Mike Hommey 2018-07-11 16:26:15 +09:00
parent c946c2539e
commit 5336df7e3c
2 changed files with 518 additions and 0 deletions

View File

@ -0,0 +1,86 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Qux {}
struct A;
struct B;
impl Qux for A {}
impl Qux for B {}
struct Foo<T, U: Qux = A, V: Qux = B>(T, U, V);
struct foo;
struct bar;
fn want<T>(t: T) {}
fn have_usize(f: usize) {
want::<foo>(f); //~ ERROR mismatched types
want::<bar>(f); //~ ERROR mismatched types
want::<Foo<usize>>(f); //~ ERROR mismatched types
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
want::<Foo<foo>>(f); //~ ERROR mismatched types
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
want::<Foo<bar>>(f); //~ ERROR mismatched types
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
}
fn have_foo(f: foo) {
want::<usize>(f); //~ ERROR mismatched types
want::<bar>(f); //~ ERROR mismatched types
want::<Foo<usize>>(f); //~ ERROR mismatched types
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
want::<Foo<foo>>(f); //~ ERROR mismatched types
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
want::<Foo<bar>>(f); //~ ERROR mismatched types
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
}
fn have_foo_foo(f: Foo<foo>) {
want::<usize>(f); //~ ERROR mismatched types
want::<foo>(f); //~ ERROR mismatched types
want::<bar>(f); //~ ERROR mismatched types
want::<Foo<usize>>(f); //~ ERROR mismatched types
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
want::<Foo<bar>>(f); //~ ERROR mismatched types
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
want::<&Foo<foo>>(f); //~ ERROR mismatched types
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
}
fn have_foo_foo_b(f: Foo<foo, B>) {
want::<usize>(f); //~ ERROR mismatched types
want::<foo>(f); //~ ERROR mismatched types
want::<bar>(f); //~ ERROR mismatched types
want::<Foo<usize>>(f); //~ ERROR mismatched types
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
want::<Foo<foo>>(f); //~ ERROR mismatched types
want::<Foo<bar>>(f); //~ ERROR mismatched types
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
want::<&Foo<foo>>(f); //~ ERROR mismatched types
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
}
fn have_foo_foo_b_a(f: Foo<foo, B, A>) {
want::<usize>(f); //~ ERROR mismatched types
want::<foo>(f); //~ ERROR mismatched types
want::<bar>(f); //~ ERROR mismatched types
want::<Foo<usize>>(f); //~ ERROR mismatched types
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
want::<Foo<foo>>(f); //~ ERROR mismatched types
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
want::<Foo<bar>>(f); //~ ERROR mismatched types
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
want::<&Foo<foo>>(f); //~ ERROR mismatched types
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
}
fn main() {}

View File

@ -0,0 +1,432 @@
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:25:17
|
LL | want::<foo>(f); //~ ERROR mismatched types
| ^ expected struct `foo`, found usize
|
= note: expected type `foo`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:26:17
|
LL | want::<bar>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found usize
|
= note: expected type `bar`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:27:24
|
LL | want::<Foo<usize>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<usize>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:28:27
|
LL | want::<Foo<usize, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<usize, B>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:29:22
|
LL | want::<Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<foo>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:30:25
|
LL | want::<Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<foo, B>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:31:22
|
LL | want::<Foo<bar>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<bar>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:32:25
|
LL | want::<Foo<bar, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found usize
|
= note: expected type `Foo<bar, B>`
found type `usize`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:36:19
|
LL | want::<usize>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `usize`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:37:17
|
LL | want::<bar>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `bar`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:38:24
|
LL | want::<Foo<usize>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<usize>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:39:27
|
LL | want::<Foo<usize, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<usize, B>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:40:22
|
LL | want::<Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<foo, A, B>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:41:25
|
LL | want::<Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<foo, B, B>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:42:22
|
LL | want::<Foo<bar>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<bar>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:43:25
|
LL | want::<Foo<bar, B>>(f); //~ ERROR mismatched types
| ^ expected struct `Foo`, found struct `foo`
|
= note: expected type `Foo<bar, B>`
found type `foo`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:47:19
|
LL | want::<usize>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `Foo`
|
= note: expected type `usize`
found type `Foo<foo>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:48:17
|
LL | want::<foo>(f); //~ ERROR mismatched types
| ^ expected struct `foo`, found struct `Foo`
|
= note: expected type `foo`
found type `Foo<foo, A, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:49:17
|
LL | want::<bar>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `Foo`
|
= note: expected type `bar`
found type `Foo<foo>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:50:24
|
LL | want::<Foo<usize>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, _, _>`
found type `Foo<foo, _, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:51:27
|
LL | want::<Foo<usize, B>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, B, _>`
found type `Foo<foo, A, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:52:25
|
LL | want::<Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected struct `B`, found struct `A`
|
= note: expected type `Foo<_, B, _>`
found type `Foo<_, A, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:53:22
|
LL | want::<Foo<bar>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, _, _>`
found type `Foo<foo, _, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:54:25
|
LL | want::<Foo<bar, B>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, B, _>`
found type `Foo<foo, A, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:55:23
|
LL | want::<&Foo<foo>>(f); //~ ERROR mismatched types
| ^
| |
| expected &Foo<foo>, found struct `Foo`
| help: consider borrowing here: `&f`
|
= note: expected type `&Foo<foo>`
found type `Foo<foo>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:56:26
|
LL | want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected reference, found struct `Foo`
|
= note: expected type `&Foo<foo, B>`
found type `Foo<foo>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:60:19
|
LL | want::<usize>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `Foo`
|
= note: expected type `usize`
found type `Foo<foo, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:61:17
|
LL | want::<foo>(f); //~ ERROR mismatched types
| ^ expected struct `foo`, found struct `Foo`
|
= note: expected type `foo`
found type `Foo<foo, B, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:62:17
|
LL | want::<bar>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `Foo`
|
= note: expected type `bar`
found type `Foo<foo, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:63:24
|
LL | want::<Foo<usize>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, A, _>`
found type `Foo<foo, B, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:64:27
|
LL | want::<Foo<usize, B>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, _, _>`
found type `Foo<foo, _, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:65:22
|
LL | want::<Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected struct `A`, found struct `B`
|
= note: expected type `Foo<_, A, _>`
found type `Foo<_, B, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:66:22
|
LL | want::<Foo<bar>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, A, _>`
found type `Foo<foo, B, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:67:25
|
LL | want::<Foo<bar, B>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, _, _>`
found type `Foo<foo, _, _>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:68:23
|
LL | want::<&Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected &Foo<foo>, found struct `Foo`
|
= note: expected type `&Foo<foo>`
found type `Foo<foo, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:69:26
|
LL | want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
| ^
| |
| expected reference, found struct `Foo`
| help: consider borrowing here: `&f`
|
= note: expected type `&Foo<foo, B>`
found type `Foo<foo, B>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:73:19
|
LL | want::<usize>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `Foo`
|
= note: expected type `usize`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:74:17
|
LL | want::<foo>(f); //~ ERROR mismatched types
| ^ expected struct `foo`, found struct `Foo`
|
= note: expected type `foo`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:75:17
|
LL | want::<bar>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `Foo`
|
= note: expected type `bar`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:76:24
|
LL | want::<Foo<usize>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, A, B>`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:77:27
|
LL | want::<Foo<usize, B>>(f); //~ ERROR mismatched types
| ^ expected usize, found struct `foo`
|
= note: expected type `Foo<usize, _, B>`
found type `Foo<foo, _, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:78:22
|
LL | want::<Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected struct `A`, found struct `B`
|
= note: expected type `Foo<_, A, B>`
found type `Foo<_, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:79:25
|
LL | want::<Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected struct `B`, found struct `A`
|
= note: expected type `Foo<_, _, B>`
found type `Foo<_, _, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:80:22
|
LL | want::<Foo<bar>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, A, B>`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:81:25
|
LL | want::<Foo<bar, B>>(f); //~ ERROR mismatched types
| ^ expected struct `bar`, found struct `foo`
|
= note: expected type `Foo<bar, _, B>`
found type `Foo<foo, _, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:82:23
|
LL | want::<&Foo<foo>>(f); //~ ERROR mismatched types
| ^ expected &Foo<foo>, found struct `Foo`
|
= note: expected type `&Foo<foo>`
found type `Foo<foo, B, A>`
error[E0308]: mismatched types
--> $DIR/type-mismatch.rs:83:26
|
LL | want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
| ^ expected reference, found struct `Foo`
|
= note: expected type `&Foo<foo, B>`
found type `Foo<foo, B, A>`
error: aborting due to 47 previous errors
For more information about this error, try `rustc --explain E0308`.