File: generic-type-params-name-repr.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (53 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//@ dont-require-annotations: NOTE

use std::marker;

struct A;
struct B;
struct C;
struct Foo<T = A, U = B, V = C>(marker::PhantomData<(T,U,V)>);

struct Hash<T>(marker::PhantomData<T>);
struct HashMap<K, V, H = Hash<K>>(marker::PhantomData<(K,V,H)>);

fn main() {
    // Ensure that the printed type doesn't include the default type params...
    let _: Foo<isize> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `Foo<isize>`, found `()`
    //~| NOTE expected struct `Foo<isize>`
    //~| NOTE found unit type `()`

    // ...even when they're present, but the same types as the defaults.
    let _: Foo<isize, B, C> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `Foo<isize>`, found `()`
    //~| NOTE expected struct `Foo<isize>`
    //~| NOTE found unit type `()`

    // Including cases where the default is using previous type params.
    let _: HashMap<String, isize> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `HashMap<String, isize>`, found `()`
    //~| NOTE expected struct `HashMap<String, isize>`
    //~| NOTE found unit type `()`
    let _: HashMap<String, isize, Hash<String>> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `HashMap<String, isize>`, found `()`
    //~| NOTE expected struct `HashMap<String, isize>`
    //~| NOTE found unit type `()`

    // But not when there's a different type in between.
    let _: Foo<A, isize, C> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `Foo<A, isize>`, found `()`
    //~| NOTE expected struct `Foo<A, isize>`
    //~| NOTE found unit type `()`

    // And don't print <> at all when there's just defaults.
    let _: Foo<A, B, C> = ();
    //~^ ERROR mismatched types
    //~| NOTE expected `Foo`, found `()`
    //~| NOTE expected struct `Foo`
    //~| NOTE found unit type `()`
}