summaryrefslogtreecommitdiffstats
path: root/tests/ui/generics/generic-type-params-name-repr.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/ui/generics/generic-type-params-name-repr.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/generics/generic-type-params-name-repr.rs')
-rw-r--r--tests/ui/generics/generic-type-params-name-repr.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/ui/generics/generic-type-params-name-repr.rs b/tests/ui/generics/generic-type-params-name-repr.rs
new file mode 100644
index 000000000..6e0beec66
--- /dev/null
+++ b/tests/ui/generics/generic-type-params-name-repr.rs
@@ -0,0 +1,51 @@
+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
+ //~| expected struct `Foo`, found `()`
+ //~| expected struct `Foo<isize>`
+ //~| found unit type `()`
+
+ // ...even when they're present, but the same types as the defaults.
+ let _: Foo<isize, B, C> = ();
+ //~^ ERROR mismatched types
+ //~| expected struct `Foo`, found `()`
+ //~| expected struct `Foo<isize>`
+ //~| found unit type `()`
+
+ // Including cases where the default is using previous type params.
+ let _: HashMap<String, isize> = ();
+ //~^ ERROR mismatched types
+ //~| expected struct `HashMap`, found `()`
+ //~| expected struct `HashMap<String, isize>`
+ //~| found unit type `()`
+ let _: HashMap<String, isize, Hash<String>> = ();
+ //~^ ERROR mismatched types
+ //~| expected struct `HashMap`, found `()`
+ //~| expected struct `HashMap<String, isize>`
+ //~| found unit type `()`
+
+ // But not when there's a different type in between.
+ let _: Foo<A, isize, C> = ();
+ //~^ ERROR mismatched types
+ //~| expected struct `Foo`, found `()`
+ //~| expected struct `Foo<A, isize>`
+ //~| found unit type `()`
+
+ // And don't print <> at all when there's just defaults.
+ let _: Foo<A, B, C> = ();
+ //~^ ERROR mismatched types
+ //~| expected struct `Foo`, found `()`
+ //~| expected struct `Foo`
+ //~| found unit type `()`
+}