Skip to content

Commit 5336df7

Browse files
committed
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.
1 parent c946c25 commit 5336df7

File tree

2 files changed

+518
-0
lines changed

2 files changed

+518
-0
lines changed

src/test/ui/type-mismatch.rs

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Qux {}
12+
struct A;
13+
struct B;
14+
impl Qux for A {}
15+
impl Qux for B {}
16+
17+
struct Foo<T, U: Qux = A, V: Qux = B>(T, U, V);
18+
19+
struct foo;
20+
struct bar;
21+
22+
fn want<T>(t: T) {}
23+
24+
fn have_usize(f: usize) {
25+
want::<foo>(f); //~ ERROR mismatched types
26+
want::<bar>(f); //~ ERROR mismatched types
27+
want::<Foo<usize>>(f); //~ ERROR mismatched types
28+
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
29+
want::<Foo<foo>>(f); //~ ERROR mismatched types
30+
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
31+
want::<Foo<bar>>(f); //~ ERROR mismatched types
32+
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
33+
}
34+
35+
fn have_foo(f: foo) {
36+
want::<usize>(f); //~ ERROR mismatched types
37+
want::<bar>(f); //~ ERROR mismatched types
38+
want::<Foo<usize>>(f); //~ ERROR mismatched types
39+
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
40+
want::<Foo<foo>>(f); //~ ERROR mismatched types
41+
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
42+
want::<Foo<bar>>(f); //~ ERROR mismatched types
43+
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
44+
}
45+
46+
fn have_foo_foo(f: Foo<foo>) {
47+
want::<usize>(f); //~ ERROR mismatched types
48+
want::<foo>(f); //~ ERROR mismatched types
49+
want::<bar>(f); //~ ERROR mismatched types
50+
want::<Foo<usize>>(f); //~ ERROR mismatched types
51+
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
52+
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
53+
want::<Foo<bar>>(f); //~ ERROR mismatched types
54+
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
55+
want::<&Foo<foo>>(f); //~ ERROR mismatched types
56+
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
57+
}
58+
59+
fn have_foo_foo_b(f: Foo<foo, B>) {
60+
want::<usize>(f); //~ ERROR mismatched types
61+
want::<foo>(f); //~ ERROR mismatched types
62+
want::<bar>(f); //~ ERROR mismatched types
63+
want::<Foo<usize>>(f); //~ ERROR mismatched types
64+
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
65+
want::<Foo<foo>>(f); //~ ERROR mismatched types
66+
want::<Foo<bar>>(f); //~ ERROR mismatched types
67+
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
68+
want::<&Foo<foo>>(f); //~ ERROR mismatched types
69+
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
70+
}
71+
72+
fn have_foo_foo_b_a(f: Foo<foo, B, A>) {
73+
want::<usize>(f); //~ ERROR mismatched types
74+
want::<foo>(f); //~ ERROR mismatched types
75+
want::<bar>(f); //~ ERROR mismatched types
76+
want::<Foo<usize>>(f); //~ ERROR mismatched types
77+
want::<Foo<usize, B>>(f); //~ ERROR mismatched types
78+
want::<Foo<foo>>(f); //~ ERROR mismatched types
79+
want::<Foo<foo, B>>(f); //~ ERROR mismatched types
80+
want::<Foo<bar>>(f); //~ ERROR mismatched types
81+
want::<Foo<bar, B>>(f); //~ ERROR mismatched types
82+
want::<&Foo<foo>>(f); //~ ERROR mismatched types
83+
want::<&Foo<foo, B>>(f); //~ ERROR mismatched types
84+
}
85+
86+
fn main() {}

0 commit comments

Comments
 (0)