about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2022-12-26 01:03:24 +0300
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-01-07 13:42:16 +0300
commitbf228ace5cf6824078d6d36144ad8a65f07fa8d3 (patch)
tree94b4721d3a1b4ff0150ffb8d2129109916583e87 /src/test
parent030d60f1c729c01ef9ea11a1adb153c7c58e5fe2 (diff)
downloadrust-bf228ace5cf6824078d6d36144ad8a65f07fa8d3.tar.gz
rust-bf228ace5cf6824078d6d36144ad8a65f07fa8d3.zip
don't eagerly normalize SelfCtor type
Delay until user annotations are registered.
See the added test.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/nll/user-annotations/normalization-default.rs22
-rw-r--r--src/test/ui/nll/user-annotations/normalization-default.stderr36
-rw-r--r--src/test/ui/nll/user-annotations/normalization-self.rs26
-rw-r--r--src/test/ui/nll/user-annotations/normalization-self.stderr36
4 files changed, 120 insertions, 0 deletions
diff --git a/src/test/ui/nll/user-annotations/normalization-default.rs b/src/test/ui/nll/user-annotations/normalization-default.rs
new file mode 100644
index 00000000000..fa52e6d857f
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/normalization-default.rs
@@ -0,0 +1,22 @@
+// check-fail
+
+trait Trait { type Assoc; }
+impl<'a> Trait for &'a () { type Assoc = &'a (); }
+
+struct MyTuple<T, U = <&'static () as Trait>::Assoc>(T, U);
+fn test_tuple(x: &(), y: &()) {
+    MyTuple::<_>((), x);
+    //~^ ERROR
+    let _: MyTuple::<_> = MyTuple((), y);
+    //~^ ERROR
+}
+
+struct MyStruct<T, U = <&'static () as Trait>::Assoc> { val: (T, U), }
+fn test_struct(x: &(), y: &()) {
+    MyStruct::<_> { val: ((), x) };
+    //~^ ERROR
+    let _: MyStruct::<_> = MyStruct { val: ((), y) };
+    //~^ ERROR
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/user-annotations/normalization-default.stderr b/src/test/ui/nll/user-annotations/normalization-default.stderr
new file mode 100644
index 00000000000..6c73ac69254
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/normalization-default.stderr
@@ -0,0 +1,36 @@
+error: lifetime may not live long enough
+  --> $DIR/normalization-default.rs:8:22
+   |
+LL | fn test_tuple(x: &(), y: &()) {
+   |                  - let's call the lifetime of this reference `'1`
+LL |     MyTuple::<_>((), x);
+   |                      ^ this usage requires that `'1` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-default.rs:10:12
+   |
+LL | fn test_tuple(x: &(), y: &()) {
+   |                          - let's call the lifetime of this reference `'2`
+...
+LL |     let _: MyTuple::<_> = MyTuple((), y);
+   |            ^^^^^^^^^^^^ type annotation requires that `'2` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-default.rs:16:26
+   |
+LL | fn test_struct(x: &(), y: &()) {
+   |                   - let's call the lifetime of this reference `'1`
+LL |     MyStruct::<_> { val: ((), x) };
+   |                          ^^^^^^^ this usage requires that `'1` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-default.rs:18:12
+   |
+LL | fn test_struct(x: &(), y: &()) {
+   |                           - let's call the lifetime of this reference `'2`
+...
+LL |     let _: MyStruct::<_> = MyStruct { val: ((), y) };
+   |            ^^^^^^^^^^^^^ type annotation requires that `'2` must outlive `'static`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/nll/user-annotations/normalization-self.rs b/src/test/ui/nll/user-annotations/normalization-self.rs
new file mode 100644
index 00000000000..c18760b53cf
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/normalization-self.rs
@@ -0,0 +1,26 @@
+// check-fail
+
+trait Trait { type Assoc; }
+impl<'a> Trait for &'a () { type Assoc = &'a (); }
+
+struct MyTuple<T>(T);
+impl MyTuple<<&'static () as Trait>::Assoc> {
+    fn test(x: &(), y: &()) {
+        Self(x);
+        //~^ ERROR
+        let _: Self = MyTuple(y);
+        //~^ ERROR
+    }
+}
+
+struct MyStruct<T> { val: T, }
+impl MyStruct<<&'static () as Trait>::Assoc> {
+    fn test(x: &(), y: &()) {
+        Self { val: x };
+        //~^ ERROR
+        let _: Self = MyStruct { val: y };
+        //~^ ERROR
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/user-annotations/normalization-self.stderr b/src/test/ui/nll/user-annotations/normalization-self.stderr
new file mode 100644
index 00000000000..e231ed03c2e
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/normalization-self.stderr
@@ -0,0 +1,36 @@
+error: lifetime may not live long enough
+  --> $DIR/normalization-self.rs:9:14
+   |
+LL |     fn test(x: &(), y: &()) {
+   |                - let's call the lifetime of this reference `'1`
+LL |         Self(x);
+   |              ^ this usage requires that `'1` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-self.rs:11:16
+   |
+LL |     fn test(x: &(), y: &()) {
+   |                        - let's call the lifetime of this reference `'2`
+...
+LL |         let _: Self = MyTuple(y);
+   |                ^^^^ type annotation requires that `'2` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-self.rs:19:21
+   |
+LL |     fn test(x: &(), y: &()) {
+   |                - let's call the lifetime of this reference `'1`
+LL |         Self { val: x };
+   |                     ^ this usage requires that `'1` must outlive `'static`
+
+error: lifetime may not live long enough
+  --> $DIR/normalization-self.rs:21:16
+   |
+LL |     fn test(x: &(), y: &()) {
+   |                        - let's call the lifetime of this reference `'2`
+...
+LL |         let _: Self = MyStruct { val: y };
+   |                ^^^^ type annotation requires that `'2` must outlive `'static`
+
+error: aborting due to 4 previous errors
+