summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/user-annotations/normalization-infer.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/nll/user-annotations/normalization-infer.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/nll/user-annotations/normalization-infer.rs')
-rw-r--r--tests/ui/nll/user-annotations/normalization-infer.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/ui/nll/user-annotations/normalization-infer.rs b/tests/ui/nll/user-annotations/normalization-infer.rs
new file mode 100644
index 000000000..8bfc272d4
--- /dev/null
+++ b/tests/ui/nll/user-annotations/normalization-infer.rs
@@ -0,0 +1,40 @@
+// Annnotations may contain projection types with inference variables as input.
+// Make sure we don't get ambiguities when normalizing them.
+
+// check-fail
+
+// Single impl.
+fn test1<A, B, C, D>(a: A, b: B, c: C) {
+ trait Tr { type Ty; }
+ impl<T: 'static> Tr for (T,) { type Ty = T; }
+
+ let _: <(_,) as Tr>::Ty = a; //~ ERROR type `A`
+ Some::<<(_,) as Tr>::Ty>(b); //~ ERROR type `B`
+ || -> <(_,) as Tr>::Ty { c }; //~ ERROR type `C`
+ |d: <(_,) as Tr>::Ty| -> D { d }; //~ ERROR type `D`
+}
+
+
+// Two impls. The selected impl depends on the actual type.
+fn test2<A, B, C>(a: A, b: B, c: C) {
+ trait Tr { type Ty; }
+ impl<T: 'static> Tr for (u8, T) { type Ty = T; }
+ impl<T> Tr for (i8, T) { type Ty = T; }
+ type Alias<X, Y> = (<(X, Y) as Tr>::Ty, X);
+
+ fn temp() -> String { todo!() }
+
+ // `u8` impl, requires static.
+ let _: Alias<_, _> = (a, 0u8); //~ ERROR type `A`
+ Some::<Alias<_, _>>((b, 0u8)); //~ ERROR type `B`
+ || -> Alias<_, _> { (c, 0u8) }; //~ ERROR type `C`
+
+ let _: Alias<_, _> = (&temp(), 0u8); //~ ERROR temporary value
+ Some::<Alias<_, _>>((&temp(), 0u8)); //~ ERROR temporary value
+
+ // `i8` impl, no region constraints.
+ let _: Alias<_, _> = (&temp(), 0i8);
+ Some::<Alias<_, _>>((&temp(), 0i8));
+}
+
+fn main() {}