about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-16 12:47:49 +0000
committerbors <bors@rust-lang.org>2022-12-16 12:47:49 +0000
commit03770f0e2b60c02db8fcf52fed5fb36aac70cedc (patch)
treefa8e7aea22d80f0b44cd5d982b6d3418a2ccb787 /src
parent01ef4b21dc5251b58bd9c6fd6face2ae95d56da1 (diff)
parentff41359e6535ca7dc1261f282b1601136fedee21 (diff)
downloadrust-03770f0e2b60c02db8fcf52fed5fb36aac70cedc.tar.gz
rust-03770f0e2b60c02db8fcf52fed5fb36aac70cedc.zip
Auto merge of #103880 - b-naber:field-ty-mir, r=lcnr
Use non-ascribed type as field's type in mir

Fixes https://github.com/rust-lang/rust/issues/96514

r? `@lcnr`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/mir/field-projection-invariant.rs24
-rw-r--r--src/test/ui/mir/field-ty-ascription-enums.rs15
-rw-r--r--src/test/ui/mir/field-ty-ascription.rs37
3 files changed, 76 insertions, 0 deletions
diff --git a/src/test/ui/mir/field-projection-invariant.rs b/src/test/ui/mir/field-projection-invariant.rs
new file mode 100644
index 00000000000..b5d6add043c
--- /dev/null
+++ b/src/test/ui/mir/field-projection-invariant.rs
@@ -0,0 +1,24 @@
+// build-pass
+struct Inv<'a>(&'a mut &'a ());
+enum Foo<T> {
+    Bar,
+    Var(T),
+}
+type Supertype = Foo<for<'a> fn(Inv<'a>, Inv<'a>)>;
+
+fn foo(x: Foo<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>) {
+    match x {
+        Supertype::Bar => {}
+        Supertype::Var(x) => {}
+    }
+}
+
+fn foo_nested(x: Foo<Foo<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>>) {
+    match x {
+        Foo::Bar => {}
+        Foo::Var(Supertype::Bar) => {}
+        Foo::Var(Supertype::Var(x)) => {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/mir/field-ty-ascription-enums.rs b/src/test/ui/mir/field-ty-ascription-enums.rs
new file mode 100644
index 00000000000..179af617090
--- /dev/null
+++ b/src/test/ui/mir/field-ty-ascription-enums.rs
@@ -0,0 +1,15 @@
+// build-pass
+
+enum Foo<T> {
+    Var(T),
+} // `T` is covariant.
+
+fn foo<'b>(x: Foo<for<'a> fn(&'a ())>) {
+    let Foo::Var(x): Foo<fn(&'b ())> = x;
+}
+
+fn foo_nested<'b>(x: Foo<Foo<for<'a> fn(&'a ())>>) {
+    let Foo::Var(Foo::Var(x)): Foo<Foo<fn(&'b ())>> = x;
+}
+
+fn main() {}
diff --git a/src/test/ui/mir/field-ty-ascription.rs b/src/test/ui/mir/field-ty-ascription.rs
new file mode 100644
index 00000000000..178c7916bc5
--- /dev/null
+++ b/src/test/ui/mir/field-ty-ascription.rs
@@ -0,0 +1,37 @@
+// build-pass
+
+struct Foo<T>(T); // `T` is covariant.
+
+struct Bar<T> {
+    x: T,
+} // `T` is covariant.
+
+fn bar<'b>(x: Bar<for<'a> fn(&'a ())>) {
+    let Bar { x }: Bar<fn(&'b ())> = x;
+}
+
+fn bar_nested<'b>(x: Bar<Bar<for<'a> fn(&'a ())>>) {
+    let Bar { x: Bar { x } }: Bar<Bar<fn(&'b ())>> = x;
+}
+
+fn bar_foo_nested<'b>(x: Bar<Foo<for<'a> fn(&'a ())>>) {
+    let Bar { x: Foo ( x ) }: Bar<Foo<fn(&'b ())>> = x;
+}
+
+fn foo<'b>(x: Foo<for<'a> fn(&'a ())>) {
+    let Foo(y): Foo<fn(&'b ())> = x;
+}
+
+fn foo_nested<'b>(x: Foo<Foo<for<'a> fn(&'a ())>>) {
+    let Foo(Foo(y)): Foo<Foo<fn(&'b ())>> = x;
+}
+
+fn tuple<'b>(x: (u32, for<'a> fn(&'a ()))) {
+    let (_, y): (u32, fn(&'b ())) = x;
+}
+
+fn tuple_nested<'b>(x: (u32, (u32, for<'a> fn(&'a ())))) {
+    let (_, (_, y)): (u32, (u32, fn(&'b ()))) = x;
+}
+
+fn main() {}