]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/generic-type-params-name-repr.rs
core: rename strbuf::StrBuf to string::String
[rust.git] / src / test / compile-fail / generic-type-params-name-repr.rs
1 // Copyright 2014 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 #![feature(default_type_params)]
12
13 struct A;
14 struct B;
15 struct C;
16 struct Foo<T = A, U = B, V = C>;
17
18 struct Hash<T>;
19 struct HashMap<K, V, H = Hash<K>>;
20
21 fn main() {
22     // Ensure that the printed type doesn't include the default type params...
23     let _: Foo<int> = ();
24     //~^ ERROR mismatched types: expected `Foo<int>` but found `()`
25
26     // ...even when they're present, but the same types as the defaults.
27     let _: Foo<int, B, C> = ();
28     //~^ ERROR mismatched types: expected `Foo<int>` but found `()`
29
30     // Including cases where the default is using previous type params.
31     let _: HashMap<String, int> = ();
32     //~^ ERROR mismatched types: expected `HashMap<std::string::String,int>` but found `()`
33     let _: HashMap<String, int, Hash<String>> = ();
34     //~^ ERROR mismatched types: expected `HashMap<std::string::String,int>` but found `()`
35
36     // But not when there's a different type in between.
37     let _: Foo<A, int, C> = ();
38     //~^ ERROR mismatched types: expected `Foo<A,int>` but found `()`
39
40     // And don't print <> at all when there's just defaults.
41     let _: Foo<A, B, C> = ();
42     //~^ ERROR mismatched types: expected `Foo` but found `()`
43 }