don't eagerly normalize SelfCtor type

Delay until user annotations are registered.
See the added test.
This commit is contained in:
Ali MJ Al-Nasrawy 2022-12-26 01:03:24 +03:00
parent 030d60f1c7
commit bf228ace5c
8 changed files with 148 additions and 36 deletions

View file

@ -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() {}

View file

@ -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

View file

@ -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() {}

View file

@ -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